]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
sulogin: Use read instead of allocated size from getline()
authorGuillem Jover <guillem@hadrons.org>
Sat, 6 Jun 2015 04:26:43 +0000 (06:26 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 8 Jun 2015 10:10:05 +0000 (12:10 +0200)
The getline function distinguishes between the allocated and read
lenghts, and we should not mix them up, as we might end up processing
junk.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
login-utils/sulogin-consoles.c

index 9fd10340562410a5d1e09d58738d33e1007dfe25..39d24d293f987788aa6b52a8eb5df195d257e355 100644 (file)
@@ -154,13 +154,15 @@ char *oneline(const char *file)
 {
        FILE *fp;
        char *ret = NULL;
-       size_t len = 0;
+       size_t dummy = 0;
+       ssize_t len;
 
        DBG(dbgprint("reading %s", file));
 
        if (!(fp = fopen(file, "re")))
                return NULL;
-       if (getline(&ret, &len, fp) >= 0) {
+       len = getline(&ret, &dummy, fp);
+       if (len >= 0) {
                char *nl;
 
                if (len)