From dd695ee5a773267865665afb6627e8c12e956987 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 5 May 2026 13:10:21 +0200 Subject: [PATCH] modules: handle allocation errors gracefully --- spa/plugins/videoconvert/videoconvert-ffmpeg.c | 4 ++++ src/modules/module-combine-stream.c | 2 ++ src/modules/module-ffado-driver.c | 5 ++++- src/modules/module-rtp-sap.c | 16 +++++++++++++--- src/modules/module-rtp-session.c | 6 ++++++ src/modules/module-snapcast-discover.c | 6 ++++++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/spa/plugins/videoconvert/videoconvert-ffmpeg.c b/spa/plugins/videoconvert/videoconvert-ffmpeg.c index 3a556eede..40acea1ac 100644 --- a/spa/plugins/videoconvert/videoconvert-ffmpeg.c +++ b/spa/plugins/videoconvert/videoconvert-ffmpeg.c @@ -2015,6 +2015,8 @@ static int port_set_peer_enum_format(void *object, if (formats) { uint32_t count = 0; port->peer_format_pod = spa_pod_copy(formats); + if (port->peer_format_pod == NULL) + return -errno; for (i = 0; i < SPA_N_ELEMENTS(subtypes); i++) { state = NULL; @@ -2028,6 +2030,8 @@ static int port_set_peer_enum_format(void *object, } } port->peer_formats = calloc(count, sizeof(struct spa_pod *)); + if (port->peer_formats == NULL) + return -errno; for (i = 0; i < SPA_N_ELEMENTS(subtypes); i++) { state = NULL; while (spa_peer_param_parse(port->peer_format_pod, &info, sizeof(info), &state) > 0) { diff --git a/src/modules/module-combine-stream.c b/src/modules/module-combine-stream.c index f5b128456..4efef2117 100644 --- a/src/modules/module-combine-stream.c +++ b/src/modules/module-combine-stream.c @@ -931,6 +931,8 @@ static int create_stream(struct stream_info *info) if (info->on_demand_id) { s->on_demand_id = strdup(info->on_demand_id); + if (s->on_demand_id == NULL) + goto error_errno; pw_properties_set(info->stream_props, "combine.on-demand-id", s->on_demand_id); } else { if (pw_properties_get(info->stream_props, PW_KEY_TARGET_OBJECT) == NULL) diff --git a/src/modules/module-ffado-driver.c b/src/modules/module-ffado-driver.c index c98b0efcd..69646f742 100644 --- a/src/modules/module-ffado-driver.c +++ b/src/modules/module-ffado-driver.c @@ -1410,7 +1410,10 @@ static void parse_devices(struct impl *impl, const char *val, size_t len) impl->n_devices = 0; while (spa_json_get_string(&it[0], v, sizeof(v)) > 0 && impl->n_devices < FFADO_MAX_SPECSTRINGS) { - impl->devices[impl->n_devices++] = strdup(v); + char *s = strdup(v); + if (s == NULL) + return; + impl->devices[impl->n_devices++] = s; } } diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index 220fe6d77..f4dc321cf 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -1532,6 +1532,8 @@ static int parse_sdp_m(struct impl *impl, char *c, struct sdp_info *info) return -EINVAL; info->media_type = strdup(media_type); + if (info->media_type == NULL) + return -errno; info->dst_port = (uint16_t) port; info->payload = (uint8_t) payload; @@ -1583,6 +1585,8 @@ static int parse_sdp_a_rtpmap(struct impl *impl, char *c, struct sdp_info *info) c += len; c[strcspn(c, "/")] = 0; info->mime_type = strdup(c); + if (info->mime_type == NULL) + return -errno; c += strlen(c) + 1; if (sscanf(c, "%u/%u", &rate, &channels) == 2) { @@ -1647,6 +1651,8 @@ static int parse_sdp_a_ts_refclk(struct impl *impl, char *c, struct sdp_info *in c += strlen("a=ts-refclk:"); info->ts_refclk = strdup(c); + if (info->ts_refclk == NULL) + return -errno; return 0; } @@ -1668,11 +1674,15 @@ static int parse_sdp(struct impl *impl, char *sdp, struct sdp_info *info) if (count++ == 0 && strcmp(s, "v=0") != 0) goto invalid_version; - if (spa_strstartswith(s, "o=")) + if (spa_strstartswith(s, "o=")) { info->origin = strdup(&s[2]); - else if (spa_strstartswith(s, "s=")) + if (info->origin == NULL) + res = -errno; + } else if (spa_strstartswith(s, "s=")) { info->session_name = strdup(&s[2]); - else if (spa_strstartswith(s, "c=")) + if (info->session_name == NULL) + res = -errno; + } else if (spa_strstartswith(s, "c=")) res = parse_sdp_c(impl, s, info); else if (spa_strstartswith(s, "m=")) res = parse_sdp_m(impl, s, info); diff --git a/src/modules/module-rtp-session.c b/src/modules/module-rtp-session.c index 671fac2c4..54fe9a65c 100644 --- a/src/modules/module-rtp-session.c +++ b/src/modules/module-rtp-session.c @@ -622,6 +622,12 @@ static struct session *make_session(struct impl *impl, struct service_info *info str = pw_properties_get(props, "sess.name"); sess->name = str ? strdup(str) : strdup("RTP Session"); + if (sess->info.name == NULL || sess->info.type == NULL || + sess->info.domain == NULL || sess->name == NULL) { + free_session(sess); + goto error; + } + if (impl->ts_refclk != NULL) pw_properties_setf(props, "rtp.sender-ts-offset", "%u", impl->ts_offset); pw_properties_setf(props, "rtp.sender-ssrc", "%u", sess->ssrc); diff --git a/src/modules/module-snapcast-discover.c b/src/modules/module-snapcast-discover.c index 8ce133f18..cb13371e1 100644 --- a/src/modules/module-snapcast-discover.c +++ b/src/modules/module-snapcast-discover.c @@ -497,6 +497,8 @@ static int add_snapcast_stream(struct impl *impl, struct tunnel *t, while (spa_json_get_string(&it[0], v, sizeof(v)) > 0) { t->server_address = strdup(v); + if (t->server_address == NULL) + return -errno; snapcast_connect(t); return 0; } @@ -544,6 +546,8 @@ static int create_stream(struct impl *impl, struct pw_properties *props, if ((str = pw_properties_get(props, "snapcast.stream-name")) == NULL) str = "PipeWire"; t->stream_name = strdup(str); + if (t->stream_name == NULL) + return -errno; if ((str = pw_properties_get(props, "capture")) == NULL) pw_properties_set(props, "capture", "true"); @@ -662,6 +666,8 @@ static void on_zeroconf_added(void *data, const void *user, const struct spa_dic free((char*)t->info.host); t->info.host = strdup(pw_properties_get(props, "snapcast.ip")); + if (t->info.host == NULL) + return; family = protocol == 4 ? AF_INET : AF_INET6;