From 399c1e08c30a23b87350aba093c131e54629e29f Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Sat, 28 Apr 2018 23:12:04 +0100 Subject: [PATCH] dtfile: batch coverity fixes --- cde/programs/dtfile/Main.c | 10 +++++----- cde/programs/dtfile/Trash.c | 15 +++++++++++---- cde/programs/dtfile/dtcopy/copydialog.c | 2 +- cde/programs/dtfile/dtcopy/dosync.c | 13 ++++++------- cde/programs/dtfile/dtcopy/dtcopy.h | 6 ++++-- cde/programs/dtfile/dtcopy/fsrtns.c | 4 ++-- cde/programs/dtfile/dtcopy/overwrtdialog.c | 2 +- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/cde/programs/dtfile/Main.c b/cde/programs/dtfile/Main.c index a4cd3373..6a526735 100644 --- a/cde/programs/dtfile/Main.c +++ b/cde/programs/dtfile/Main.c @@ -2584,9 +2584,9 @@ SaveSession( { static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL, NULL, NULL, NULL}; - char view_number[5]; + char view_number[11]; char number[5]; - char workspaceNumber[5]; + char workspaceNumber[11]; int fd; Atom * ws_presence = NULL; char * workspace_name=NULL; @@ -2991,8 +2991,8 @@ RestoreSession( char * full_path = NULL; Boolean status=False; char * temp = NULL; - char wsNum[5]; - char dialogNum[5]; + char wsNum[11]; + char dialogNum[11]; int num_sec_help_dialogs; int i; int j; @@ -3226,7 +3226,7 @@ LoadViews ( XrmRepresentation rep_type; XrmValue value; static char * name_list[] = { DTFILE_CLASS_NAME, NULL, NULL }; - char view_number[5]; + char view_number[11]; DialogData * dialog_data; FileMgrData * file_mgr_data; char * workspaces; diff --git a/cde/programs/dtfile/Trash.c b/cde/programs/dtfile/Trash.c index 5f0148eb..ad792753 100644 --- a/cde/programs/dtfile/Trash.c +++ b/cde/programs/dtfile/Trash.c @@ -4168,15 +4168,17 @@ CheckDeletePermission( if (FileSysType(statbuf.st_dev) < 0) /* Root user and nfs */ #endif { + int fd = -1; char *tmpfile; tmpfile = tempnam(parentdir,"dtfile"); if (!tmpfile) return -1; - if (creat(tmpfile,O_RDONLY) < 0) /* Create a temporary file */ + if ((fd = creat(tmpfile,O_RDONLY)) < 0) /* Create a temporary file */ { free(tmpfile); return -1; } + close(fd); if (remove(tmpfile) < 0) /* Delete the created file */ { free(tmpfile); @@ -4232,8 +4234,10 @@ CheckDeletePermissionRecur( if (first_file) { /* check for write permission in this directory */ - if (CheckAccess(destinationPath, W_OK|X_OK) < 0) + if (CheckAccess(destinationPath, W_OK|X_OK) < 0) { + closedir(dirp); return -1; + } /* append a '/' to the end of directory name */ fnamep = destinationPath + strlen(destinationPath); @@ -4307,10 +4311,13 @@ RestoreObject( } if(stat(target,&stattar) >= 0) /* Target exists */ { - if(CheckDeletePermission(localdir,target)) + if(CheckDeletePermission(localdir,target)) { + free(localdir); return ((int)False); - else + } else { + free(localdir); return SKIP_FILE; + } } } diff --git a/cde/programs/dtfile/dtcopy/copydialog.c b/cde/programs/dtfile/dtcopy/copydialog.c index ae63fb55..9bf90d6a 100644 --- a/cde/programs/dtfile/dtcopy/copydialog.c +++ b/cde/programs/dtfile/dtcopy/copydialog.c @@ -484,7 +484,7 @@ create_copydir_dialog( /* Save the name of the source directory in order to truncate the pathname */ /* displayed as the copy proceeds ... see function UpdateStatus. */ - strcpy(G_source_dir,source); + snprintf(G_source_dir, sizeof(G_source_dir), "%s", source); tsource = (char * )get_path(source); ttarget = (char * )get_path(target); diff --git a/cde/programs/dtfile/dtcopy/dosync.c b/cde/programs/dtfile/dtcopy/dosync.c index c0868ca1..487fd6e0 100644 --- a/cde/programs/dtfile/dtcopy/dosync.c +++ b/cde/programs/dtfile/dtcopy/dosync.c @@ -254,9 +254,9 @@ GetDirEntry(char *fname, FileOp *op, int *rc) /* get file name */ p = strrchr(fname, '/'); if (p && p > fname) - strcpy(deP->name, p + 1); + snprintf(deP->name, sizeof(deP->name), "%s", p + 1); else - strcpy(deP->name, fname); + snprintf(deP->name, sizeof(deP->name), "%s", fname); /* assume everything is fine */ *op = 0; @@ -321,7 +321,7 @@ GetDir(char *dirname, PatternList *xl, PatternList *sl, DirEntry **listPP) } /* copy dirname to file name buffer */ - strcpy(fname, dirname); + snprintf(fname, sizeof(fname), "%s", dirname); fnP = fname + strlen(fname); *fnP++ = '/'; @@ -410,8 +410,7 @@ doUnlink(char *fname, DirEntry *fP, int confirm) else if (SP->keepold) { char newname[1024]; - strcpy(newname, fname); - strcat(newname, SP->keepold); + snprintf(newname, sizeof(newname), "%s%s", fname, SP->keepold); fsMove(fname, newname, 1, &rc); } else if ((fP->ftype & ft_isdir) && !(fP->ftype & ft_islnk)) { @@ -941,8 +940,8 @@ SyncDirectory(SyncParams *p) /* save pointer to params; copy source & target names */ SP = p; - strcpy(sbuf, SP->source); - strcpy(tbuf, SP->target); + snprintf(sbuf, sizeof(sbuf), "%s", SP->source); + snprintf(tbuf, sizeof(tbuf), "%s", SP->target); /* get info about the source */ sP = GetDirEntry(sbuf, &op, &rc); diff --git a/cde/programs/dtfile/dtcopy/dtcopy.h b/cde/programs/dtfile/dtcopy/dtcopy.h index c3e3b072..ca644af1 100644 --- a/cde/programs/dtfile/dtcopy/dtcopy.h +++ b/cde/programs/dtfile/dtcopy/dtcopy.h @@ -38,6 +38,8 @@ **************************************************************************** ************************************<+>*************************************/ +#include + /* Macros */ #define MAX_PATH PATH_MAX @@ -93,8 +95,8 @@ extern Widget G_rename_text; extern Widget G_toggle_main; extern Widget G_toggle_error; -extern char G_rename_oldname[]; -extern char G_source_dir[]; +extern char G_rename_oldname[MAX_PATH]; +extern char G_source_dir[MAX_PATH]; extern int G_move; extern int G_do_copy; extern int G_pause_copy; diff --git a/cde/programs/dtfile/dtcopy/fsrtns.c b/cde/programs/dtfile/dtcopy/fsrtns.c index c6660480..5e5243a4 100644 --- a/cde/programs/dtfile/dtcopy/fsrtns.c +++ b/cde/programs/dtfile/dtcopy/fsrtns.c @@ -366,7 +366,7 @@ EmptyDir(char *sourceP, int rm, int force) return errno; /* prepare source name */ - strcpy(srcname, sourceP); + snprintf(srcname, sizeof(srcname), "%s", sourceP); srclen = strlen(srcname); if (srcname[srclen - 1] != '/') srcname[srclen++] = '/'; @@ -486,7 +486,7 @@ fsMove(char *sourceP, char *targetP, int replace, int *rcP) /* first check if we have write permission in the source directory */ char dir[1024], *p; - strcpy(dir, sourceP); + snprintf(dir, sizeof(dir), "%s", sourceP); p = strrchr(dir, '/'); if (p == 0) strcpy(dir, "."); diff --git a/cde/programs/dtfile/dtcopy/overwrtdialog.c b/cde/programs/dtfile/dtcopy/overwrtdialog.c index e4ca1695..04390dfd 100644 --- a/cde/programs/dtfile/dtcopy/overwrtdialog.c +++ b/cde/programs/dtfile/dtcopy/overwrtdialog.c @@ -278,7 +278,7 @@ create_overwrite_dialog( /* save the target name for possible rename in ok_callback */ - strcpy(G_rename_oldname,tname); + snprintf(G_rename_oldname, sizeof(G_rename_oldname), "%s", tname); if (G_move) -- 2.25.1