mirror of
https://github.com/swaywm/sway.git
synced 2026-03-30 11:10:59 -04:00
Plug memory dbus_message_iter_get_signature leak
This commit is contained in:
parent
5c8dc9cb73
commit
b9f36716b5
4 changed files with 20 additions and 14 deletions
|
|
@ -5,6 +5,12 @@
|
|||
#include <dbus/dbus.h>
|
||||
extern DBusConnection *conn;
|
||||
|
||||
/**
|
||||
* Checks the signature of the given iter against `sig`. Prefer to
|
||||
* `dbus_message_iter_get_signature` as this one frees the intermediate string.
|
||||
*/
|
||||
bool dbus_message_iter_check_signature(DBusMessageIter *iter, const char *sig);
|
||||
|
||||
/**
|
||||
* Should be called in main loop to dispatch events
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#define _XOPEN_SOURCE 700
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
|
@ -137,6 +138,13 @@ static void dispatch_status(DBusConnection *connection, DBusDispatchStatus new_s
|
|||
|
||||
/* Public functions below */
|
||||
|
||||
bool dbus_message_iter_check_signature(DBusMessageIter *iter, const char *sig) {
|
||||
char *msg_sig = dbus_message_iter_get_signature(iter);
|
||||
int result = strcmp(msg_sig, sig);
|
||||
dbus_free(msg_sig);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
void dispatch_dbus() {
|
||||
if (!should_dispatch || !conn) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -71,17 +71,13 @@ static void reply_icon(DBusPendingCall *pending, void *_data) {
|
|||
|
||||
// Each if here checks the types above before recursing
|
||||
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
|
||||
sway_log(L_ERROR, "Relpy type incorrect");
|
||||
sway_log(L_ERROR, "Should be \"v\", is \"%s\"",
|
||||
dbus_message_iter_get_signature(&iter));
|
||||
sway_log(L_ERROR, "Icon relpy type incorrect");
|
||||
goto bail;
|
||||
}
|
||||
dbus_message_iter_recurse(&iter, &variant);
|
||||
|
||||
if (strcmp("a(iiay)", dbus_message_iter_get_signature(&variant)) != 0) {
|
||||
sway_log(L_ERROR, "Relpy type incorrect");
|
||||
sway_log(L_ERROR, "Should be \"a(iiay)\", is \"%s\"",
|
||||
dbus_message_iter_get_signature(&variant));
|
||||
if (dbus_message_iter_check_signature(&variant, "a(iiay)")) {
|
||||
sway_log(L_ERROR, "Icon relpy type incorrect");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
|
|
@ -237,18 +233,14 @@ static void reply_icon_name(DBusPendingCall *pending, void *_data) {
|
|||
|
||||
dbus_message_iter_init(reply, &iter);
|
||||
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
|
||||
sway_log(L_ERROR, "Relpy type incorrect");
|
||||
sway_log(L_ERROR, "Should be \"v\", is \"%s\"",
|
||||
dbus_message_iter_get_signature(&iter));
|
||||
sway_log(L_ERROR, "Icon name relpy type incorrect");
|
||||
goto bail;
|
||||
}
|
||||
dbus_message_iter_recurse(&iter, &variant);
|
||||
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_STRING) {
|
||||
sway_log(L_ERROR, "Relpy type incorrect");
|
||||
sway_log(L_ERROR, "Should be \"s\", is \"%s\"",
|
||||
dbus_message_iter_get_signature(&iter));
|
||||
sway_log(L_ERROR, "Icon name relpy type incorrect");
|
||||
goto bail;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ static void get_obj_items_reply(DBusPendingCall *pending, void *_data) {
|
|||
goto bail;
|
||||
}
|
||||
dbus_message_iter_recurse(&iter, &variant);
|
||||
if (strcmp(dbus_message_iter_get_signature(&variant), "a(os)") != 0) {
|
||||
if (dbus_message_iter_check_signature(&iter, "a(os)")) {
|
||||
sway_log(L_ERROR, "Replyed with wrong type not a(os)");
|
||||
goto bail;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue