The unix socket path needs to be stored in sockaddr_un::sun_path. But
strncpy() is silently truncating the string when the target buffer is too
small.

Reject such paths with a clear error message.

Fixes: 6c6a6f735054 ("alfred: Make unix socket path configurable")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 gpsd/alfred-gpsd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gpsd/alfred-gpsd.c b/gpsd/alfred-gpsd.c
index 4a00526..eecf914 100644
--- a/gpsd/alfred-gpsd.c
+++ b/gpsd/alfred-gpsd.c
@@ -16,6 +16,12 @@ static int alfred_open_sock(struct globals *globals)
 {
        struct sockaddr_un addr;
 
+       if (strlen(globals->unix_path) >= sizeof(addr.sun_path)) {
+               fprintf(stderr, "unix socket path too long\n");
+               globals->unix_sock = -1;
+               return -1;
+       }
+
        globals->unix_sock = socket(AF_LOCAL, SOCK_STREAM, 0);
        if (globals->unix_sock < 0) {
                perror("can't create unix socket");

-- 
2.47.3

Reply via email to