aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbusbind.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c69
1 files changed, 49 insertions, 20 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 4828f4e968d..2a38d15873c 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -259,6 +259,18 @@ xd_symbol_to_dbus_type (Lisp_Object object)
259 } \ 259 } \
260 while (0) 260 while (0)
261 261
262/* Append to SIGNATURE a copy of X, making sure SIGNATURE does
263 not become too long. */
264static void
265xd_signature_cat (char *signature, char const *x)
266{
267 ptrdiff_t siglen = strlen (signature);
268 ptrdiff_t xlen = strlen (x);
269 if (DBUS_MAXIMUM_SIGNATURE_LENGTH - xlen <= siglen)
270 string_overflow ();
271 strcat (signature, x);
272}
273
262/* Compute SIGNATURE of OBJECT. It must have a form that it can be 274/* Compute SIGNATURE of OBJECT. It must have a form that it can be
263 used in dbus_message_iter_open_container. DTYPE is the DBusType 275 used in dbus_message_iter_open_container. DTYPE is the DBusType
264 the object is related to. It is passed as argument, because it 276 the object is related to. It is passed as argument, because it
@@ -271,6 +283,8 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
271{ 283{
272 unsigned int subtype; 284 unsigned int subtype;
273 Lisp_Object elt; 285 Lisp_Object elt;
286 char const *subsig;
287 int subsiglen;
274 char x[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 288 char x[DBUS_MAXIMUM_SIGNATURE_LENGTH];
275 289
276 elt = object; 290 elt = object;
@@ -328,12 +342,13 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
328 if (NILP (elt)) 342 if (NILP (elt))
329 { 343 {
330 subtype = DBUS_TYPE_STRING; 344 subtype = DBUS_TYPE_STRING;
331 strcpy (x, DBUS_TYPE_STRING_AS_STRING); 345 subsig = DBUS_TYPE_STRING_AS_STRING;
332 } 346 }
333 else 347 else
334 { 348 {
335 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 349 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
336 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 350 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
351 subsig = x;
337 } 352 }
338 353
339 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the 354 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the
@@ -342,7 +357,7 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
342 if ((subtype == DBUS_TYPE_SIGNATURE) 357 if ((subtype == DBUS_TYPE_SIGNATURE)
343 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt))) 358 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt)))
344 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt)))) 359 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt))))
345 strcpy (x, SSDATA (CAR_SAFE (XD_NEXT_VALUE (elt)))); 360 subsig = SSDATA (CAR_SAFE (XD_NEXT_VALUE (elt)));
346 361
347 while (!NILP (elt)) 362 while (!NILP (elt))
348 { 363 {
@@ -351,7 +366,10 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
351 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 366 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
352 } 367 }
353 368
354 sprintf (signature, "%c%s", dtype, x); 369 subsiglen = snprintf (signature, DBUS_MAXIMUM_SIGNATURE_LENGTH,
370 "%c%s", dtype, subsig);
371 if (! (0 <= subsiglen && subsiglen < DBUS_MAXIMUM_SIGNATURE_LENGTH))
372 string_overflow ();
355 break; 373 break;
356 374
357 case DBUS_TYPE_VARIANT: 375 case DBUS_TYPE_VARIANT:
@@ -383,10 +401,10 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
383 { 401 {
384 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 402 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
385 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 403 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
386 strcat (signature, x); 404 xd_signature_cat (signature, x);
387 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 405 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
388 } 406 }
389 strcat (signature, DBUS_STRUCT_END_CHAR_AS_STRING); 407 xd_signature_cat (signature, DBUS_STRUCT_END_CHAR_AS_STRING);
390 break; 408 break;
391 409
392 case DBUS_TYPE_DICT_ENTRY: 410 case DBUS_TYPE_DICT_ENTRY:
@@ -407,7 +425,7 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
407 elt = XD_NEXT_VALUE (elt); 425 elt = XD_NEXT_VALUE (elt);
408 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 426 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
409 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 427 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
410 strcat (signature, x); 428 xd_signature_cat (signature, x);
411 429
412 if (!XD_BASIC_DBUS_TYPE (subtype)) 430 if (!XD_BASIC_DBUS_TYPE (subtype))
413 wrong_type_argument (intern ("D-Bus"), CAR_SAFE (XD_NEXT_VALUE (elt))); 431 wrong_type_argument (intern ("D-Bus"), CAR_SAFE (XD_NEXT_VALUE (elt)));
@@ -416,14 +434,14 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
416 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 434 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
417 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 435 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
418 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 436 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
419 strcat (signature, x); 437 xd_signature_cat (signature, x);
420 438
421 if (!NILP (CDR_SAFE (XD_NEXT_VALUE (elt)))) 439 if (!NILP (CDR_SAFE (XD_NEXT_VALUE (elt))))
422 wrong_type_argument (intern ("D-Bus"), 440 wrong_type_argument (intern ("D-Bus"),
423 CAR_SAFE (CDR_SAFE (XD_NEXT_VALUE (elt)))); 441 CAR_SAFE (CDR_SAFE (XD_NEXT_VALUE (elt))));
424 442
425 /* Closing signature. */ 443 /* Closing signature. */
426 strcat (signature, DBUS_DICT_ENTRY_END_CHAR_AS_STRING); 444 xd_signature_cat (signature, DBUS_DICT_ENTRY_END_CHAR_AS_STRING);
427 break; 445 break;
428 446
429 default: 447 default:
@@ -2026,7 +2044,7 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2026 DBusConnection *connection; 2044 DBusConnection *connection;
2027 ptrdiff_t i; 2045 ptrdiff_t i;
2028 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2046 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
2029 char x[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2047 int rulelen;
2030 DBusError derror; 2048 DBusError derror;
2031 2049
2032 /* Check parameters. */ 2050 /* Check parameters. */
@@ -2071,32 +2089,43 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2071 connection = xd_initialize (bus, TRUE); 2089 connection = xd_initialize (bus, TRUE);
2072 2090
2073 /* Create a rule to receive related signals. */ 2091 /* Create a rule to receive related signals. */
2074 sprintf (rule, 2092 rulelen = snprintf (rule, sizeof rule,
2075 "type='signal',interface='%s',member='%s'", 2093 "type='signal',interface='%s',member='%s'",
2076 SDATA (interface), 2094 SDATA (interface),
2077 SDATA (signal)); 2095 SDATA (signal));
2096 if (! (0 <= rulelen && rulelen < sizeof rule))
2097 string_overflow ();
2078 2098
2079 /* Add unique name and path to the rule if they are non-nil. */ 2099 /* Add unique name and path to the rule if they are non-nil. */
2080 if (!NILP (uname)) 2100 if (!NILP (uname))
2081 { 2101 {
2082 sprintf (x, ",sender='%s'", SDATA (uname)); 2102 int len = snprintf (rule + rulelen, sizeof rule - rulelen,
2083 strcat (rule, x); 2103 ",sender='%s'", SDATA (uname));
2104 if (! (0 <= len && len < sizeof rule - rulelen))
2105 string_overflow ();
2106 rulelen += len;
2084 } 2107 }
2085 2108
2086 if (!NILP (path)) 2109 if (!NILP (path))
2087 { 2110 {
2088 sprintf (x, ",path='%s'", SDATA (path)); 2111 int len = snprintf (rule + rulelen, sizeof rule - rulelen,
2089 strcat (rule, x); 2112 ",path='%s'", SDATA (path));
2113 if (! (0 <= len && len < sizeof rule - rulelen))
2114 string_overflow ();
2115 rulelen += len;
2090 } 2116 }
2091 2117
2092 /* Add arguments to the rule if they are non-nil. */ 2118 /* Add arguments to the rule if they are non-nil. */
2093 for (i = 6; i < nargs; ++i) 2119 for (i = 6; i < nargs; ++i)
2094 if (!NILP (args[i])) 2120 if (!NILP (args[i]))
2095 { 2121 {
2122 int len;
2096 CHECK_STRING (args[i]); 2123 CHECK_STRING (args[i]);
2097 sprintf (x, ",arg%"pD"d='%s'", i - 6, 2124 len = snprintf (rule + rulelen, sizeof rule - rulelen,
2098 SDATA (args[i])); 2125 ",arg%"pD"d='%s'", i - 6, SDATA (args[i]));
2099 strcat (rule, x); 2126 if (! (0 <= len && len < sizeof rule - rulelen))
2127 string_overflow ();
2128 rulelen += len;
2100 } 2129 }
2101 2130
2102 /* Add the rule to the bus. */ 2131 /* Add the rule to the bus. */