From 5dfd77538405a3fdb0793fe52d55a5ea20dcdbb0 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 8 Feb 2012 11:05:04 +0000 Subject: Ensure strncpy() function always ends with '\0' Since last character needs to be \0 for string, pass buffer size smaller by 1 byte. --- libdm/libdm-common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdm/libdm-common.c') diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index a4a351ed..2fb5e5e5 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -706,7 +706,7 @@ int get_dev_node_read_ahead(const char *dev_name, uint32_t major, uint32_t minor if ((fd = open(_path0, O_RDONLY, 0)) != -1) { /* Reading from sysfs, expecting number\n */ - if ((len = read(fd, buf, sizeof(buf))) < 1) { + if ((len = read(fd, buf, sizeof(buf) - 1)) < 1) { log_sys_error("read", _path0); r = 0; } else { @@ -1256,7 +1256,7 @@ static int _sysfs_get_kernel_name(uint32_t major, uint32_t minor, char *buf, siz goto error; } - if ((size = readlink(sysfs_path, temp_buf, PATH_MAX)) < 0) { + if ((size = readlink(sysfs_path, temp_buf, PATH_MAX - 1)) < 0) { if (errno != ENOENT) log_sys_error("readlink", sysfs_path); else -- cgit