lib/path: fix read string to be backwardly compatible

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2018-05-15 14:11:38 +02:00
parent bcf445fd68
commit d5878cabe6
1 changed files with 4 additions and 0 deletions

View 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)