shadow/Fix-some-issues-found-in-Coverity-scan.patch

68 lines
1.9 KiB
Diff
Raw Normal View History

2019-12-25 17:13:08 +08:00
From fb97da1ce1606f7a2f7c897f5441d1d04020f402 Mon Sep 17 00:00:00 2001
From: Tomas Mraz <tmraz@fedoraproject.org>
Date: Wed, 10 Oct 2018 12:22:04 +0200
Subject: [PATCH 10/19] 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(-)
--- shadow-4.6/lib/commonio.c 2019-02-12 00:00:00.000000000 +0000
+++ shadow-4.6-new/lib/commonio.c 2019-02-12 00:00:00.000000000 +0000
@@ -384,7 +384,7 @@
char* lock = NULL;
size_t lock_file_len;
size_t file_len;
- int err;
+ int err = 0;
if (db->locked) {
return 1;
@@ -393,12 +393,10 @@
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%s.%lu",
--- shadow-4.6/lib/spawn.c 2019-02-12 00:00:00.000000000 +0000
+++ shadow-4.6-new/lib/spawn.c 2019-02-12 00:00:00.000000000 +0000
@@ -69,7 +69,7 @@
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",
--- shadow-4.6/libmisc/console.c 2019-02-12 00:00:00.000000000 +0000
+++ shadow-4.6-new/libmisc/console.c 2019-02-12 00:00:00.000000000 +0000
@@ -50,7 +50,7 @@
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 @@
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) {