diff options
Diffstat (limited to 'toc.c')
-rw-r--r-- | toc.c | 48 |
1 files changed, 28 insertions, 20 deletions
@@ -41,7 +41,8 @@ static int IsDir(char *name) struct stat buf; if (*name == '.') return FALSE; - (void) sprintf(str, "%s/%s", app_resources.mail_path, name); + if (snprintf(str, sizeof(str), "%s/%s", app_resources.mail_path, name) + >= sizeof(str)) return False; if (stat(str, &buf) /* failed */) return False; #ifdef S_ISDIR return S_ISDIR(buf.st_mode); @@ -60,11 +61,13 @@ static void MakeSureFolderExists( char str[200]; for (i=0 ; i<*numfoldersptr ; i++) if (strcmp((*namelistptr)[i], name) == 0) return; - (void) sprintf(str, "%s/%s", app_resources.mail_path, name); + if (snprintf(str, sizeof(str), "%s/%s", app_resources.mail_path, name) + >= sizeof(str)) goto punt; (void) mkdir(str, 0700); *numfoldersptr = ScanDir(app_resources.mail_path, namelistptr, IsDir); for (i=0 ; i<*numfoldersptr ; i++) if (strcmp((*namelistptr)[i], name) == 0) return; + punt: Punt("Can't create new mail folder!"); } @@ -88,7 +91,9 @@ static void MakeSureSubfolderExists( /* The parent folder exists. Make sure the subfolder exists. */ - (void) sprintf(subfolder_path, "%s/%s", app_resources.mail_path, name); + if (snprintf(subfolder_path, sizeof(subfolder_path), "%s/%s", + app_resources.mail_path, name) >= sizeof(subfolder_path)) + goto punt; if (stat(subfolder_path, &buf) /* failed */) { (void) mkdir(subfolder_path, 0700); if (stat(subfolder_path, &buf) /* failed */) @@ -99,6 +104,7 @@ static void MakeSureSubfolderExists( #else if ((buf.st_mode & S_IFMT) != S_IFDIR) #endif + punt: Punt("Can't create new xmh subfolder!"); } @@ -106,9 +112,8 @@ int TocFolderExists(Toc toc) { struct stat buf; if (! toc->path) { - char str[500]; - (void) sprintf(str, "%s/%s", app_resources.mail_path, toc->foldername); - toc->path = XtNewString(str); + XtAsprintf(&toc->path, "%s/%s", + app_resources.mail_path, toc->foldername); } return ((stat(toc->path, &buf) == 0) && #ifdef S_ISDIR @@ -123,7 +128,7 @@ static void LoadCheckFiles(void) FILE *fid; char str[1024]; - (void) sprintf(str, "%s/.xmhcheck", homeDir); + snprintf(str, sizeof(str), "%s/.xmhcheck", homeDir); fid = myfopen(str, "r"); if (fid) { int i; @@ -219,7 +224,8 @@ Toc TocCreateFolder(char *foldername) Toc toc; char str[500]; if (TocGetNamed(foldername)) return NULL; - (void) sprintf(str, "%s/%s", app_resources.mail_path, foldername); + if (snprintf(str, sizeof(str), "%s/%s", app_resources.mail_path, foldername) + >= sizeof(str)) return NULL; if (mkdir(str, 0700) < 0) return NULL; toc = TocCreate(foldername); return toc; @@ -797,8 +803,8 @@ void TocSetCacheValid(Toc toc) char *TocMakeFolderName(Toc toc) { - char* name = XtMalloc((Cardinal) (strlen(toc->path) + 2) ); - (void)sprintf( name, "+%s", toc->path ); + char* name; + XtAsprintf(&name, "+%s", toc->path); return name; } @@ -872,8 +878,9 @@ int TocConfirmCataclysm( char str[300]; Widget tocwidget; - (void)sprintf(str,"Are you sure you want to remove all changes to %s?", - toc->foldername); + snprintf(str, sizeof(str), + "Are you sure you want to remove all changes to %s?", + toc->foldername); yes_callbacks[0].closure = (XtPointer) toc; yes_callbacks[1].callback = confirms[0].callback; yes_callbacks[1].closure = confirms[0].closure; @@ -967,7 +974,7 @@ void TocCommitChanges( if (curfate != Fignore && curfate == fate && desttoc == curdesttoc) { argv = ResizeArgv(argv, cur + 1); - (void) sprintf(str, "%d", MsgGetId(msg)); + snprintf(str, sizeof(str), "%d", MsgGetId(msg)); argv[cur++] = XtNewString(str); MsgSetFate(msg, Fignore, (Toc)NULL); if (curdesttoc) { @@ -1044,7 +1051,7 @@ int TocIncorporate(Toc toc) argv[0] = "inc"; argv[1] = TocMakeFolderName(toc); argv[2] = "-width"; - (void) sprintf(str, "%d", app_resources.toc_width); + snprintf(str, sizeof(str), "%d", app_resources.toc_width); argv[3] = str; if (toc->incfile) { argv[4] = "-file"; @@ -1097,10 +1104,10 @@ void TocMsgChanged(Toc toc, Msg msg) argv = MakeArgv(6); argv[0] = "scan"; argv[1] = TocMakeFolderName(toc); - (void) sprintf(str, "%d", msg->msgid); + snprintf(str, sizeof(str), "%d", msg->msgid); argv[2] = str; argv[3] = "-width"; - (void) sprintf(str2, "%d", app_resources.toc_width); + snprintf(str2, sizeof(str2), "%d", app_resources.toc_width); argv[4] = str2; argv[5] = "-noheader"; ptr = DoCommandToString(argv); @@ -1137,7 +1144,8 @@ Msg TocMsgFromId(Toc toc, int msgid) if (h < 0) { if (app_resources.debug) { char str[100]; - (void)sprintf(str, "Toc is empty! folder=%s\n", toc->foldername); + snprintf(str, sizeof(str), + "Toc is empty! folder=%s\n", toc->foldername); DEBUG( str ) } return NULL; @@ -1153,9 +1161,9 @@ Msg TocMsgFromId(Toc toc, int msgid) if (toc->msgs[h]->msgid == msgid) return toc->msgs[h]; if (app_resources.debug) { char str[100]; - (void) sprintf(str, - "TocMsgFromId search failed! hi=%d, lo=%d, msgid=%d\n", - h, l, msgid); + snprintf(str, sizeof(str), + "TocMsgFromId search failed! hi=%d, lo=%d, msgid=%d\n", + h, l, msgid); DEBUG( str ) } return NULL; |