chiark / gitweb /
@@ -1,3 +1,11 @@
authorianmdlvl <ianmdlvl>
Sat, 5 Aug 2006 14:34:08 +0000 (14:34 +0000)
committerianmdlvl <ianmdlvl>
Sat, 5 Aug 2006 14:34:08 +0000 (14:34 +0000)
+chiark-utils (4.1.4) unstable; urgency=low
+
+  summer bugfix:
+  * `buf' is used reentrantely by recurse() and sometimes is the `path'
+    argument to recurse; cope appropriately.
+
+ -- Ian Jackson <ian@davenant.greenend.org.uk>  Sat,  5 Aug 2006 15:34:03 +0100
+
 chiark-utils (4.1.3) unstable; urgency=low

   backup snap remountrocp fixes:

cprogs/summer.c
debian/changelog

index 887409db55bb0d3ed43d8c675a65b3b61332d3bd..2c4f9df197995beba1cf04d10ffbed101459906d 100644 (file)
@@ -287,24 +287,29 @@ static int recurse_compar(const void *av, const void *bv) {
   return strcmp((*a)->d_name, (*b)->d_name);
 }
 
-static void recurse(const char *path) {
+static void recurse(const char *path_or_buf) {
   static char *buf;
   static int buf_allocd;
   
   struct dirent **namelist, *const *de;
   char *subpathp;
+  const char *path_or_0= path_or_buf==buf ? 0 : path_or_buf;
   int nentries, pathl, esave, buf_want, i;
 
-  pathl= strlen(path);
+  pathl= strlen(path_or_buf);
   recurse_maxlen= 2;
-  nentries= scandir(path, &namelist, recurse_filter, recurse_compar);
+  nentries= scandir(path_or_buf, &namelist, recurse_filter, recurse_compar);
   esave= errno;
+  
   buf_want= pathl+1+recurse_maxlen+1;
   if (buf_want > buf_allocd) {
     buf= mrealloc(buf, buf_want);
     buf_allocd= buf_want;
   }
-  strcpy(buf,path);
+  /* NOTE that path_or_buf is invalid after this point because
+   * it might have been realloc'd ! */
+  if (path_or_0) strcpy(buf,path_or_0);
+
   buf[pathl]= '/';
   subpathp= buf+pathl+1;
   if (nentries < 0) {
@@ -313,6 +318,9 @@ static void recurse(const char *path) {
     return;
   }
   for (i=0, de=namelist; i<nentries; i++, de++) {
+ fprintf(stderr,
+        "buf=%p \"%s\" path=%p \"%s\" subpathp-buf=%ld d_name=\"%s\"\n",
+        buf,buf,path_or_0,path_or_0,(long)(subpathp-buf),(*de)->d_name);
     strcpy(subpathp, (*de)->d_name);
     node(buf);
     free(*de);
index e62b38efa25f8f39d4a5143e5ed6668606a3090c..9ef478a56194506719e681f95d99ecf6cdb1f3e1 100644 (file)
@@ -1,3 +1,11 @@
+chiark-utils (4.1.4) unstable; urgency=low
+
+  summer bugfix:
+  * `buf' is used reentrantely by recurse() and sometimes is the `path'
+    argument to recurse; cope appropriately.
+
+ -- Ian Jackson <ian@davenant.greenend.org.uk>  Sat,  5 Aug 2006 15:34:03 +0100
+
 chiark-utils (4.1.3) unstable; urgency=low
 
   backup snap remountrocp fixes: