Blame SOURCES/shadow-4.6-coverity.patch

4fb1b2
diff -up shadow-4.6/lib/commonio.c.coverity shadow-4.6/lib/commonio.c
4fb1b2
--- shadow-4.6/lib/commonio.c.coverity	2018-10-10 09:50:59.307738194 +0200
4fb1b2
+++ shadow-4.6/lib/commonio.c	2018-10-10 09:55:32.919319048 +0200
4fb1b2
@@ -382,7 +382,7 @@ int commonio_lock_nowait (struct commoni
4fb1b2
 	char* lock = NULL;
4fb1b2
 	size_t lock_file_len;
4fb1b2
 	size_t file_len;
4fb1b2
-	int err;
4fb1b2
+	int err = 0;
4fb1b2
 
4fb1b2
 	if (db->locked) {
4fb1b2
 		return 1;
4fb1b2
@@ -391,12 +391,10 @@ int commonio_lock_nowait (struct commoni
4fb1b2
 	lock_file_len = strlen(db->filename) + 6; /* sizeof ".lock" */
4fb1b2
 	file = (char*)malloc(file_len);
4fb1b2
 	if(file == NULL) {
4fb1b2
-		err = ENOMEM;
4fb1b2
 		goto cleanup_ENOMEM;
4fb1b2
 	}
4fb1b2
 	lock = (char*)malloc(lock_file_len);
4fb1b2
 	if(lock == NULL) {
4fb1b2
-		err = ENOMEM;
4fb1b2
 		goto cleanup_ENOMEM;
4fb1b2
 	}
4fb1b2
 	snprintf (file, file_len, "%s.%lu",
4fb1b2
diff -up shadow-4.6/libmisc/console.c.coverity shadow-4.6/libmisc/console.c
4fb1b2
--- shadow-4.6/libmisc/console.c.coverity	2018-04-29 18:42:37.000000000 +0200
4fb1b2
+++ shadow-4.6/libmisc/console.c	2018-10-10 11:56:51.368837533 +0200
4fb1b2
@@ -50,7 +50,7 @@ static bool is_listed (const char *cfgin
4fb1b2
 static bool is_listed (const char *cfgin, const char *tty, bool def)
4fb1b2
 {
4fb1b2
 	FILE *fp;
4fb1b2
-	char buf[200], *s;
4fb1b2
+	char buf[1024], *s;
4fb1b2
 	const char *cons;
4fb1b2
 
4fb1b2
 	/*
4fb1b2
@@ -70,7 +70,8 @@ static bool is_listed (const char *cfgin
4fb1b2
 
4fb1b2
 	if (*cons != '/') {
4fb1b2
 		char *pbuf;
4fb1b2
-		strcpy (buf, cons);
4fb1b2
+		strncpy (buf, cons, sizeof (buf));
4fb1b2
+		buf[sizeof (buf) - 1] = '\0';
4fb1b2
 		pbuf = &buf[0];
4fb1b2
 		while ((s = strtok (pbuf, ":")) != NULL) {
4fb1b2
 			if (strcmp (s, tty) == 0) {
4fb1b2
diff -up shadow-4.6/lib/spawn.c.coverity shadow-4.6/lib/spawn.c
4fb1b2
--- shadow-4.6/lib/spawn.c.coverity	2018-04-29 18:42:37.000000001 +0200
4fb1b2
+++ shadow-4.6/lib/spawn.c	2018-10-10 11:36:49.035784609 +0200
4fb1b2
@@ -69,7 +69,7 @@ int run_command (const char *cmd, const
4fb1b2
 	do {
4fb1b2
 		wpid = waitpid (pid, status, 0);
4fb1b2
 	} while (   ((pid_t)-1 == wpid && errno == EINTR)
4fb1b2
-	         || (wpid != pid));
4fb1b2
+	         || ((pid_t)-1 != wpid && wpid != pid));
4fb1b2
 
4fb1b2
 	if ((pid_t)-1 == wpid) {
4fb1b2
 		fprintf (stderr, "%s: waitpid (status: %d): %s\n",
4fb1b2
diff -up shadow-4.6/src/useradd.c.coverity shadow-4.6/src/useradd.c
4fb1b2
--- shadow-4.6/src/useradd.c.coverity	2018-10-10 09:50:59.303738098 +0200
4fb1b2
+++ shadow-4.6/src/useradd.c	2018-10-12 13:51:54.480490257 +0200
4fb1b2
@@ -314,7 +314,7 @@ static void fail_exit (int code)
4fb1b2
 static void get_defaults (void)
4fb1b2
 {
4fb1b2
 	FILE *fp;
4fb1b2
-	char* default_file = USER_DEFAULTS_FILE;
4fb1b2
+	char *default_file = USER_DEFAULTS_FILE;
4fb1b2
 	char buf[1024];
4fb1b2
 	char *cp;
4fb1b2
 
4fb1b2
@@ -324,6 +324,8 @@ static void get_defaults (void)
4fb1b2
 
4fb1b2
 		len = strlen(prefix) + strlen(USER_DEFAULTS_FILE) + 2;
4fb1b2
 		default_file = malloc(len);
4fb1b2
+                if (default_file == NULL)
4fb1b2
+                       return;
4fb1b2
 		wlen = snprintf(default_file, len, "%s/%s", prefix, USER_DEFAULTS_FILE);
4fb1b2
 		assert (wlen == (int) len -1);
4fb1b2
 	}
4fb1b2
@@ -334,7 +336,7 @@ static void get_defaults (void)
4fb1b2
 
4fb1b2
 	fp = fopen (default_file, "r");
4fb1b2
 	if (NULL == fp) {
4fb1b2
-		return;
4fb1b2
+		goto getdef_err;
4fb1b2
 	}
4fb1b2
 
4fb1b2
 	/*
4fb1b2
@@ -445,7 +447,7 @@ static void get_defaults (void)
4fb1b2
 		}
4fb1b2
 	}
4fb1b2
 	(void) fclose (fp);
4fb1b2
-
4fb1b2
+     getdef_err:
4fb1b2
 	if(prefix[0]) {
4fb1b2
 		free(default_file);
4fb1b2
 	}
4fb1b2
@@ -480,8 +482,8 @@ static int set_defaults (void)
4fb1b2
 	FILE *ifp;
4fb1b2
 	FILE *ofp;
4fb1b2
 	char buf[1024];
4fb1b2
-	char* new_file = NEW_USER_FILE;
4fb1b2
-	char* default_file = USER_DEFAULTS_FILE;
4fb1b2
+	char *new_file = NULL;
4fb1b2
+	char *default_file = USER_DEFAULTS_FILE;
4fb1b2
 	char *cp;
4fb1b2
 	int ofd;
4fb1b2
 	int wlen;
4fb1b2
@@ -492,17 +494,30 @@ static int set_defaults (void)
4fb1b2
 	bool out_shell = false;
4fb1b2
 	bool out_skel = false;
4fb1b2
 	bool out_create_mail_spool = false;
4fb1b2
+	size_t len;
4fb1b2
+	int ret = -1;
4fb1b2
 
4fb1b2
-	if(prefix[0]) {
4fb1b2
-		size_t len;
4fb1b2
 
4fb1b2
-		len = strlen(prefix) + strlen(NEW_USER_FILE) + 2;
4fb1b2
-		new_file = malloc(len);
4fb1b2
-		wlen = snprintf(new_file, len, "%s/%s", prefix, NEW_USER_FILE);
4fb1b2
-		assert (wlen == (int) len -1);
4fb1b2
+	len = strlen(prefix) + strlen(NEW_USER_FILE) + 2;
4fb1b2
+	new_file = malloc(len);
4fb1b2
+        if (new_file == NULL) {
4fb1b2
+		fprintf (stderr,
4fb1b2
+		         _("%s: cannot create new defaults file: %s\n"),
4fb1b2
+		         Prog, strerror(errno));
4fb1b2
+		return -1;
4fb1b2
+        }
4fb1b2
+	wlen = snprintf(new_file, len, "%s%s%s", prefix, prefix[0]?"/":"", NEW_USER_FILE);
4fb1b2
+	assert (wlen <= (int) len -1);
4fb1b2
 
4fb1b2
+	if(prefix[0]) {
4fb1b2
 		len = strlen(prefix) + strlen(USER_DEFAULTS_FILE) + 2;
4fb1b2
 		default_file = malloc(len);
4fb1b2
+		if (default_file == NULL) {
4fb1b2
+			fprintf (stderr,
4fb1b2
+			         _("%s: cannot create new defaults file: %s\n"),
4fb1b2
+			         Prog, strerror(errno));
4fb1b2
+			goto setdef_err;
4fb1b2
+		}
4fb1b2
 		wlen = snprintf(default_file, len, "%s/%s", prefix, USER_DEFAULTS_FILE);
4fb1b2
 		assert (wlen == (int) len -1);
4fb1b2
 	}
4fb1b2
@@ -515,7 +530,7 @@ static int set_defaults (void)
4fb1b2
 		fprintf (stderr,
4fb1b2
 		         _("%s: cannot create new defaults file\n"),
4fb1b2
 		         Prog);
4fb1b2
-		return -1;
4fb1b2
+		goto setdef_err;
4fb1b2
 	}
4fb1b2
 
4fb1b2
 	ofp = fdopen (ofd, "w");
4fb1b2
@@ -523,7 +538,7 @@ static int set_defaults (void)
4fb1b2
 		fprintf (stderr,
4fb1b2
 		         _("%s: cannot open new defaults file\n"),
4fb1b2
 		         Prog);
4fb1b2
-		return -1;
4fb1b2
+		goto setdef_err;
4fb1b2
 	}
4fb1b2
 
4fb1b2
 	/*
4fb1b2
@@ -550,7 +565,7 @@ static int set_defaults (void)
4fb1b2
 				         _("%s: line too long in %s: %s..."),
4fb1b2
 				         Prog, default_file, buf);
4fb1b2
 				(void) fclose (ifp);
4fb1b2
-				return -1;
4fb1b2
+				goto setdef_err;
4fb1b2
 			}
4fb1b2
 		}
4fb1b2
 
4fb1b2
@@ -614,7 +629,7 @@ static int set_defaults (void)
4fb1b2
 	    || (fsync (fileno (ofp)) != 0)
4fb1b2
 	    || (fclose (ofp) != 0)) {
4fb1b2
 		unlink (new_file);
4fb1b2
-		return -1;
4fb1b2
+		goto setdef_err;
4fb1b2
 	}
4fb1b2
 
4fb1b2
 	/*
4fb1b2
@@ -629,7 +644,7 @@ static int set_defaults (void)
4fb1b2
 		         _("%s: Cannot create backup file (%s): %s\n"),
4fb1b2
 		         Prog, buf, strerror (err));
4fb1b2
 		unlink (new_file);
4fb1b2
-		return -1;
4fb1b2
+		goto setdef_err;
4fb1b2
 	}
4fb1b2
 
4fb1b2
 	/*
4fb1b2
@@ -640,11 +655,11 @@ static int set_defaults (void)
4fb1b2
 		fprintf (stderr,
4fb1b2
 		         _("%s: rename: %s: %s\n"),
4fb1b2
 		         Prog, new_file, strerror (err));
4fb1b2
-		return -1;
4fb1b2
+		goto setdef_err;
4fb1b2
 	}
4fb1b2
 #ifdef WITH_AUDIT
4fb1b2
 	audit_logger (AUDIT_USYS_CONFIG, Prog,
4fb1b2
-	              "changing-useradd-defaults",
4fb1b2
+	              "changing useradd defaults",
4fb1b2
 	              NULL, AUDIT_NO_ID,
4fb1b2
 	              SHADOW_AUDIT_SUCCESS);
4fb1b2
 #endif
4fb1b2
@@ -654,13 +669,14 @@ static int set_defaults (void)
4fb1b2
 	         (unsigned int) def_group, def_home, def_shell,
4fb1b2
 	         def_inactive, def_expire, def_template,
4fb1b2
 	         def_create_mail_spool));
4fb1b2
-
4fb1b2
+	ret = 0;
4fb1b2
+    setdef_err:
4fb1b2
+	free(new_file);
4fb1b2
 	if(prefix[0]) {
4fb1b2
-		free(new_file);
4fb1b2
 		free(default_file);
4fb1b2
 	}
4fb1b2
 
4fb1b2
-	return 0;
4fb1b2
+	return ret;
4fb1b2
 }
4fb1b2
 
4fb1b2
 /*