X Tutup
Skip to content

Commit cfcc005

Browse files
committed
sd-bus: add define for the maximum signature length
Less magic numbers in the code…
1 parent f0ae945 commit cfcc005

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/libsystemd/sd-bus/bus-message.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int message_append_field_signature(
284284
/* dbus1 doesn't allow signatures over 8bit, let's enforce
285285
* this globally, to not risk convertability */
286286
l = strlen(s);
287-
if (l > 255)
287+
if (l > SD_BUS_MAXIMUM_SIGNATURE_LENGTH)
288288
return -EINVAL;
289289

290290
/* Signature "(yv)" where the variant contains "g" */

src/libsystemd/sd-bus/bus-signature.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,5 @@ bool signature_is_valid(const char *s, bool allow_dict_entry) {
144144
p += t;
145145
}
146146

147-
return p - s <= 255;
147+
return p - s <= SD_BUS_MAXIMUM_SIGNATURE_LENGTH;
148148
}

src/systemd/sd-bus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ _SD_BEGIN_DECLARATIONS;
3333
#define SD_BUS_DEFAULT_USER ((sd_bus *) 2)
3434
#define SD_BUS_DEFAULT_SYSTEM ((sd_bus *) 3)
3535

36+
/* https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-signature */
37+
#define SD_BUS_MAXIMUM_SIGNATURE_LENGTH 255
38+
3639
/* Types */
3740

3841
typedef struct sd_bus sd_bus;

0 commit comments

Comments
 (0)
X Tutup