This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug ports/5070] glibc-2.5: ../sysdeps/unix/sysv/linux/check_pf.c:68: make_request: Assertion fails


------- Additional Comments From ikalvachev at gmail dot com  2007-10-05 23:42 -------
If I understand correctly, the bug is that the arm aligns to 8 bytes, not 4.
This causes bigger align, that is not properly cleared but still would be send
over the network.

Instead of arguing how to clear the padding set by the compiler, I think it
would be much better to not send it at all. There is simple portable way to get
the size of the whole structure without padding and it is already used in the
assert().

Using offsetof(struct req,pad) instead of sizeof(req) would always give us the
correct size of the structure without the padding. It would still require at
least one byte padding (that we can ignore).


This solution is not only more portable, it is also faster.
And this is what I care about 
(I've never touched arm so far).


Here is sample patch against glibc 2.6.1, it applies without problems to current
cvs HEAD r1.12.

---------
--- check_pf.c.old      2007-04-25 19:05:18.000000000 +0300
+++ check_pf.c  2007-10-06 00:54:45.000000000 +0300
@@ -53,21 +53,18 @@ make_request (int fd, pid_t pid, bool *s
     struct rtgenmsg g;
     /* struct rtgenmsg consists of a single byte.  This means there
        are three bytes of padding included in the REQ definition.
-       We make them explicit here.  */
-    char pad[3];
+       We use pad as a mark for the size of the data we need.  */
+    char pad;
   } req;
   struct sockaddr_nl nladdr;
 
-  req.nlh.nlmsg_len = sizeof (req);
+  req.nlh.nlmsg_len = offsetof (struct req, pad);
   req.nlh.nlmsg_type = RTM_GETADDR;
   req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
   req.nlh.nlmsg_pid = 0;
   req.nlh.nlmsg_seq = time (NULL);
   req.g.rtgen_family = AF_UNSPEC;
 
-  assert (sizeof (req) - offsetof (struct req, pad) == 3);
-  memset (req.pad, '\0', sizeof (req.pad));
-
   memset (&nladdr, '\0', sizeof (nladdr));
   nladdr.nl_family = AF_NETLINK;
 
@@ -94,7 +91,7 @@ make_request (int fd, pid_t pid, bool *s
 
   struct iovec iov = { buf, buf_size };
 
-  if (TEMP_FAILURE_RETRY (__sendto (fd, (void *) &req, sizeof (req), 0,
+  if (TEMP_FAILURE_RETRY (__sendto (fd, (void *) &req, offsetof (struct req,
pad), 0,
                                    (struct sockaddr *) &nladdr,
                                    sizeof (nladdr))) < 0)
     goto out_fail;
---------

Thank you for your patience.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


http://sourceware.org/bugzilla/show_bug.cgi?id=5070

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]