From 28c13a3e38e8b350ffadb1ae7c2687aafe7ac6c0 Mon Sep 17 00:00:00 2001 From: Ivan Davydov Date: Tue, 17 Jun 2025 17:03:48 +0300 Subject: Re-worked handling of too long socket paths --- acccre-server | Bin 0 -> 7944 bytes acccre-server.c | 10 +++++----- acccre-server.h | 3 +++ acccre-server.o | Bin 0 -> 5312 bytes 4 files changed, 8 insertions(+), 5 deletions(-) create mode 100755 acccre-server create mode 100644 acccre-server.o diff --git a/acccre-server b/acccre-server new file mode 100755 index 0000000..9e524ad Binary files /dev/null and b/acccre-server differ diff --git a/acccre-server.c b/acccre-server.c index 310317a..a3c1896 100644 --- a/acccre-server.c +++ b/acccre-server.c @@ -85,13 +85,13 @@ int main (int argc, char *argv[]) { DEFAULT_PATH /* sun_path */ }; if (argc > 1) { - /* Taken from https://pubs.opengroup.org/onlinepubs/9799919799/ */ - if (sizeof(argv[1]) >= sizeof(((struct sockaddr_un *)0)->sun_path)) { - strcpy(sun.sun_path, argv[1]); + size_t sun_path_length = strlen(argv[1]); + if (sun_path_length >= MAX_SUN_PATH) { + fprintf(stderr, "Size of path to the socket (%zu) is greater than, or equal to the maximum size (%zu).\n", sun_path_length, MAX_SUN_PATH); + exit(EXIT_FAILURE); } else { - fprintf(stderr, "Path to the socket is longer than %zu.\n", sizeof(((struct sockaddr_un *)0)->sun_path)); - exit(EXIT_FAILURE); + strcpy(sun.sun_path, argv[1]); } } diff --git a/acccre-server.h b/acccre-server.h index 7ffd84b..d030c6b 100644 --- a/acccre-server.h +++ b/acccre-server.h @@ -22,4 +22,7 @@ const int sigs[] = { #define BUFFER_SIZE 100 #define DEFAULT_PATH "./acccre.sock" +/* Taken from https://pubs.opengroup.org/onlinepubs/9799919799/ */ +#define MAX_SUN_PATH sizeof(((struct sockaddr_un *)0)->sun_path) typedef uint16_t acccre_size_t; + diff --git a/acccre-server.o b/acccre-server.o new file mode 100644 index 0000000..961cce2 Binary files /dev/null and b/acccre-server.o differ -- cgit v1.2.3