Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 5 Dec 2010 17:12:34 +0000 (UTC)
From: Bhadrinath <>
Subject: Re: Interesting behavior with struct initiailization

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

Powered by blists - more mailing lists

Please check out the Open Source Software Security Wiki, which is counterpart to this mailing list.

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.