netjack2: check config against MAX_CHANNELS

Check that the params don't include more than MAX_CHANNELS of audio or
else we overflow the position array.

Adapt to the compiled value of SPA_AUDIO_MAX_CHANNELS but allow at least
128 channels.
This commit is contained in:
Wim Taymans 2026-05-08 11:07:03 +02:00
parent 6cee86e509
commit 753eae9302
3 changed files with 17 additions and 14 deletions

View file

@ -139,8 +139,6 @@
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define PW_LOG_TOPIC_DEFAULT mod_topic
#define MAX_PORTS 128
#define DEFAULT_NET_IP "225.3.19.154"
#define DEFAULT_NET_PORT 19000
#define DEFAULT_NET_TTL 1
@ -865,7 +863,8 @@ static int handle_follower_setup(struct impl *impl, struct nj2_session_params *p
pw_loop_update_io(impl->main_loop, impl->setup_socket, 0);
impl->sink.n_ports = peer->params.send_audio_channels + peer->params.send_midi_channels;
if (impl->sink.n_ports > MAX_PORTS) {
if (impl->sink.n_ports > MAX_PORTS ||
(uint32_t)peer->params.send_audio_channels > MAX_CHANNELS) {
pw_log_warn("Too many follower sink ports %d > %d", impl->sink.n_ports, MAX_PORTS);
return -EINVAL;
}
@ -876,7 +875,8 @@ static int handle_follower_setup(struct impl *impl, struct nj2_session_params *p
impl->sink.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
}
impl->source.n_ports = peer->params.recv_audio_channels + peer->params.recv_midi_channels;
if (impl->source.n_ports > MAX_PORTS) {
if (impl->source.n_ports > MAX_PORTS ||
(uint32_t)peer->params.recv_audio_channels > MAX_CHANNELS) {
pw_log_warn("Too many follower source ports %d > %d", impl->source.n_ports, MAX_PORTS);
return -EINVAL;
}

View file

@ -139,8 +139,6 @@
PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
#define PW_LOG_TOPIC_DEFAULT mod_topic
#define MAX_PORTS 128
#define DEFAULT_NET_IP "225.3.19.154"
#define DEFAULT_NET_PORT 19000
#define DEFAULT_NET_TTL 1
@ -1050,26 +1048,29 @@ static int handle_follower_available(struct impl *impl, struct nj2_session_param
peer->params.recv_midi_channels = follower->source.n_midi;
follower->source.n_ports = peer->params.recv_audio_channels + peer->params.recv_midi_channels;
follower->sink.n_ports = peer->params.send_audio_channels + peer->params.send_midi_channels;
if (follower->source.n_ports > MAX_PORTS || follower->sink.n_ports > MAX_PORTS ||
(uint32_t)peer->params.recv_audio_channels > MAX_CHANNELS ||
(uint32_t)peer->params.send_audio_channels > MAX_CHANNELS) {
pw_log_error("too many ports source:%d sink:%d max:%d", follower->source.n_ports,
follower->sink.n_ports, MAX_PORTS);
res = -EINVAL;
goto cleanup;
}
follower->source.info.rate = peer->params.sample_rate;
if ((uint32_t)peer->params.recv_audio_channels != follower->source.info.channels) {
follower->source.info.channels = peer->params.recv_audio_channels;
for (i = 0; i < follower->source.info.channels; i++)
follower->source.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
}
follower->sink.n_ports = peer->params.send_audio_channels + peer->params.send_midi_channels;
follower->sink.info.rate = peer->params.sample_rate;
if ((uint32_t)peer->params.send_audio_channels != follower->sink.info.channels) {
follower->sink.info.channels = peer->params.send_audio_channels;
for (i = 0; i < follower->sink.info.channels; i++)
follower->sink.info.position[i] = SPA_AUDIO_CHANNEL_AUX0 + i;
}
if (follower->source.n_ports > MAX_PORTS || follower->sink.n_ports > MAX_PORTS) {
pw_log_error("too many ports source:%d sink:%d max:%d", follower->source.n_ports,
follower->sink.n_ports, MAX_PORTS);
res = -EINVAL;
goto cleanup;
}
media = follower->sink.info.channels > 0 ? "Audio" : "Midi";
if (pw_properties_get_bool(follower->sink.props, "netjack2.connect", DEFAULT_CONNECT)) {
if (pw_properties_get(follower->sink.props, PW_KEY_NODE_AUTOCONNECT) == NULL)

View file

@ -9,6 +9,8 @@
#endif
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define MAX_MIDI 128u
#define MAX_PORTS (MAX_CHANNELS > MAX_MIDI ? MAX_CHANNELS : MAX_MIDI)
struct volume {
bool mute;