[Bridge] [PATCH] rstpd: sizeof mismatch + macro enhancement

Vitaly Demyanec vitas at nppfactor.kiev.ua
Fri May 22 06:20:48 PDT 2009


This patch is against rstpd v.0.21 (get it here: 
https://lists.linux-foundation.org/pipermail/bridge/2009-February/006178.html).

Description:
1. For some setups (e.g. mine) sizeof(struct sockaddr_un) != 
sizeof((sa)->sun_family) + sizeof((sa)->sun_path) , which leads to incomplete 
clean-up in set_socket_address macro, which in turn leads to different socket 
addresses in rstpd and rstpctl.
2. We should avoid possible side-effects multiplication in the (sa) (e.g. when 
this macro is called like this: set_socket_address(++sa_ptr, str[i])) by the 
use of temporary variable inside the macro.

Signed-off-by: Vitaly Demyanec <vitas at nppfactor.kiev.ua>
---

diff -ur a/ctl_socket.h b/ctl_socket.h
--- a/ctl_socket.h      2009-05-22 15:34:00.000000000 +0300
+++ b/ctl_socket.h      2009-05-22 16:17:47.000000000 +0300
@@ -47,10 +47,11 @@

 #define set_socket_address(sa, string) \
  do {\
-  (sa)->sun_family = AF_UNIX; \
-  memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \
-  strcpy((sa)->sun_path + 1, (string)); \
- } while (0)
+  struct sockaddr_un * tmp_sa = (sa); \
+  memset(tmp_sa, 0, sizeof(*tmp_sa)); \
+  tmp_sa->sun_family = AF_UNIX; \
+  strcpy(tmp_sa->sun_path + 1, (string)); \
+} while (0)

 #define RSTP_SERVER_SOCK_NAME ".rstp_server"

-- 
With Best Regards,
Vitaly Demyanec
Head engineer
Factor-SPE
Kiev, Ukraine
tel/fax: +380(44)249-21-63


More information about the Bridge mailing list