oss-sec mailing list archives
Re: Interesting behavior with struct initiailization
From: Bhadrinath <bitstrat () gmail com>
Date: Sun, 5 Dec 2010 17:12:34 +0000 (UTC)
One solution to ensure no padding bits are copied uninitialized,
struct test{ int a; char b; int c;};
unsigned char r[sizeof arg];
struct test arg = { .a = 1, .b = 2, .c = 3 };
.
.
// Do all operations on arg and just before passing it to the function
.
.
memset(r,0,sizeof r); // initialize everything to zero
memcpy(r+offsetof(struct test,a),&arg.a,sizeof arg.a);
memcpy(r+offsetof(struct test,b),&arg.b,sizeof arg.b);
memcpy(r+offsetof(struct test,c),&arg.c,sizeof arg.c);
//now pass r to the function
Copy_to_user(ptr, r, sizeof(r));
Comments and ideas are welcome
With Regards
Bhadrinath
Current thread:
- Re: Interesting behavior with struct initiailization Geoff Keating (Nov 29)
- RE: Interesting behavior with struct initiailization Robert Seacord (Dec 03)
- Re: Interesting behavior with struct initiailization Geoff Keating (Dec 03)
- Re: Interesting behavior with struct initiailization Bhadrinath (Dec 05)
- Re: Interesting behavior with struct initiailization Bhadrinath (Dec 05)
- Re: Re: Interesting behavior with struct initiailization Dan Rosenberg (Dec 05)
- Re: Interesting behavior with struct initiailization Bhadrinath (Dec 05)
- Re: Interesting behavior with struct initiailization Geoff Keating (Dec 03)
- RE: Interesting behavior with struct initiailization Robert Seacord (Dec 03)
