mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
pw-reserve: require valid name + check rd_reserve_new errors
Empty name in rd_device_new triggers assert inside DBus, so bail out before that.
This commit is contained in:
parent
422c270a74
commit
b12119da28
3 changed files with 44 additions and 2 deletions
|
|
@ -142,8 +142,8 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (opt_name == NULL) {
|
if (opt_name == NULL || !rd_device_valid_device_name(opt_name)) {
|
||||||
fprintf(stderr, "name must be given\n");
|
fprintf(stderr, "valid name must be given\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,6 +190,11 @@ int main(int argc, char *argv[])
|
||||||
opt_appname,
|
opt_appname,
|
||||||
opt_priority,
|
opt_priority,
|
||||||
&reserve_callbacks, &impl);
|
&reserve_callbacks, &impl);
|
||||||
|
if (!impl.device) {
|
||||||
|
res = -errno;
|
||||||
|
fprintf(stderr, "dbus connection failed: %m\n");
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (!opt_monitor) {
|
if (!opt_monitor) {
|
||||||
res = rd_device_acquire(impl.device);
|
res = rd_device_acquire(impl.device);
|
||||||
|
|
|
||||||
|
|
@ -307,6 +307,34 @@ invalid:
|
||||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool rd_device_valid_device_name(const char *name)
|
||||||
|
{
|
||||||
|
const char *p = name;
|
||||||
|
|
||||||
|
if (!p || !*p)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* cf. dbus-marshal-validate.c:_dbus_validate_bus_name_full */
|
||||||
|
while (*p) {
|
||||||
|
switch (*p) {
|
||||||
|
case 'A' ... 'Z':
|
||||||
|
case 'a' ... 'z':
|
||||||
|
case '-':
|
||||||
|
case '_':
|
||||||
|
break;
|
||||||
|
case '0' ... '9':
|
||||||
|
if (p == name)
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
struct rd_device *
|
struct rd_device *
|
||||||
rd_device_new(DBusConnection *connection, const char *device_name, const char *application_name,
|
rd_device_new(DBusConnection *connection, const char *device_name, const char *application_name,
|
||||||
int32_t priority, const struct rd_device_callbacks *callbacks, void *data)
|
int32_t priority, const struct rd_device_callbacks *callbacks, void *data)
|
||||||
|
|
@ -314,6 +342,11 @@ rd_device_new(DBusConnection *connection, const char *device_name, const char *a
|
||||||
struct rd_device *d;
|
struct rd_device *d;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
if (!rd_device_valid_device_name(device_name)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
d = calloc(1, sizeof(struct rd_device));
|
d = calloc(1, sizeof(struct rd_device));
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -51,6 +52,9 @@ void rd_device_release(struct rd_device *d);
|
||||||
/** destroy a device */
|
/** destroy a device */
|
||||||
void rd_device_destroy(struct rd_device *d);
|
void rd_device_destroy(struct rd_device *d);
|
||||||
|
|
||||||
|
/** check if device name is a valid name */
|
||||||
|
bool rd_device_valid_device_name(const char *name);
|
||||||
|
|
||||||
/* Set the application device name for an rd_device object. Returns 0
|
/* Set the application device name for an rd_device object. Returns 0
|
||||||
* on success, a negative errno style return value on error. */
|
* on success, a negative errno style return value on error. */
|
||||||
int rd_device_set_application_device_name(struct rd_device *d, const char *name);
|
int rd_device_set_application_device_name(struct rd_device *d, const char *name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue