]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/path: fix read string to be backwardly compatible
authorKarel Zak <kzak@redhat.com>
Tue, 15 May 2018 12:11:38 +0000 (14:11 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Jun 2018 11:07:46 +0000 (13:07 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/path.c

index 998dce5bb4b7229a594d3a126d3f03e1ed72b26a..c665196a995af00b41c6b877b6dc4b3166efaa89 100644 (file)
@@ -505,6 +505,10 @@ int ul_path_read_string(struct path_cxt *pc, char **str, const char *path)
        if (rc < 0 || !str)
                return rc;;
 
+       /* Remove tailing newline (usuall in sysfs) */
+       if (rc > 0 && *(buf + rc - 1) == '\n')
+               --rc;
+
        buf[rc] = '\0';
        *str = strdup(buf);
        if (!*str)