From: Kern Sibbald Date: Mon, 3 Jun 2002 20:26:11 +0000 (+0000) Subject: Fix zero length filenames & make abort() seg fault for traceback X-Git-Tag: Release-1.21~4 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=93b7334aa9f3ee9da6ef55b9f42b9e1b03b059f8;p=bacula%2Fbacula Fix zero length filenames & make abort() seg fault for traceback git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@37 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index e889fee83f..5d63af7577 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -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); diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index ad5b9b314d..ca5f868a66 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -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); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index c071e532f0..d70adadeae 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -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 */ + } } /*