mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Ensure strncpy() function always ends with '\0'
Since last character needs to be \0 for string, pass buffer size smaller by 1 byte.
This commit is contained in:
parent
cd4c26a27f
commit
5dfd775384
@ -1,5 +1,6 @@
|
||||
Version 2.02.91 -
|
||||
===================================
|
||||
Ensure strncpy() function always ends with '\0'.
|
||||
Set status in _fsadm_cmd() for error path.
|
||||
Add missing deps for lvm2api for rebuild when lvm-internal is changed.
|
||||
Fix resource leaks for failing allocation of formats (lvm1/2,pool).
|
||||
|
@ -1,5 +1,6 @@
|
||||
Version 1.02.70 -
|
||||
===================================
|
||||
Leave space for '\0' for readline() call in _sysfs_get_kernel_name().
|
||||
|
||||
Version 1.02.69 - 1st February 2012
|
||||
===================================
|
||||
|
@ -254,8 +254,10 @@ static int _compare_paths(const char *path0, const char *path1)
|
||||
if (slash1 < slash0)
|
||||
return 1;
|
||||
|
||||
strncpy(p0, path0, PATH_MAX);
|
||||
strncpy(p1, path1, PATH_MAX);
|
||||
strncpy(p0, path0, sizeof(p0) - 1);
|
||||
p0[sizeof(p0) - 1] = '\0';
|
||||
strncpy(p1, path1, sizeof(p1) - 1);
|
||||
p1[sizeof(p1) - 1] = '\0';
|
||||
s0 = p0 + 1;
|
||||
s1 = p1 + 1;
|
||||
|
||||
|
@ -459,7 +459,8 @@ int lock_vol(struct cmd_context *cmd, const char *vol, uint32_t flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
strncpy(resource, vol, sizeof(resource));
|
||||
strncpy(resource, vol, sizeof(resource) - 1);
|
||||
resource[sizeof(resource) - 1] = '\0';
|
||||
|
||||
if (!_lock_vol(cmd, resource, flags, lv_op))
|
||||
return_0;
|
||||
|
@ -136,7 +136,7 @@ void fin_syslog(void)
|
||||
|
||||
void init_msg_prefix(const char *prefix)
|
||||
{
|
||||
strncpy(_msg_prefix, prefix, sizeof(_msg_prefix));
|
||||
strncpy(_msg_prefix, prefix, sizeof(_msg_prefix) - 1);
|
||||
_msg_prefix[sizeof(_msg_prefix) - 1] = '\0';
|
||||
}
|
||||
|
||||
|
@ -165,13 +165,13 @@ void init_detect_internal_vg_cache_corruption(int detect)
|
||||
|
||||
void set_cmd_name(const char *cmd)
|
||||
{
|
||||
strncpy(_cmd_name, cmd, sizeof(_cmd_name));
|
||||
strncpy(_cmd_name, cmd, sizeof(_cmd_name) - 1);
|
||||
_cmd_name[sizeof(_cmd_name) - 1] = '\0';
|
||||
}
|
||||
|
||||
void set_sysfs_dir_path(const char *path)
|
||||
{
|
||||
strncpy(_sysfs_dir_path, path, sizeof(_sysfs_dir_path));
|
||||
strncpy(_sysfs_dir_path, path, sizeof(_sysfs_dir_path) - 1);
|
||||
_sysfs_dir_path[sizeof(_sysfs_dir_path) - 1] = '\0';
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,10 @@ void get_shared_library_path(struct cmd_context *cmd, const char *libname,
|
||||
if (libname[0] == '/' ||
|
||||
!(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
|
||||
(dm_snprintf(path, path_len, "%s/%s", lib_dir,
|
||||
libname) == -1) || stat(path, &info) == -1)
|
||||
strncpy(path, libname, path_len);
|
||||
libname) == -1) || stat(path, &info) == -1) {
|
||||
strncpy(path, libname, path_len - 1);
|
||||
path[path_len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void *load_shared_library(struct cmd_context *cmd, const char *libname,
|
||||
|
@ -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
|
||||
|
@ -3059,7 +3059,8 @@ static char *parse_loop_device_name(const char *dev, const char *dev_dir)
|
||||
device[strlen(dev_dir)] != '/')
|
||||
goto error;
|
||||
|
||||
strncpy(buf, strrchr(device, '/') + 1, (size_t) PATH_MAX);
|
||||
strncpy(buf, strrchr(device, '/') + 1, PATH_MAX - 1);
|
||||
buf[PATH_MAX - 1] = '\0';
|
||||
dm_free(device);
|
||||
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user