Skip to content

Commit 93e96f1

Browse files
committed
session server BUGFIX check UNIX socket length
1 parent 86f8ed3 commit 93e96f1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/session_server.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ nc_sock_listen_unix(const char *address, const struct nc_server_unix_opts *opts)
285285
struct sockaddr_un sun;
286286
int sock = -1;
287287

288+
if (strlen(address) > sizeof(sun.sun_path) - 1) {
289+
ERR(NULL, "Socket path \"%s\" is longer than maximum length %d.", address, (int)(sizeof(sun.sun_path) - 1));
290+
goto fail;
291+
}
292+
288293
sock = socket(AF_UNIX, SOCK_STREAM, 0);
289294
if (sock == -1) {
290295
ERR(NULL, "Failed to create socket (%s).", strerror(errno));
@@ -293,7 +298,7 @@ nc_sock_listen_unix(const char *address, const struct nc_server_unix_opts *opts)
293298

294299
memset(&sun, 0, sizeof(sun));
295300
sun.sun_family = AF_UNIX;
296-
snprintf(sun.sun_path, sizeof(sun.sun_path), "%s", address);
301+
snprintf(sun.sun_path, sizeof(sun.sun_path) - 1, "%s", address);
297302

298303
unlink(sun.sun_path);
299304
if (bind(sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
@@ -326,7 +331,6 @@ nc_sock_listen_unix(const char *address, const struct nc_server_unix_opts *opts)
326331
if (sock > -1) {
327332
close(sock);
328333
}
329-
330334
return -1;
331335
}
332336

0 commit comments

Comments
 (0)