X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=cde%2Fprograms%2Fdtfile%2FSharedProcs.c;h=1a4366634250c09175556cb4f36ab59fff538975;hb=671530082004aa880b3a0bfb7108bc30c6d97fab;hp=63b7c1158f57bba294b18a5a1bbdd73ae13f993e;hpb=7fa35c29c4559ce8b4ca4d4b5f0216a5305bb6ea;p=oweals%2Fcde.git diff --git a/cde/programs/dtfile/SharedProcs.c b/cde/programs/dtfile/SharedProcs.c index 63b7c115..1a436663 100644 --- a/cde/programs/dtfile/SharedProcs.c +++ b/cde/programs/dtfile/SharedProcs.c @@ -16,7 +16,7 @@ * details. * * You should have received a copy of the GNU Lesser General Public - * License along with these librararies and programs; if not, write + * License along with these libraries and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ @@ -234,9 +234,9 @@ _DtFollowLink ( strcpy(file, path); - while ((link_len = readlink(file, link_path, MAXPATHLEN)) > 0) + while ((link_len = readlink(file, link_path, MAXPATHLEN - 1)) > 0) { - link_path[link_len-1] = 0; + link_path[link_len] = 0; /* Force the link to be an absolute path, if necessary */ if (link_path[0] != '/') @@ -393,7 +393,7 @@ _DtLoadSubdialogArray ( { int i; - char number[10]; + static char number[10]; /* Load sub-dialogs */ nameList[nameCount] = number; @@ -404,7 +404,7 @@ _DtLoadSubdialogArray ( for (i = 0; i < dialogCount; i++) { - sprintf(number, "%d", firstId); + snprintf(number, 10, "%d", firstId); (*dialogArray)[i] = _DtGetResourceDialogData(dialogId, dataBase, nameList); firstId++; } @@ -423,14 +423,14 @@ _DtSaveSubdialogArray ( { int i; - char number[10]; + static char number[10]; nameList[nameCount] = number; nameList[nameCount + 1] = NULL; for (i = 0; i < dialogCount; i++) { - sprintf(number, "%d", firstId); + snprintf(number, 10, "%d", firstId); _DtWriteDialogData(dialogArray[i], fd, nameList); firstId++; } @@ -1348,7 +1348,7 @@ BuildBufferFileName (char *file_name, /* * This is a function for building a buffer name using predfined input * and name template information from the types database. - * WARNING: template_input will be freed. It must point to a char *. + * WARNING: template_input MAY be freed. It must point to a char *. */ static char * @@ -1378,6 +1378,7 @@ RetrieveAndUseNameTemplateInfo( } else { + DtDtsFreeAttributeValue(name_template); return(template_input); } } @@ -1628,9 +1629,10 @@ _DtPathFromInput( /* Resolve, if there're any, environment variables */ { - FILE *pfp; + FILE *pfp = NULL; char command[MAXPATHLEN]; + memset(command, 0, sizeof(command)); sprintf(command,"echo %s",path); if((pfp=popen(command,"r")) != NULL) @@ -1649,19 +1651,29 @@ _DtPathFromInput( sleep (1); if (NULL != (fgets(command,MAXPATHLEN,pfp))) break; - } + } if (i >= 5) read_ok = 0; } - if (read_ok) + if (read_ok) { - command[MAXPATHLEN-1] = '\0'; + int slen = strlen(command); + /* need to remove the trailing newline safely*/ + if (slen >= 1) + command[slen-1] = '\0'; + XtFree(path); path = XtNewString(command); pclose(pfp); + pfp = NULL; } } + if (pfp) + { + pclose(pfp); + pfp = NULL; + } } /* Resolve '~' -- new memory is allocated, old memory is freed */