From f67aea132164b3d79894279a4cfbfdc5d5a97830 Mon Sep 17 00:00:00 2001 From: Randy Kunkee Date: Tue, 4 Apr 2000 09:42:44 +0000 Subject: [PATCH] Using a stale obj from Tcl_GetResultObj() to store error results caused incorrect data in result array and possibly segmentation violations when searches terminated due to errors such as timeout, exceeding search limit, or the remote server going down in the middle of a search. Also correctly puts error message on top of traceback stack (instead of randomly in memory per the stale result obj). A segmentation violation could have manifested later in the program's life, or perhaps during termination of the interpreter. --- contrib/ldaptcl/neoXldap.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/contrib/ldaptcl/neoXldap.c b/contrib/ldaptcl/neoXldap.c index b91e6a450b..45e0f09330 100644 --- a/contrib/ldaptcl/neoXldap.c +++ b/contrib/ldaptcl/neoXldap.c @@ -302,16 +302,13 @@ LDAP_PerformSearch (interp, ldaptcl, base, scope, attrs, filtpatt, value, LDAPMessage *entryMessage = 0; char *sortKey; - Tcl_Obj *resultObj; int lderrno; - resultObj = Tcl_GetObjResult (interp); - sprintf(filter, filtpatt, value); fflush(stderr); if ((msgid = ldap_search (ldap, base, scope, filter, attrs, 0)) == -1) { - Tcl_AppendStringsToObj (resultObj, + Tcl_AppendResult (interp, "LDAP start search error: ", LDAP_ERR_STRING(ldap), (char *)NULL); @@ -376,27 +373,19 @@ LDAP_PerformSearch (interp, ldaptcl, base, scope, attrs, filtpatt, value, return tclResult; } if (resultCode == -1) { - Tcl_AppendStringsToObj (resultObj, + Tcl_ResetResult (interp); + Tcl_AppendResult (interp, "LDAP result search error: ", LDAP_ERR_STRING(ldap), (char *)NULL); LDAP_SetErrorCode(ldaptcl, -1, interp); return TCL_ERROR; } - if (resultCode == 0) { - Tcl_SetErrorCode (interp, "TIMEOUT", (char*) NULL); - Tcl_SetStringObj (resultObj, "LDAP timeout retrieving results", -1); - return TCL_ERROR; - } - /* - if (resultCode == LDAP_RES_SEARCH_RESULT || - (all && resultCode == LDAP_RES_SEARCH_ENTRY)) - return tclResult; - */ if ((errorCode = ldap_result2error (ldap, resultMessage, 0)) != LDAP_SUCCESS) { - Tcl_AppendStringsToObj (resultObj, + Tcl_ResetResult (interp); + Tcl_AppendResult (interp, "LDAP search error: ", ldap_err2string(errorCode), (char *)NULL); -- 2.39.5