aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbusbind.c
diff options
context:
space:
mode:
authorPaul Eggert2011-08-29 08:49:19 -0700
committerPaul Eggert2011-08-29 08:49:19 -0700
commit2ea16b8969850fd2952ca80239cf37e77d0e7edd (patch)
treed10d97fd1e6bbcc1fb3334af6da10d30b2ec912b /src/dbusbind.c
parent62f19c197d32e8773a284616d575686d87903b7d (diff)
downloademacs-2ea16b8969850fd2952ca80239cf37e77d0e7edd.tar.gz
emacs-2ea16b8969850fd2952ca80239cf37e77d0e7edd.zip
* dbusbind.c (xd_signature, Fdbus_register_signal):
Do not overrun buffer; instead, report string overflow.
Diffstat (limited to 'src/dbusbind.c')
-rw-r--r--src/dbusbind.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 4828f4e968d..005d521c1db 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -271,6 +271,7 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
271{ 271{
272 unsigned int subtype; 272 unsigned int subtype;
273 Lisp_Object elt; 273 Lisp_Object elt;
274 char const *subsig;
274 char x[DBUS_MAXIMUM_SIGNATURE_LENGTH]; 275 char x[DBUS_MAXIMUM_SIGNATURE_LENGTH];
275 276
276 elt = object; 277 elt = object;
@@ -328,12 +329,13 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
328 if (NILP (elt)) 329 if (NILP (elt))
329 { 330 {
330 subtype = DBUS_TYPE_STRING; 331 subtype = DBUS_TYPE_STRING;
331 strcpy (x, DBUS_TYPE_STRING_AS_STRING); 332 subsig = DBUS_TYPE_STRING_AS_STRING;
332 } 333 }
333 else 334 else
334 { 335 {
335 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt)); 336 subtype = XD_OBJECT_TO_DBUS_TYPE (CAR_SAFE (elt));
336 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt))); 337 xd_signature (x, subtype, dtype, CAR_SAFE (XD_NEXT_VALUE (elt)));
338 subsig = x;
337 } 339 }
338 340
339 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the 341 /* If the element type is DBUS_TYPE_SIGNATURE, and this is the
@@ -342,7 +344,7 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
342 if ((subtype == DBUS_TYPE_SIGNATURE) 344 if ((subtype == DBUS_TYPE_SIGNATURE)
343 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt))) 345 && STRINGP (CAR_SAFE (XD_NEXT_VALUE (elt)))
344 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt)))) 346 && NILP (CDR_SAFE (XD_NEXT_VALUE (elt))))
345 strcpy (x, SSDATA (CAR_SAFE (XD_NEXT_VALUE (elt)))); 347 subsig = SSDATA (CAR_SAFE (XD_NEXT_VALUE (elt)));
346 348
347 while (!NILP (elt)) 349 while (!NILP (elt))
348 { 350 {
@@ -351,7 +353,10 @@ xd_signature (char *signature, unsigned int dtype, unsigned int parent_type, Lis
351 elt = CDR_SAFE (XD_NEXT_VALUE (elt)); 353 elt = CDR_SAFE (XD_NEXT_VALUE (elt));
352 } 354 }
353 355
354 sprintf (signature, "%c%s", dtype, x); 356 if (esnprintf (signature, DBUS_MAXIMUM_SIGNATURE_LENGTH,
357 "%c%s", dtype, subsig)
358 == DBUS_MAXIMUM_SIGNATURE_LENGTH - 1)
359 string_overflow ();
355 break; 360 break;
356 361
357 case DBUS_TYPE_VARIANT: 362 case DBUS_TYPE_VARIANT:
@@ -2026,7 +2031,7 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2026 DBusConnection *connection; 2031 DBusConnection *connection;
2027 ptrdiff_t i; 2032 ptrdiff_t i;
2028 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2033 char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
2029 char x[DBUS_MAXIMUM_MATCH_RULE_LENGTH]; 2034 int rulelen;
2030 DBusError derror; 2035 DBusError derror;
2031 2036
2032 /* Check parameters. */ 2037 /* Check parameters. */
@@ -2071,34 +2076,32 @@ usage: (dbus-register-signal BUS SERVICE PATH INTERFACE SIGNAL HANDLER &rest ARG
2071 connection = xd_initialize (bus, TRUE); 2076 connection = xd_initialize (bus, TRUE);
2072 2077
2073 /* Create a rule to receive related signals. */ 2078 /* Create a rule to receive related signals. */
2074 sprintf (rule, 2079 rulelen = esnprintf (rule, sizeof rule,
2075 "type='signal',interface='%s',member='%s'", 2080 "type='signal',interface='%s',member='%s'",
2076 SDATA (interface), 2081 SDATA (interface),
2077 SDATA (signal)); 2082 SDATA (signal));
2078 2083
2079 /* Add unique name and path to the rule if they are non-nil. */ 2084 /* Add unique name and path to the rule if they are non-nil. */
2080 if (!NILP (uname)) 2085 if (!NILP (uname))
2081 { 2086 rulelen += esnprintf (rule + rulelen, sizeof rule - rulelen,
2082 sprintf (x, ",sender='%s'", SDATA (uname)); 2087 ",sender='%s'", SDATA (uname));
2083 strcat (rule, x);
2084 }
2085 2088
2086 if (!NILP (path)) 2089 if (!NILP (path))
2087 { 2090 rulelen += esnprintf (rule + rulelen, sizeof rule - rulelen,
2088 sprintf (x, ",path='%s'", SDATA (path)); 2091 ",path='%s'", SDATA (path));
2089 strcat (rule, x);
2090 }
2091 2092
2092 /* Add arguments to the rule if they are non-nil. */ 2093 /* Add arguments to the rule if they are non-nil. */
2093 for (i = 6; i < nargs; ++i) 2094 for (i = 6; i < nargs; ++i)
2094 if (!NILP (args[i])) 2095 if (!NILP (args[i]))
2095 { 2096 {
2096 CHECK_STRING (args[i]); 2097 CHECK_STRING (args[i]);
2097 sprintf (x, ",arg%"pD"d='%s'", i - 6, 2098 rulelen += esnprintf (rule + rulelen, sizeof rule - rulelen,
2098 SDATA (args[i])); 2099 ",arg%"pD"d='%s'", i - 6, SDATA (args[i]));
2099 strcat (rule, x);
2100 } 2100 }
2101 2101
2102 if (rulelen == sizeof rule - 1)
2103 string_overflow ();
2104
2102 /* Add the rule to the bus. */ 2105 /* Add the rule to the bus. */
2103 dbus_error_init (&derror); 2106 dbus_error_init (&derror);
2104 dbus_bus_add_match (connection, rule, &derror); 2107 dbus_bus_add_match (connection, rule, &derror);