unix-server: guard against buffer overflow

sun_path is fairly small, and while the input is a smaller constant,
you never know how that might change.
This commit is contained in:
Vincent Penquerc'h 2013-12-28 06:25:31 -05:00 committed by Marek Marczykowski-Górecki
parent 21154a3e6b
commit 77d34c3096

View File

@ -44,7 +44,8 @@ int get_server_socket(char *socket_address)
} }
memset(&sockname, 0, sizeof(sockname)); memset(&sockname, 0, sizeof(sockname));
sockname.sun_family = AF_UNIX; sockname.sun_family = AF_UNIX;
memcpy(sockname.sun_path, socket_address, strlen(socket_address)); strncpy(sockname.sun_path, socket_address, sizeof sockname.sun_path);
sockname.sun_path[sizeof sockname.sun_path - 1] = 0;
if (bind(s, (struct sockaddr *) &sockname, sizeof(sockname)) == -1) { if (bind(s, (struct sockaddr *) &sockname, sizeof(sockname)) == -1) {
printf("bind() failed\n"); printf("bind() failed\n");