[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: Untested patch: back-tcl used wrong types (ITS#1719)



> [tcl_merge_bvlist()] ... You left an
> off-by-one bug when allocating the temporary for the char * array;

I don't think so.  I counted (number of strings + 1) in the loop,
for the strings and a NULL.

> I turned it into an automatic variable.

...and used a variable-length array.  That's a gcc extension, it is not
in ANSI C89.  (It is in C99 though.)  You seem to be compiling without
-pedantic:-)  Anyway, here is a patch to turn it back into ch_malloc(),
plus some README fixes.

> I couldn't test it as well, because I had no idea of how to test it
> and I didn't have time to prepare any test script.  Maybe there's
> someone out there that uses back-tcl.

I'll mail the author and ask him if he'll contribute a back-tcl example.

BTW, I've just noticed that tcl_merge_bvlist() is always called with the
same argument: the list of suffixes.  So it it could probably be moved
to the init section.  I'll look at that someday later if a back-tcl
example arrives, and maybe insert normalized DNs in the argument lists.


diff -u2 -r servers/slapd/back-tcl/README.back-tcl~ servers/slapd/back-tcl/README.back-tcl
--- servers/slapd/back-tcl/README.back-tcl~	Mon Apr  8 10:56:01 2002
+++ servers/slapd/back-tcl/README.back-tcl	Mon Apr  8 14:50:05 2002
@@ -26,5 +26,5 @@
 
 # This is one of the biggest pluses of using the tcl backend.
-# The realm let's you group several databases to the same interpreter.
+# The realm lets you group several databases to the same interpreter.
 # This basically means they share the same global variables and proc
 # space. So global variables, as well as all the procs, are callable
@@ -110,5 +110,5 @@
 	suffix - List of suffix(es) associated with the call. Each one
 		 is and entry in a tcl formatted list (surrounded by {}'s)
-	dn     - DN who's RDN is being renamed
+	dn     - DN whose RDN is being renamed
 	newrdn - New RDN
 	deleteoldrdn - Boolean stating whether or not the old RDN should
diff -u2 -r servers/slapd/back-tcl/tcl_search.c~ servers/slapd/back-tcl/tcl_search.c
--- servers/slapd/back-tcl/tcl_search.c~	Mon Apr  8 10:56:02 2002
+++ servers/slapd/back-tcl/tcl_search.c	Mon Apr  8 14:33:36 2002
@@ -48,10 +48,10 @@
 	for (i = 0, an = attrs; an && an->an_name.bv_val; an++, i++);
 	if (i > 0) {
-		char *sattrs[i+1];
-
+		char **sattrs = ch_malloc( (i+1) * sizeof(char *));
 		for (i = 0, an = attrs; an->an_name.bv_val; an++, i++)
 			sattrs[i] = an->an_name.bv_val;
 		sattrs[i] = NULL;
 		attrs_tcl = Tcl_Merge (i, sattrs);
+		ch_free(sattrs);
 	}
 
diff -u2 -r servers/slapd/back-tcl/tcl_util.c~ servers/slapd/back-tcl/tcl_util.c
--- servers/slapd/back-tcl/tcl_util.c~	Mon Apr  8 10:56:02 2002
+++ servers/slapd/back-tcl/tcl_util.c	Mon Apr  8 14:33:58 2002
@@ -216,5 +216,10 @@
 
 	if (i) {
-		char *strlist[i + 1];
+		char **strlist = ch_malloc ((i + 1) * sizeof(char *));
+		if (strlist == NULL) {
+			if (out == NULL)
+				ch_free (ret);
+			return NULL;
+		}
 		for (i = 0; bvlist[i] != NULL; i++) {
 			strlist[i] = bvlist[i]->bv_val;
@@ -223,4 +228,5 @@
 		ret->bv_val = Tcl_Merge(i, strlist);
 		ret->bv_len = ret->bv_val ? strlen(ret->bv_val) : 0;
+		ch_free (strlist);
 	}
 

-- 
Hallvard