cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
05ad79
From 94f380e223e7496804dcd68e204fba0a15df8bd7 Mon Sep 17 00:00:00 2001
05ad79
From: Karel Zak <kzak@redhat.com>
05ad79
Date: Mon, 25 May 2015 15:24:13 +0200
05ad79
Subject: [PATCH 163/173] sulogin: don't use strcpy(), enlarge pwd line buffer
05ad79
05ad79
* according to "man getpwnam" 16384 bytes is enough to store one
05ad79
  passwd entry (let's use 2*BUFSIZE to avoid magic numbers in code)
05ad79
05ad79
* don't use strcpy() to set empty password
05ad79
05ad79
Upstream: http://github.com/karelzak/util-linux/commit/d681e0956cdca1a016346424939fe1b9c6a0a549
05ad79
Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1561200
05ad79
Signed-off-by: Karel Zak <kzak@redhat.com>
05ad79
---
05ad79
 login-utils/sulogin.c | 14 +++++++-------
05ad79
 1 file changed, 7 insertions(+), 7 deletions(-)
05ad79
05ad79
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
05ad79
index bbd67b3ee..6d03bc5ae 100644
05ad79
--- a/login-utils/sulogin.c
05ad79
+++ b/login-utils/sulogin.c
05ad79
@@ -373,8 +373,8 @@ static struct passwd *getrootpwent(int try_manually)
05ad79
 	struct passwd *pw;
05ad79
 	struct spwd *spw;
05ad79
 	FILE *fp;
05ad79
-	static char line[256];
05ad79
-	static char sline[256];
05ad79
+	static char line[2 * BUFSIZ];
05ad79
+	static char sline[2 * BUFSIZ];
05ad79
 	char *p;
05ad79
 
05ad79
 	/*
05ad79
@@ -410,7 +410,7 @@ static struct passwd *getrootpwent(int try_manually)
05ad79
 	/*
05ad79
 	 * Find root in the password file.
05ad79
 	 */
05ad79
-	while ((p = fgets(line, 256, fp)) != NULL) {
05ad79
+	while ((p = fgets(line, sizeof(line), fp)) != NULL) {
05ad79
 		if (strncmp(line, "root:", 5) != 0)
05ad79
 			continue;
05ad79
 		p += 5;
05ad79
@@ -439,12 +439,12 @@ static struct passwd *getrootpwent(int try_manually)
05ad79
 	/*
05ad79
 	 * The password is invalid. If there is a shadow password, try it.
05ad79
 	 */
05ad79
-	strcpy(pwd.pw_passwd, "");
05ad79
+	*pwd.pw_passwd = '\0';
05ad79
 	if ((fp = fopen(_PATH_SHADOW_PASSWD, "r")) == NULL) {
05ad79
 		warn(_("cannot open %s"), _PATH_PASSWD);
05ad79
 		return &pw;;
05ad79
 	}
05ad79
-	while ((p = fgets(sline, 256, fp)) != NULL) {
05ad79
+	while ((p = fgets(sline, sizeof(sline), fp)) != NULL) {
05ad79
 		if (strncmp(sline, "root:", 5) != 0)
05ad79
 			continue;
05ad79
 		p += 5;
05ad79
@@ -458,11 +458,11 @@ static struct passwd *getrootpwent(int try_manually)
05ad79
 	 */
05ad79
 	if (p == NULL) {
05ad79
 		warnx(_("%s: no entry for root"), _PATH_SHADOW_PASSWD);
05ad79
-		strcpy(pwd.pw_passwd, "");
05ad79
+		*pwd.pw_passwd = '\0';
05ad79
 	}
05ad79
 	if (!valid(pwd.pw_passwd)) {
05ad79
 		warnx(_("%s: root password garbled"), _PATH_SHADOW_PASSWD);
05ad79
-		strcpy(pwd.pw_passwd, "");
05ad79
+		*pwd.pw_passwd = '\0';
05ad79
 	}
05ad79
 	return &pw;;
05ad79
 }
05ad79
-- 
05ad79
2.14.4
05ad79