Skip to content

Commit

Permalink
lib/sysfs: zero-terminate result of sysfs_blkdev_get_devchain()
Browse files Browse the repository at this point in the history
sysfs_blkdev_get_devchain() does not zero-terminate its result, but the
caller expects a C-string.
Use ul_buffer_get_string() which includes a trailing zero-byte.

Now it's also valid for sz and bufsz to be equal.

See #3088.
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
  • Loading branch information
t-8ch committed Jun 13, 2024
1 parent 49e177d commit 24e3ede
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ char *sysfs_blkdev_get_devchain(struct path_cxt *pc, char *buf, size_t bufsz)
ul_buffer_append_string(&tmp, _PATH_SYS_DEVBLOCK "/");
ul_buffer_append_data(&tmp, buf, ssz);

p = ul_buffer_get_data(&tmp, &sz, NULL);
if (p && sz < bufsz) {
p = ul_buffer_get_string(&tmp, &sz, NULL);
if (p && sz <= bufsz) {
memcpy(buf, p, sz);
res = buf;
}
Expand Down

0 comments on commit 24e3ede

Please sign in to comment.