From 96b43dd6e5a49eb10a81208bc5763ccd00d8cac6 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 4 Dec 2024 16:16:02 +0100 Subject: [PATCH] aplay/mixer: restricting senders - check err --- src/audio/playback/mixer.cpp | 24 ++++++++++++++++-------- src/utils/net.c | 3 +-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/audio/playback/mixer.cpp b/src/audio/playback/mixer.cpp index c178e603f..34c659135 100644 --- a/src/audio/playback/mixer.cpp +++ b/src/audio/playback/mixer.cpp @@ -330,14 +330,22 @@ state_audio_mixer::check_messages() MSG(INFO, "flushing the address restriction (defaulting to mix all)\n"); only_sender.ss_family = AF_UNSPEC; } else { - MSG(INFO, "restricting mixer to: %s\n", val); - only_sender = get_sockaddr(val, 0); - if (participants.find(only_sender) == - participants.end()) { - MSG(WARNING, - "The requested participant %s is not yet " - "present...\n", - val); + struct sockaddr_storage ss = get_sockaddr(val, 0); + if (ss.ss_family != AF_UNSPEC) { + MSG(INFO, "restricting mixer to: %s\n", val); + only_sender = ss; + if (participants.find(only_sender) == + participants.end()) { + MSG(WARNING, + "The requested participant %s is " + "not yet present...\n", val); + } + } else { + MSG(ERROR, "Wrong addr spec: %s\n", val); + free_message(msg, + new_response(RESPONSE_BAD_REQUEST, + nullptr)); + continue; } } diff --git a/src/utils/net.c b/src/utils/net.c index 96ebd5662..7cbba0442 100644 --- a/src/utils/net.c +++ b/src/utils/net.c @@ -477,11 +477,10 @@ get_sockaddr_str(const struct sockaddr *sa, unsigned sa_len, char *buf, struct sockaddr_storage get_sockaddr(const char *hostport, int mode) { - struct sockaddr_storage ret; + struct sockaddr_storage ret = { .ss_family = AF_UNSPEC }; socklen_t socklen_unused = 0; char host[STR_LEN]; - ret.ss_family = AF_UNSPEC; const char *const rightmost_colon = strrchr(hostport, ':'); if (rightmost_colon == NULL) { MSG(ERROR, "Address %s not in format host:port!\n", hostport);