mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-02 06:46:36 -04:00
security: fix JSON injection in pulse module arguments
Use spa_json_encode_string to escape user-supplied strings before inserting them into JSON configs in module-always-sink, module-x11-bell, and module-switch-on-connect. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
7c2d8f7251
commit
344c9265a6
3 changed files with 33 additions and 15 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
|
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
|
||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <spa/utils/json.h>
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
#include "../module.h"
|
#include "../module.h"
|
||||||
|
|
@ -50,14 +51,17 @@ static int module_always_sink_load(struct module *module)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *args;
|
char *args;
|
||||||
const char *str;
|
const char *str;
|
||||||
|
char encoded[1024];
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
if ((f = open_memstream(&args, &size)) == NULL)
|
if ((f = open_memstream(&args, &size)) == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
fprintf(f, "{");
|
fprintf(f, "{");
|
||||||
if ((str = pw_properties_get(module->props, "sink_name")) != NULL)
|
if ((str = pw_properties_get(module->props, "sink_name")) != NULL) {
|
||||||
fprintf(f, " sink.name = \"%s\"", str);
|
spa_json_encode_string(encoded, sizeof(encoded), str);
|
||||||
|
fprintf(f, " sink.name = %s", encoded);
|
||||||
|
}
|
||||||
fprintf(f, " }");
|
fprintf(f, " }");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,11 +135,15 @@ static void manager_added(void *data, struct pw_manager_object *o)
|
||||||
/* Switch default */
|
/* Switch default */
|
||||||
pw_log_debug("switching to %s", name);
|
pw_log_debug("switching to %s", name);
|
||||||
|
|
||||||
pw_manager_set_metadata(d->manager, d->metadata_default,
|
{
|
||||||
PW_ID_CORE,
|
char encoded[1024];
|
||||||
pw_manager_object_is_sink(o) ? METADATA_CONFIG_DEFAULT_SINK
|
spa_json_encode_string(encoded, sizeof(encoded), name);
|
||||||
: METADATA_CONFIG_DEFAULT_SOURCE,
|
pw_manager_set_metadata(d->manager, d->metadata_default,
|
||||||
"Spa:String:JSON", "{ \"name\"\"%s\" }", name);
|
PW_ID_CORE,
|
||||||
|
pw_manager_object_is_sink(o) ? METADATA_CONFIG_DEFAULT_SINK
|
||||||
|
: METADATA_CONFIG_DEFAULT_SOURCE,
|
||||||
|
"Spa:String:JSON", "{ \"name\" %s }", encoded);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void manager_sync(void *data)
|
static void manager_sync(void *data)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
|
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
|
||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <spa/utils/json.h>
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
#include "../module.h"
|
#include "../module.h"
|
||||||
|
|
@ -58,20 +59,29 @@ static int module_x11_bell_load(struct module *module)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *args;
|
char *args;
|
||||||
const char *str;
|
const char *str;
|
||||||
|
char encoded[1024];
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
if ((f = open_memstream(&args, &size)) == NULL)
|
if ((f = open_memstream(&args, &size)) == NULL)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
fprintf(f, "{");
|
fprintf(f, "{");
|
||||||
if ((str = pw_properties_get(module->props, "sink")) != NULL)
|
if ((str = pw_properties_get(module->props, "sink")) != NULL) {
|
||||||
fprintf(f, " sink.name = \"%s\"", str);
|
spa_json_encode_string(encoded, sizeof(encoded), str);
|
||||||
if ((str = pw_properties_get(module->props, "sample")) != NULL)
|
fprintf(f, " sink.name = %s", encoded);
|
||||||
fprintf(f, " sample.name = \"%s\"", str);
|
}
|
||||||
if ((str = pw_properties_get(module->props, "display")) != NULL)
|
if ((str = pw_properties_get(module->props, "sample")) != NULL) {
|
||||||
fprintf(f, " x11.display = \"%s\"", str);
|
spa_json_encode_string(encoded, sizeof(encoded), str);
|
||||||
if ((str = pw_properties_get(module->props, "xauthority")) != NULL)
|
fprintf(f, " sample.name = %s", encoded);
|
||||||
fprintf(f, " x11.xauthority = \"%s\"", str);
|
}
|
||||||
|
if ((str = pw_properties_get(module->props, "display")) != NULL) {
|
||||||
|
spa_json_encode_string(encoded, sizeof(encoded), str);
|
||||||
|
fprintf(f, " x11.display = %s", encoded);
|
||||||
|
}
|
||||||
|
if ((str = pw_properties_get(module->props, "xauthority")) != NULL) {
|
||||||
|
spa_json_encode_string(encoded, sizeof(encoded), str);
|
||||||
|
fprintf(f, " x11.xauthority = %s", encoded);
|
||||||
|
}
|
||||||
fprintf(f, " }");
|
fprintf(f, " }");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue