[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: xdebug: FTBFS on hurd-i386 (for review)



On Tue, 2014-04-15 at 03:19 +0200, Samuel Thibault wrote:
> Svante Signell, le Mon 14 Apr 2014 17:16:36 +0200, a écrit :
> > -	memset(dfp, 0, sizeof(dfp));
> > -	strncpy(dfp, efp, sizeof(dfp) - 1);
> 
> Why not simply using xdstrdup?

Done!

> > +		dfp = tmp + 7;
> 
> > +	free(dfp);
> 
> Will obviously crash. Did you try your code at all?

I wrote a test program and run that one through valgind. Better now?

--- a/xdebug-2.2.4/usefulstuff.c
+++ b/xdebug-2.2.4/usefulstuff.c
@@ -284,25 +284,25 @@ char *xdebug_raw_url_encode(char const *
 char *xdebug_path_from_url(const char *fileurl TSRMLS_DC)
 {
 	/* deal with file: url's */
-	char dfp[PATH_MAX * 2];
-	const char *fp = dfp, *efp = fileurl;
+	const char *efp = fileurl;
+	char *dfp = NULL;
 #ifdef PHP_WIN32
 	int l = 0;
 	int i;
 #endif
 	char *tmp = NULL, *ret = NULL;;
 
-	memset(dfp, 0, sizeof(dfp));
-	strncpy(dfp, efp, sizeof(dfp) - 1);
+	dfp = xdstrdup(efp);
 	xdebug_raw_url_decode(dfp, strlen(dfp));
-	tmp = strstr(fp, "file://");
+	tmp = strstr(dfp, "file://");
 
 	if (tmp) {
-		fp = tmp + 7;
-		if (fp[0] == '/' && fp[2] == ':') {
-			fp++;
+		dfp = tmp + 7;
+		if (dfp[0] == '/' && dfp[2] == ':') {
+			dfp++;
 		}
-		ret = xdstrdup(fp);
+		ret = xdstrdup(dfp);
+		free(tmp);
 #ifdef PHP_WIN32
 		l = strlen(ret);
 		/* convert '/' to '\' */
@@ -314,8 +314,8 @@ char *xdebug_path_from_url(const char *f
 #endif
 	} else {
 		ret = xdstrdup(fileurl);
+		free(dfp);
 	}
-
 	return ret;
 }
 

Reply to: