mirror of
git://github.com/lxc/lxc
synced 2025-08-29 17:49:50 +00:00
make lxc_af_unix_open() safely return error on long pathnames
Signed-off-by: Dwight Engen <dwight.engen@oracle.com> Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
599d425251
commit
ddb17f1f08
@ -36,6 +36,7 @@ lxc_log_define(lxc_af_unix, lxc);
|
||||
int lxc_af_unix_open(const char *path, int type, int flags)
|
||||
{
|
||||
int fd;
|
||||
size_t len;
|
||||
struct sockaddr_un addr;
|
||||
|
||||
if (flags & O_TRUNC)
|
||||
@ -52,8 +53,16 @@ int lxc_af_unix_open(const char *path, int type, int flags)
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
/* copy entire buffer in case of abstract socket */
|
||||
memcpy(addr.sun_path, path,
|
||||
path[0]?strlen(path):sizeof(addr.sun_path));
|
||||
len = sizeof(addr.sun_path);
|
||||
if (path[0]) {
|
||||
len = strlen(path);
|
||||
if (len >= sizeof(addr.sun_path)) {
|
||||
close(fd);
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
memcpy(addr.sun_path, path, len);
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr))) {
|
||||
int tmp = errno;
|
||||
|
Loading…
x
Reference in New Issue
Block a user