dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

Blame SOURCES/0163-sulogin-don-t-use-strcpy-enlarge-pwd-line-buffer.patch

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