svn commit: samba r23961 - in branches/SAMBA_4_0/source/lib/appweb: ejs-2.0/ejs ejs-2.0/mpr esp mpr

abartlet at samba.org abartlet at samba.org
Thu Jul 19 04:00:32 GMT 2007


Author: abartlet
Date: 2007-07-19 04:00:32 +0000 (Thu, 19 Jul 2007)
New Revision: 23961

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23961

Log:
Allow SWAT to operate on x86_64 machines.

On machines with a 4 byte int, and a 8 byte pointer, the ESP could would fail.

The problem is that 0 != NULL.  0 is an int (4 bytes) and NULL is a
pointer (8), and this matters critically to varargs functions.

If a 0 was passed as the 'terminating' argument, then only 4 bytes
would be written to the stack, but va_arg(ap, char *) would try and
pull 8, reading uninitalised memory.

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsCmd.c
   branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsVar.c
   branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/mpr/mprString.c
   branches/SAMBA_4_0/source/lib/appweb/esp/esp.c
   branches/SAMBA_4_0/source/lib/appweb/mpr/miniMpr.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsCmd.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsCmd.c	2007-07-19 03:57:44 UTC (rev 23960)
+++ branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsCmd.c	2007-07-19 04:00:32 UTC (rev 23961)
@@ -167,10 +167,10 @@
 		i = 0;
 		commandLine = 0;
 		len = mprAllocStrcat(MPR_LOC_ARGS(app), &commandLine, 0, " ", 
-			mprGetBaseName(argv[i++]), 0);
+			mprGetBaseName(argv[i++]), NULL);
 		for (; i < argc; i++) {
 			len = mprReallocStrcat(MPR_LOC_ARGS(app), &commandLine, 0, len, 
-				" ", argv[i], 0);
+				" ", argv[i], NULL);
 		}
 		mprPrintf(app, "  %s\n", commandLine);
 	}
@@ -339,7 +339,7 @@
 			line[len - 1] = '\0';
 		}
 		cmdLen = mprReallocStrcat(MPR_LOC_ARGS(app), &cmd, EJS_MAX_SCRIPT, 
-			cmdLen, 0, line, 0);
+			cmdLen, 0, line, NULL);
 	}
 	return cmd;
 }
@@ -380,12 +380,12 @@
 		if (line[len - 1] == '\\') {
 			line[len - 1] = '\0';
 			cmdLen = mprReallocStrcat(MPR_LOC_ARGS(app), &cmd, EJS_MAX_SCRIPT, 
-				cmdLen, 0, line, 0);
+				cmdLen, 0, line, NULL);
 
 		} else {
 
 			cmdLen = mprReallocStrcat(MPR_LOC_ARGS(app), &cmd, EJS_MAX_SCRIPT, 
-				cmdLen, 0, line, 0);
+				cmdLen, 0, line, NULL);
 			
 
 			if (traceCmds) {

Modified: branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsVar.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsVar.c	2007-07-19 03:57:44 UTC (rev 23960)
+++ branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/ejs/ejsVar.c	2007-07-19 04:00:32 UTC (rev 23961)
@@ -2590,7 +2590,7 @@
 	/* MOB -- need to encapsulate this logic */
 
 	if (mprAllocStrcat(MPR_LOC_ARGS(ep), &propName, EJS_MAX_ID+5, 0, 
-			"-set-", prop, 0) < 0) {
+			"-set-", prop, NULL) < 0) {
 		ejsMemoryError(ep);
 		return 0;
 	}
@@ -2633,7 +2633,7 @@
 
 	/* MOB -- OPT to use SLAB */
 	if (mprAllocStrcat(MPR_LOC_ARGS(ep), &propName, EJS_MAX_ID + 5, 0, 
-			"-set-", prop, 0) < 0) {
+			"-set-", prop, NULL) < 0) {
 		ejsMemoryError(ep);
 		return 0;
 	}

Modified: branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/mpr/mprString.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/mpr/mprString.c	2007-07-19 03:57:44 UTC (rev 23960)
+++ branches/SAMBA_4_0/source/lib/appweb/ejs-2.0/mpr/mprString.c	2007-07-19 04:00:32 UTC (rev 23961)
@@ -232,8 +232,10 @@
 	return required - 1;
 }
 
