Message ID | 5E7CF115-219A-4260-BE53-19B5A8D1D7F3@bell.net |
---|---|
State | New |
Headers | show |
On 06/15/2016 01:42 PM, John David Anglin wrote: > The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that > byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. > -} HEADER; > +} __attribute__ ((packed)) HEADER; Unfortunately, we cannot apply this simple fix because this is a public header, and the above changes alignment of the struct. It would also have to be __attribute__ ((__packed__)). Florian
Florian Weimer <fweimer@redhat.com> writes: > On 06/15/2016 01:42 PM, John David Anglin wrote: >> The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that >> byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. > >> -} HEADER; >> +} __attribute__ ((packed)) HEADER; > > Unfortunately, we cannot apply this simple fix because this is a public > header, and the above changes alignment of the struct. It would also have > to be __attribute__ ((__packed__)). It also needs to work with other compilers. Andreas.
On 2016-06-15 8:16 AM, Andreas Schwab wrote: > Florian Weimer<fweimer@redhat.com> writes: > >> >On 06/15/2016 01:42 PM, John David Anglin wrote: >>> >>The attached patch fixes BZ 20243. The HEADER struct needs to be packed so that >>> >>byte accesses are used. Tested using glibc 2.22-11on hppa. Please install if okay. >> > >>> >>-} HEADER; >>> >>+} __attribute__ ((packed)) HEADER; >> > >> >Unfortunately, we cannot apply this simple fix because this is a public >> >header, and the above changes alignment of the struct. It would also have >> >to be __attribute__ ((__packed__)). > It also needs to work with other compilers. The packed attribute is used in several places in glibc. Maybe a packed derivative of HEADER can be used in res_query.c to avoid the above issue? I don't think the packed derivative affects the layout of HEADER given the way the fields are arranged. Dave
On 06/15/2016 04:40 PM, John David Anglin wrote: > On 2016-06-15 8:16 AM, Andreas Schwab wrote: >> Florian Weimer<fweimer@redhat.com> writes: >> >>> >On 06/15/2016 01:42 PM, John David Anglin wrote: >>>> >>The attached patch fixes BZ 20243. The HEADER struct needs to be >>>> packed so that >>>> >>byte accesses are used. Tested using glibc 2.22-11on hppa. >>>> Please install if okay. >>> > >>>> >>-} HEADER; >>>> >>+} __attribute__ ((packed)) HEADER; > I don't think the packed derivative affects the layout of HEADER given > the way the fields are > arranged. I verified that it changes alignment, even on x86_64. That's the intent, and it results in a layout change (if this struct is used as a part of other structs, for example). Florian
On 2016-06-15 10:43 AM, Florian Weimer wrote: >> I don't think the packed derivative affects the layout of HEADER given >> the way the fields are >> arranged. > > I verified that it changes alignment, even on x86_64. That's the > intent, and it results in a layout change (if this struct is used as a > part of other structs, for example). I'm suggesting this be done in res_query.c where we we need byte alignment. Nothing else would have access to this typedef, so it couldn't affect the layout of any other structs. Dave
diff --git a/resolv/arpa/nameser_compat.h b/resolv/arpa/nameser_compat.h index d59c9e4..6c0f69c 100644 --- a/resolv/arpa/nameser_compat.h +++ b/resolv/arpa/nameser_compat.h @@ -80,7 +80,7 @@ typedef struct { unsigned ancount :16; /*%< number of answer entries */ unsigned nscount :16; /*%< number of authority entries */ unsigned arcount :16; /*%< number of resource entries */ -} HEADER; +} __attribute__ ((packed)) HEADER; #define PACKETSZ NS_PACKETSZ #define MAXDNAME NS_MAXDNAME