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

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



On Fri, 2014-01-31 at 19:48 +0100, Samuel Thibault wrote:
> Svante Signell, le Wed 29 Jan 2014 14:20:47 +0100, a écrit :
> > 1) src/Rserv.c: Since PATH_MAX is not defined use the st_size parameter
> > of a previously made lstat() call:
> 
> Errr, but st_size contains the size of the file, not the size of the
> name of the file...
> 
> > (Problems can arise since rm_rf() is recursive?? Help needed here!)
> 
> Not a problem: you'll get newer variables. Just keep the call as it is.
> 
> > -					snprintf(path, sizeof(path), "%s/%s", what, d->d_name);
> > +					int len = st.st_size + strlen(d->d_name) + 1;
> 
> Just use strlen(what) instead of st.st_size. Also don't forget to count
> the / !

Of course you are right (as always), new patch attached :)

--- a/src/Rserv.c.orig	2013-08-21 23:09:33.000000000 +0200
+++ b/src/Rserv.c	2014-01-31 21:22:28.000000000 +0100
@@ -2206,14 +2206,17 @@ static void rm_rf(const char *what) {
 		chmod(what, st.st_mode | ((st.st_mode & S_IFDIR) ? S_IRWXU : S_IWUSR));
 		if (st.st_mode & S_IFDIR) { /* dirs need to be deleted recursively */
 			DIR *dir = opendir(what);
-			char path[PATH_MAX];
+			char *path = NULL;
 			if (dir) {
 				struct dirent *d;
 				while ((d = readdir(dir))) {
 					if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
 						continue;
-					snprintf(path, sizeof(path), "%s/%s", what, d->d_name);
+					int len = strlen(what) + 1 + strlen(d->d_name) + 1;
+					path = (char*)malloc(len);
+					snprintf(path, len, "%s/%s", what, d->d_name);
 					rm_rf(path);
+					free(path);
 				}
 				closedir(dir);
 			}

Reply to: