security: add missing NULL check after strdup in MIDI server

Memory Safety: Medium

spa_bt_midi_server_new() did not check the return value of strdup()
when duplicating the characteristic path. On allocation failure, a
NULL chr_path would be returned as part of the server object,
leading to a NULL pointer dereference when later used. Add a NULL
check that jumps to the existing fail cleanup path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Wim Taymans 2026-04-29 11:36:53 +02:00
parent acabcf085d
commit bc93a745ab

View file

@ -526,6 +526,10 @@ struct spa_bt_midi_server *spa_bt_midi_server_new(const struct spa_bt_midi_serve
spa_scnprintf(path, sizeof(path), MIDI_CHR_PATH, impl->server_id); spa_scnprintf(path, sizeof(path), MIDI_CHR_PATH, impl->server_id);
impl->this.chr_path = strdup(path); impl->this.chr_path = strdup(path);
if (impl->this.chr_path == NULL) {
res = -ENOMEM;
goto fail;
}
return &impl->this; return &impl->this;