From fb97da1ce1606f7a2f7c897f5441d1d04020f402 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Wed, 10 Oct 2018 12:22:04 +0200 Subject: [PATCH] Fix some issues found in Coverity scan. --- lib/commonio.c | 4 +--- lib/spawn.c | 2 +- libmisc/console.c | 5 +++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/commonio.c b/lib/commonio.c index d06b8e7d..52a360cf 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -379,7 +379,7 @@ int commonio_lock_nowait (struct commonio_db *db, bool log) char* lock = NULL; size_t lock_file_len; size_t file_len; - int err; + int err = 0; if (db->locked) { return 1; @@ -388,12 +388,10 @@ int commonio_lock_nowait (struct commonio_db *db, bool log) lock_file_len = strlen(db->filename) + 6; /* sizeof ".lock" */ file = (char*)malloc(file_len); if(file == NULL) { - err = ENOMEM; goto cleanup_ENOMEM; } lock = (char*)malloc(lock_file_len); if(lock == NULL) { - err = ENOMEM; goto cleanup_ENOMEM; } snprintf (file, file_len, "%s.%lu", diff --git a/lib/spawn.c b/lib/spawn.c index da984019..fc4ad95c 100644 --- a/lib/spawn.c +++ b/lib/spawn.c @@ -69,7 +69,7 @@ int run_command (const char *cmd, const char *argv[], do { wpid = waitpid (pid, status, 0); } while ( ((pid_t)-1 == wpid && errno == EINTR) - || (wpid != pid)); + || ((pid_t)-1 != wpid && wpid != pid)); if ((pid_t)-1 == wpid) { fprintf (stderr, "%s: waitpid (status: %d): %s\n", diff --git a/libmisc/console.c b/libmisc/console.c index 70d13903..cb74c2f9 100644 --- a/libmisc/console.c +++ b/libmisc/console.c @@ -50,7 +50,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def); static bool is_listed (const char *cfgin, const char *tty, bool def) { FILE *fp; - char buf[200], *s; + char buf[1024], *s; const char *cons; /* @@ -70,7 +70,8 @@ static bool is_listed (const char *cfgin, const char *tty, bool def) if (*cons != '/') { char *pbuf; - strcpy (buf, cons); + strncpy (buf, cons, sizeof (buf)); + buf[sizeof (buf) - 1] = '\0'; pbuf = &buf[0]; while ((s = strtok (pbuf, ":")) != NULL) { if (strcmp (s, tty) == 0) { -- 2.40.0