-/******************************************************************************/
-
+/*****************************************************************************
+  Note that this VARARGS function must be NULL (not 0, this must be a
+  pointer) terminated
+*/
 int mprStrcat(char *dest, int destMax, const char *delim, const char *src, ...)
 {
 	va_list		ap;
@@ -249,8 +251,10 @@
 	return rc;
 }
 
-/******************************************************************************/
-
+/*****************************************************************************
+  Note that this VARARGS function must be NULL (not 0, this must be a
+  pointer) terminated
+*/
 int mprAllocStrcat(MPR_LOC_DEC(ctx, loc), char **destp, int destMax, 
 	const char *delim, const char *src, ...)
 {
@@ -268,8 +272,10 @@
 	return rc;
 }
 
-/******************************************************************************/
-
+/*****************************************************************************
+  Note that this VARARGS function must be NULL (not 0, this must be a
+  pointer) terminated
+*/
 int mprReallocStrcat(MPR_LOC_DEC(ctx, loc), char **destp, int destMax, 
 	int existingLen, const char *delim, const char *src,...)
 {

Modified: branches/SAMBA_4_0/source/lib/appweb/esp/esp.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/esp/esp.c	2007-07-19 03:57:44 UTC (rev 23960)
+++ branches/SAMBA_4_0/source/lib/appweb/esp/esp.c	2007-07-19 04:00:32 UTC (rev 23961)
@@ -352,7 +352,7 @@
 
 	va_start(args, fmt);
 	mprAllocVsprintf(&buf, MPR_MAX_HEAP_SIZE, fmt, args);
-	ejsSetErrorMsg(ep->eid, buf);
+	ejsSetErrorMsg(ep->eid, "%s", buf);
 	mprFree(buf);
 	va_end(args);
 }
@@ -735,7 +735,7 @@
 			
 		case ESP_TOK_LITERAL:
 			len = mprReallocStrcat(jsBuf, maxScriptSize, len, 0, 
-				"write(\"", parse.token, "\");\n", 0);
+				"write(\"", parse.token, "\");\n", NULL);
 			break;
 
 		case ESP_TOK_ATAT:
@@ -744,12 +744,12 @@
 			 *	Catenate with "" to cause toString to run. 
 			 */
 			len = mprReallocStrcat(jsBuf, maxScriptSize, len, 0, 
-				"write(\"\" + ", parse.token, ");\n", 0);
+				"write(\"\" + ", parse.token, ");\n", NULL);
 			break;
 
 		case ESP_TOK_EQUALS:
 			len = mprReallocStrcat(jsBuf, maxScriptSize, len, 0, 
-				"write(\"\" + ", parse.token, ");\n", 0);
+				"write(\"\" + ", parse.token, ");\n", NULL);
 			state = ESP_STATE_IN_ESP_TAG;
 			break;
 
@@ -759,7 +759,7 @@
 			while (tid != ESP_TOK_EOF && tid != ESP_TOK_EOF && 
 					tid != ESP_TOK_END_ESP && len >= 0) {
 				len = mprReallocStrcat(jsBuf, maxScriptSize, len, 0, 
-					parse.token, 0);
+					parse.token, NULL);
 				tid = getEspToken(state, &parse);
 			}
 			state = ESP_STATE_BEGIN;
@@ -802,7 +802,7 @@
 				return rc;
 			}
 
-			len = mprReallocStrcat(jsBuf, maxScriptSize, len, 0, incBuf, 0);
+			len = mprReallocStrcat(jsBuf, maxScriptSize, len, 0, incBuf, NULL);
 			mprFree(incText);
 			mprFree(incBuf);
 			state = ESP_STATE_IN_ESP_TAG;

Modified: branches/SAMBA_4_0/source/lib/appweb/mpr/miniMpr.c
===================================================================
--- branches/SAMBA_4_0/source/lib/appweb/mpr/miniMpr.c	2007-07-19 03:57:44 UTC (rev 23960)
+++ branches/SAMBA_4_0/source/lib/appweb/mpr/miniMpr.c	2007-07-19 04:00:32 UTC (rev 23961)
@@ -387,7 +387,10 @@
 	return required - 1;
 }
 
-/*****************************************************************************/
+/*****************************************************************************
+  Note that this VARARGS function must be NULL (not 0, this must be a
+  pointer) terminated
+*/
 
 int mprReallocStrcat(char **destp, int destMax, int existingLen, 
 	const char *delim, const char *src,...)



More information about the samba-cvs mailing list