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