]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: make sure ul_path_read_buffer() derminate result
authorKarel Zak <kzak@redhat.com>
Thu, 6 Jun 2019 09:09:17 +0000 (11:09 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Jun 2019 13:47:39 +0000 (15:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/path.c

index f7fd19592447b3e929751f6c7447e2cdb673b2cc..8dce1da408907dc9be249780244489e6753b2a59 100644 (file)
@@ -610,9 +610,10 @@ int ul_path_read_buffer(struct path_cxt *pc, char *buf, size_t bufsz, const char
 
        /* Remove tailing newline (usual in sysfs) */
        if (rc > 0 && *(buf + rc - 1) == '\n')
-               --rc;
+               buf[--rc] = '\0';
+       else
+               buf[rc - 1] = '\0';
 
-       buf[rc] = '\0';
        return rc;
 }