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