CVS User Account cvsuser
Mon Jul 18 21:14:16 PDT 2005
Log Message:
-----------
The function get_sharepath() in slonik (used only on win32) is badly broken as it is now. For one thing, it loops on an unsigned int var with a condition of ">=0", which is always true. Which results in it happily overwriting argv[] (and probably other such things!) makeing it impossible to run a simple command like "slonik foo" (because once it tries to open the file, argv[1] is now NULL).

Attached patch cleans that up. Still uses the same logic (assuming I read the original logic correctly). It's a bit simplistic, but I think it will be enough for most cases.
[Magnus Hagander]

Modified Files:
--------------
    slony1-engine/src/slonik:
        slonik.c (r1.45 -> r1.46)

-------------- next part --------------
Index: slonik.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/slonik/slonik.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -Lsrc/slonik/slonik.c -Lsrc/slonik/slonik.c -u -w -r1.45 -r1.46
--- src/slonik/slonik.c
+++ src/slonik/slonik.c
@@ -116,38 +116,51 @@
 
 #ifdef WIN32
 /*
- * This begins to look for share. 
- * It begins to look for it from path of exec.
- * bin/slonik.exe ../share
+ * Attempt to locate share directory. Will add to path of exe,
+ * except when the exe is in a "bin" directory, in which case
+ * it goes to ../share.
+ * This is a very simple view of things - perhaps it needs to be
+ * expanded? If so there is more complete code available in the
+ * PostgreSQL backend that could be adapted.
  */
 char *get_sharepath(const char *path)
 {
-       DWORD dwRet;
+	int i; 
        char *result;
 
        result = (char *)malloc(MAX_PATH+1);
+	if (!result) {
+		printf("memory allocation failure.\n");
+		exit(1);
+	}
+
        memcpy(result,path,strlen(path));
 
-       for (dwRet = strlen(path); dwRet >= 0 ; dwRet--)
+	for (i = strlen(path); i >= 0 ; i --)
        {
-               result[dwRet] = '\0';
-               if ((path[dwRet] == '/')||(path[dwRet] == '\\'))
+		if ((path[i] == '/')||(path[i] == '\\'))
                        break;
+		result[i] = '\0';
        }
 
-       if (result)
-       {
-               dwRet = strlen(result);
-               if (!_stricmp((const char *)result+dwRet-3,"bin"))
+	if (!result[0])
                {
-                       dwRet -= 3;
-                       result[dwRet] = '\0';
+		/* Nothing left, so assume subdir of current */
+		strcpy(result,PGSHARE);
+		return result;
                }
+
+	/* Check if directory of exe is "bin" */
+	if (strlen(result) >= 3 &&
+		!strncasecmp(result+i-3,"bin",3) &&
+		(result[i]=='/' || result[i]=='\\'))
+	{
+		/* Strip off bin directory */
+		result[i-3] = 0;
        }
 
-       memcpy(result+dwRet,PGSHARE,strlen(PGSHARE));
+	strcat(result, PGSHARE);
        return result;
-
 }
 #endif
 


More information about the Slony1-commit mailing list