From 2d89ad036ae0cec772cdf9ccc4827adc8eea5e68 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 26 Dec 2014 14:03:17 -0700 Subject: [PATCH] DtSvc: Coverity (memory corruption) --- cde/lib/DtSvc/DtUtil1/ActionUtil.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cde/lib/DtSvc/DtUtil1/ActionUtil.c b/cde/lib/DtSvc/DtUtil1/ActionUtil.c index 992bf79d..38509aba 100644 --- a/cde/lib/DtSvc/DtUtil1/ActionUtil.c +++ b/cde/lib/DtSvc/DtUtil1/ActionUtil.c @@ -345,7 +345,7 @@ _DtGetDisplayHostName( Display *dp) return XtNewString(displayHostName); } - tmpName = XtMalloc(MAXHOSTNAMELEN + 5); + tmpName = XtMalloc(MAXHOSTNAMELEN + 5 + 1); tmpName[0] = '\0'; if ( dp ) @@ -369,7 +369,8 @@ _DtGetDisplayHostName( Display *dp) * In the absence of a display pointer, use the * DISPLAY environment variable. */ - strcpy(tmpName,getenv("DISPLAY")); + memset(tmpName, 0, (MAXHOSTNAMELEN + 5) + 1); + strncpy(tmpName, getenv("DISPLAY"), (MAXHOSTNAMELEN + 5)); if (( tmp = DtStrrchr(tmpName,':') )) { *tmp = '\0'; @@ -713,10 +714,9 @@ char *_DtGetDtTmpDir(void) else { /* RWV: is this the right HOME if we've changed user id? */ - dirBuf = XtMalloc(MAXPATHLEN); - strcpy(dirBuf,getenv("HOME")); - strcat(dirBuf,"/"); - strcat(dirBuf,DtACTION_DTTMPDIR_DEFAULT); + char *home = getenv("HOME"); + dirBuf = XtCalloc(1, MAXPATHLEN + 1); + snprintf(dirBuf, MAXPATHLEN, "%s/%s", home, DtACTION_DTTMPDIR_DEFAULT); DtTmpDirPath = XtNewString(dirBuf); XtFree(dirBuf); } -- 2.25.1