mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Use dm_strncpy instead of plain strncpy while setting the socket path.
Also check the return value as it meaningless to work with truncated strings.
This commit is contained in:
parent
e5b9338ada
commit
bf29fa49d3
@ -32,7 +32,10 @@ daemon_handle daemon_open(daemon_info i) {
|
||||
goto error;
|
||||
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path));
|
||||
if (!dm_strncpy(sockaddr.sun_path, i.socket, sizeof(sockaddr.sun_path))) {
|
||||
fprintf(stderr, "%s: daemon socket path too long.\n", i.socket);
|
||||
goto error;
|
||||
}
|
||||
sockaddr.sun_family = AF_UNIX;
|
||||
if (connect(h.socket_fd,(struct sockaddr *) &sockaddr, sizeof(sockaddr)))
|
||||
goto error;
|
||||
|
@ -224,7 +224,10 @@ static int _open_socket(daemon_state s)
|
||||
|
||||
fprintf(stderr, "[D] creating %s\n", s.socket_path);
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path));
|
||||
if (!dm_strncpy(sockaddr.sun_path, s.socket_path, sizeof(sockaddr.sun_path))) {
|
||||
fprintf(stderr, "%s: daemon socket path too long.\n", s.socket_path);
|
||||
goto error;
|
||||
}
|
||||
sockaddr.sun_family = AF_UNIX;
|
||||
|
||||
if (bind(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
|
||||
|
Loading…
Reference in New Issue
Block a user