From f7d09f054dff74781dab42ea5572655c2e0faf8f Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Tue, 3 Apr 2018 20:59:48 -0600 Subject: [PATCH] dtfile/SharedProcs.c: rework coverity 174852 fix to unbreak dtfile --- cde/programs/dtfile/SharedProcs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cde/programs/dtfile/SharedProcs.c b/cde/programs/dtfile/SharedProcs.c index 63b7c115..eadcc2f9 100644 --- a/cde/programs/dtfile/SharedProcs.c +++ b/cde/programs/dtfile/SharedProcs.c @@ -1631,6 +1631,7 @@ _DtPathFromInput( FILE *pfp; char command[MAXPATHLEN]; + memset(command, 0, sizeof(command)); sprintf(command,"echo %s",path); if((pfp=popen(command,"r")) != NULL) @@ -1654,9 +1655,13 @@ _DtPathFromInput( 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); -- 2.25.1