Blame SOURCES/quota-4.04-warnquota-Fix-comparing-user-name-to-non-null-termin.patch

273bc0
From 59b280ebe22eceaf4250cb3b776674619a4d4ece Mon Sep 17 00:00:00 2001
273bc0
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
273bc0
Date: Mon, 5 Feb 2018 11:07:41 +0100
273bc0
Subject: [PATCH] warnquota: Fix comparing user name to non-null-terminated
273bc0
 utmp.ut_user
273bc0
MIME-Version: 1.0
273bc0
Content-Type: text/plain; charset=UTF-8
273bc0
Content-Transfer-Encoding: 8bit
273bc0
273bc0
GCC 8 with GNU libc 2.27 warns:
273bc0
273bc0
gcc -DHAVE_CONFIG_H -I.    -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include  -I/usr/include/libnl3  -g -O2 -Wall -fPIC -I/usr/include/tirpc  -c -o quota_nld-quota_nld.o `test -f 'quota_nld.c' || echo './'`quota_nld.c
273bc0
quota_nld.c: In function ‘write_console_warning’:
273bc0
quota_nld.c:273:7: warning: ‘strcmp’ argument 2 declared attribute ‘nonstring’ [-Wstringop-overflow=]
273bc0
   if (strcmp(user, uent->ut_user))
273bc0
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
273bc0
In file included from /usr/include/utmp.h:29,
273bc0
                 from quota_nld.c:23:
273bc0
/usr/include/bits/utmp.h:65:8: note: argument ‘ut_user’ declared here
273bc0
   char ut_user[UT_NAMESIZE]
273bc0
        ^~~~~~~
273bc0
273bc0
This is because ut_user value misses the terminating null byte if it
273bc0
fits exactly into ut_user array, as document in utmp(5):
273bc0
273bc0
    String fields are terminated by a null byte ('\0') if they are
273bc0
    shorter than  the size of the field.
273bc0
273bc0
Recent GCC and glibc recevied compile-time checks and annotations
273bc0
(__attribute_nonstring_) that catches these mistakes.
273bc0
273bc0
This patch fixes it by using strncmp(3) and by ignoring user names
273bc0
that does not fit into utmp log format. It's better not to warn than
273bc0
spamming unrelated user.
273bc0
273bc0
Signed-off-by: Petr Písař <ppisar@redhat.com>
273bc0
Signed-off-by: Jan Kara <jack@suse.cz>
273bc0
---
273bc0
 quota_nld.c | 5 ++++-
273bc0
 1 file changed, 4 insertions(+), 1 deletion(-)
273bc0
273bc0
diff --git a/quota_nld.c b/quota_nld.c
273bc0
index ea541e0..8559f25 100644
273bc0
--- a/quota_nld.c
273bc0
+++ b/quota_nld.c
273bc0
@@ -262,6 +262,8 @@ static void write_console_warning(struct quota_warning *warn)
273bc0
 	    warn->warntype == QUOTA_NL_BSOFTBELOW) && !(flags & FL_PRINTBELOW))
273bc0
 		return;
273bc0
 	uid2user(warn->caused_id, user);
273bc0
+	if (strlen(user) > UT_NAMESIZE)
273bc0
+		goto skip_utmp;
273bc0
 	strcpy(dev, "/dev/");
273bc0
 
273bc0
 	setutent();
273bc0
@@ -270,7 +272,7 @@ static void write_console_warning(struct quota_warning *warn)
273bc0
 		if (uent->ut_type != USER_PROCESS)
273bc0
 			continue;
273bc0
 		/* Entry for a different user? */
273bc0
-		if (strcmp(user, uent->ut_user))
273bc0
+		if (strncmp(user, uent->ut_user, UT_NAMESIZE))
273bc0
 			continue;
273bc0
 		sstrncpy(dev+5, uent->ut_line, PATH_MAX-5);
273bc0
 		if (stat(dev, &st) < 0)
273bc0
@@ -281,6 +283,7 @@ static void write_console_warning(struct quota_warning *warn)
273bc0
 		}
273bc0
 	}
273bc0
 	if (!max_atime) {
273bc0
+skip_utmp:
273bc0
 		/*
273bc0
 		 * This can happen quite easily so don't spam syslog with
273bc0
 		 * the error
273bc0
-- 
273bc0
2.13.6
273bc0