From fa0074904bd61f013fe93973ee18691456ae7059 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Fri, 26 Dec 2014 14:06:26 -0700 Subject: [PATCH] DtSvc: Coverity (memory corruption) --- cde/lib/DtSvc/DtUtil1/DbUtil.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cde/lib/DtSvc/DtUtil1/DbUtil.c b/cde/lib/DtSvc/DtUtil1/DbUtil.c index f431230f..0828860d 100644 --- a/cde/lib/DtSvc/DtUtil1/DbUtil.c +++ b/cde/lib/DtSvc/DtUtil1/DbUtil.c @@ -736,6 +736,7 @@ _DtDbGetDataBaseEnv( void ) char *nwh_dir; char *temp_buf; char *temp_s; + int slen = 0; nwh_dir = getenv ("HOME"); /* @@ -745,9 +746,10 @@ _DtDbGetDataBaseEnv( void ) if (( temp_s = getenv ("DTDATABASESEARCHPATH"))) if ( *temp_s != 0 ) return XtNewString(temp_s); - temp_buf = - XtMalloc((2*strlen(nwh_dir)) + strlen(DTDATABASESEARCHPATH_DEFAULT) + 1); - sprintf (temp_buf, DTDATABASESEARCHPATH_DEFAULT, nwh_dir, nwh_dir); + slen = (2 * strlen(nwh_dir)) + strlen(DTDATABASESEARCHPATH_DEFAULT) + 1; + temp_buf = XtCalloc(1, slen); + snprintf (temp_buf, slen - 1, + DTDATABASESEARCHPATH_DEFAULT, nwh_dir, nwh_dir); return temp_buf; } -- 2.25.1