Check for UNIX-doman socket name truncation

This commit is contained in:
Laslo Hunhold 2017-07-04 22:44:47 +02:00
parent d5a6e978b9
commit bdff59a5f6

View file

@ -841,6 +841,7 @@ static int
getusock(char *udsname) getusock(char *udsname)
{ {
struct sockaddr_un addr; struct sockaddr_un addr;
size_t udsnamelen;
int insock; int insock;
if ((insock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { if ((insock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
@ -849,7 +850,11 @@ getusock(char *udsname)
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX; addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, udsname, sizeof(addr.sun_path) - 1);
if ((udsnamelen = strlen(udsname)) > sizeof(addr.sun_path) - 1) {
die("%s: UNIX-domain socket name truncated\n", argv0);
}
memcpy(addr.sun_path, udsname, udsnamelen + 1);
unlink(udsname); unlink(udsname);