From c12c130ece63cd6c880c87eec1db2e854cd6d53a Mon Sep 17 00:00:00 2001 From: Peter Howkins Date: Wed, 4 Apr 2018 20:16:24 +0100 Subject: [PATCH] config/util: resolve coverity issues --- cde/config/util/lndir.c | 14 +++++++------- cde/config/util/makestrs.c | 14 +++++++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cde/config/util/lndir.c b/cde/config/util/lndir.c index 9dd676e2..f2a47661 100644 --- a/cde/config/util/lndir.c +++ b/cde/config/util/lndir.c @@ -179,7 +179,7 @@ int equivalent(lname, rname) return 1; for (s = lname; *s && (s = strchr(s, '/')); s++) { while (s[1] == '/') - strcpy(s+1, s+2); + memmove(s + 1, s + 2, strlen(s + 2) + 1); } return !strcmp(lname, rname); } @@ -210,12 +210,12 @@ int rel; /* if true, prepend "../" to fn before using */ return 1; } - if (rel) - strcpy (buf, "../"); - else - buf[0] = '\0'; - strcat (buf, fn); - + if (rel) { + snprintf(buf, sizeof(buf), "../%s", fn); + } else { + snprintf(buf, sizeof(buf), "%s", fn); + } + if (!(df = opendir (buf))) { msg ("%s: Cannot opendir", buf); return 1; diff --git a/cde/config/util/makestrs.c b/cde/config/util/makestrs.c index bae88f19..1c265d69 100644 --- a/cde/config/util/makestrs.c +++ b/cde/config/util/makestrs.c @@ -298,10 +298,12 @@ static void WriteHeader (tagline, phile, abi) (*headerproc[abi])(f, phile); - if (phile->tmpl) CopyTmplEpilog (phile->tmpl, f); + if (phile->tmpl) { + CopyTmplEpilog (phile->tmpl, f); + (void) fclose (phile->tmpl); + } (void) free (fileprotstr); - (void) fclose (phile->tmpl); (void) fclose (f); } @@ -465,7 +467,10 @@ static void WriteSource(tagline, abi) (*sourceproc[abi])(abi); - if (tmpl) CopyTmplEpilog (tmpl, stdout); + if (tmpl) { + CopyTmplEpilog (tmpl, stdout); + fclose(tmpl); + } } static void DoLine(buf) @@ -613,8 +618,7 @@ static void DoLine(buf) else right = buf + 1; if (buf[0] == 'H') { - strncpy (lbuf, prefixstr, 1024); - strncat (lbuf, right, strlen(right)); + snprintf(lbuf, sizeof(lbuf), "%s%s", prefixstr, right); right = lbuf; } -- 2.25.1