]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix zero length filenames & make abort() seg fault for traceback
authorKern Sibbald <kern@sibbald.com>
Mon, 3 Jun 2002 20:26:11 +0000 (20:26 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 3 Jun 2002 20:26:11 +0000 (20:26 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@37 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/sql_create.c
bacula/src/cats/sql_get.c
bacula/src/lib/message.c

index e889fee83fba9b21aea9defaec8ad9bf615d9308..5d63af75772a2e3d367a7499953383b9cedee3a5 100644 (file)
@@ -462,6 +462,7 @@ int db_create_file_attributes_record(B_DB *mdb, ATTR_DBR *ar)
    } else {
       file[0] = ' ';                  /* blank filename */
       file[1] = 0;
+      fnl = 1;
    }
 
    pnl = l - ar->fname;    
@@ -477,6 +478,7 @@ int db_create_file_attributes_record(B_DB *mdb, ATTR_DBR *ar)
       Emsg0(M_ERROR, 0, mdb->errmsg);
       spath[0] = ' ';
       spath[1] = 0;
+      pnl = 1;
    }
 
    Dmsg1(100, "spath=%s\n", spath);
index ad5b9b314d7dfc3dbae329f8289497e8d2374aa2..ca5f868a66882b6ff5992c43d98787d7b8af95c7 100644 (file)
@@ -76,32 +76,60 @@ int db_get_file_attributes_record(B_DB *mdb, char *fname, FILE_DBR *fdbr)
    char buf[MAXSTRING];
    Dmsg1(20, "Enter get_file_from_catalog fname=%s \n", fname);
 
-   /* Find path without the filename */
+   /* Find path without the filename.  
+    * I.e. everything after the last / is a "filename".
+    * OK, maybe it is a directory name, but we treat it like
+    * a filename. If we don't find a / then the whole name
+    * must be a path name (e.g. c:).
+    */
    for (p=l=fname; *p; p++) {
       if (*p == '/') {
         l = p;
       }
    }
-   if (*l == '/') {
-      l++;
+   if (*l == '/') {                   /* did we find a slash? */
+      l++;                           /* yes, point to filename */
+   } else {                          /* no, whole thing must be path name */
+      l = p;
    }
 
+   /* If filename doesn't exist (i.e. root directory), we
+    * simply create a blank name consisting of a single 
+    * space. This makes handling zero length filenames
+    * easier.
+    */
    fnl = p - l;
-   strcpy(file, l);
+   if (fnl > 255) {
+      Emsg1(M_WARNING, 0, _("Filename truncated to 255 chars: %s\n"), l);
+      fnl = 255;
+   }
+   if (fnl > 0) {
+      strncpy(file, l, fnl);         /* copy filename */
+      file[fnl] = 0;
+   } else {
+      file[0] = ' ';                  /* blank filename */
+      file[1] = 0;
+      fnl = 1;
+   }
 
    pnl = l - fname;    
+   if (pnl > 255) {
+      Emsg1(M_WARNING, 0, _("Path name truncated to 255 chars: %s\n"), fname);
+      pnl = 255;
+   }
    strncpy(spath, fname, pnl);
-   spath[l-fname] = 0;
+   spath[pnl] = 0;
 
    if (pnl == 0) {
-      return 0;
+      Mmsg1(&mdb->errmsg, _("Path length is zero. File=%s\n"), fname);
+      Emsg0(M_ERROR, 0, mdb->errmsg);
+      spath[0] = ' ';
+      spath[1] = 0;
+      pnl = 1;
    }
 
-   strip_trailing_junk(spath);
-   Dmsg1(50, "spath=%s\n", spath);
-
-   strip_trailing_junk(file);
-   Dmsg1(50, "file=%s\n", file);
+   Dmsg1(100, "spath=%s\n", spath);
+   Dmsg1(100, "file=%s\n", file);
 
    db_escape_string(buf, file, fnl);
    fdbr->FilenameId = db_get_filename_record(mdb, buf);
index c071e532f0e004ecfbdd274f1cb5bac0cc25048c..d70adadeae2b6d01ed2f146af169d43c748b4b75 100755 (executable)
@@ -867,7 +867,8 @@ e_msg(char *file, int line, int type, int level, char *fmt,...)
     dispatch_message(NULL, type, level, buf);
 
     if (type == M_ABORT) {
-       abort();
+       char *p = 0;
+       p[0] = 0;                     /* generate segmentation violation */
     }
 }
 
@@ -947,8 +948,10 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...)
 
     Dmsg3(500, "i=%d sizeof(rbuf)-i=%d len=%d\n", i, sizeof(rbuf)-i, len);
 
-    if (type == M_ABORT)
-       abort();
+    if (type == M_ABORT){
+       char *p = 0;
+       p[0] = 0;                     /* generate segmentation violation */
+    }
 }
 
 /*