|
From: Steve S. <ste...@gm...> - 2011-02-03 01:55:37
|
Hello,
First of all, thanks for all who've worked on valgrind, it's a very useful
tool!
I frequently get an error message that I don't understand:
==28571== Thread 2:
==28571== Syscall param msgsnd(msgp->mtext) points to uninitialised byte(s)
==28571== at 0x437F66F: msgsnd (msgsnd.c:43)
==28571== by 0x804D166: send_final_message (processor.c:5043)
My message structure is something like this:
typedef _f_msg {
long mtype;
unsigned int quit_type;
char *quit_msg;
int prolong;
unsigned long prolong_count;
unsigned short prolong_type;
} f_msg;
In my function, I definitely initialize every value in the structure (both
by clearing with memset and also individually), but I still get this
message. Is it because I'm using individual types instead of a mtext
structure or array? Sorry if this is a newbie question.
Thanks for reading.
SS
|
|
From: Tom H. <to...@co...> - 2011-02-03 09:14:10
|
On 03/02/11 08:47, Baurzhan Ismagulov wrote:
> On Wed, Feb 02, 2011 at 05:55:30PM -0800, Steve Singh wrote:
>> ==28571== Syscall param msgsnd(msgp->mtext) points to uninitialised byte(s)
> ...
>> typedef _f_msg {
>> long mtype;
>> unsigned int quit_type;
>> char *quit_msg;
>> int prolong;
>> unsigned long prolong_count;
>> unsigned short prolong_type;
>> } f_msg;
>>
>> In my function, I definitely initialize every value in the structure (both
>> by clearing with memset and also individually), but I still get this
>> message.
>
> Assuming that msgp is f_msg *, I fail to see mtext in f_msg. Is it the
> right struct?
No, he is passing that struct as mtext.
The problem is that the struct has padding, which he won't be initialising.
That's not generally a major problem, so long as the machine receiving
the message is expecting padding in the same place, but as valgrind
knows nothing about his application's message structure it can't tell
that the uninitialised bytes are just structure padding.
It may also be a security issue because you don't know what information
may be in those padding bytes which are then transferred from the
message sender to the message receiver.
Tom
--
Tom Hughes (to...@co...)
http://compton.nu/
|
|
From: Tom H. <to...@co...> - 2011-02-03 10:41:01
|
On 03/02/11 10:13, Baurzhan Ismagulov wrote: > On Thu, Feb 03, 2011 at 09:13:56AM +0000, Tom Hughes wrote: >>>> In my function, I definitely initialize every value in the structure (both >>>> by clearing with memset and also individually), but I still get this >>>> message. >>> >>> Assuming that msgp is f_msg *, I fail to see mtext in f_msg. Is it the >>> right struct? >> >> No, he is passing that struct as mtext. >> >> The problem is that the struct has padding, which he won't be initialising. > > I assume he memsets the whole struct, so padding should also be initialized? Why would you presume that? I would say that it's pretty clear that he isn't, or he wouldn't get the warning from valgrind! Tom -- Tom Hughes (to...@co...) http://compton.nu/ |
|
From: Julian S. <js...@ac...> - 2011-02-03 14:43:59
|
On Thursday, February 03, 2011, Tom Hughes wrote: > On 03/02/11 10:13, Baurzhan Ismagulov wrote: > > On Thu, Feb 03, 2011 at 09:13:56AM +0000, Tom Hughes wrote: > >>>> In my function, I definitely initialize every value in the structure > >>>> (both by clearing with memset and also individually), but I still get > >>>> this message. > >>> > >>> Assuming that msgp is f_msg *, I fail to see mtext in f_msg. Is it the > >>> right struct? > >> > >> No, he is passing that struct as mtext. > >> > >> The problem is that the struct has padding, which he won't be > >> initialising. > > > > I assume he memsets the whole struct, so padding should also be > > initialized? > > Why would you presume that? I would say that it's pretty clear that he > isn't, or he wouldn't get the warning from valgrind! Well, he did say that in the original msg, although it's ambiguous. If the whole struct is memset-0'd then the padding should all be initialised. memset-0-ing the fields individually obviously won't help. Steve, try (1) memset-0-ing the entire structure, and (2) using --track-origins=yes. J |
|
From: Steve S. <ste...@gm...> - 2011-02-04 17:27:15
|
On Thu, Feb 3, 2011 at 6:43 AM, Julian Seward <js...@ac...> wrote: > > >> No, he is passing that struct as mtext. > > >> > > >> The problem is that the struct has padding, which he won't be > > >> initialising. > > > > > > I assume he memsets the whole struct, so padding should also be > > > initialized? > > > > Why would you presume that? I would say that it's pretty clear that he > > isn't, or he wouldn't get the warning from valgrind! > > Well, he did say that in the original msg, although it's ambiguous. > If the whole struct is memset-0'd then the padding should all be > initialised. memset-0-ing the fields individually obviously won't > help. > > Steve, try (1) memset-0-ing the entire structure, and (2) using > --track-origins=yes Thanks for the replies everyone! To answer the earlier questions, yes I am passing the struct as mtext and yes I am memset-ing to 0 the entire structure so any padding should be automatically zero'd out. Here's a code fragment: memset (&my_message, 0x00, sizeof (f_msg)); my_message.mtype = 1; my_message.quit_type = quitID; my_message.quit_msg = NULL; my_message.prolong = 7; my_message.prolong_count = get_p_ct (local_prolong); my_message.prolong_type = get_p_type (local_prolong); Running with track-origins=yes results in a line number that points to the static declaration of my_message at the beginning of the function. ==2662== Uninitialised value was created by a stack allocation Now for the interesting part! It looks like the problem is restricted to the older version of my cross compiler. When I switch to a newer version, I don't see the same warning from valgrind. Thanks again for all your help! |
|
From: Baurzhan I. <ib...@ra...> - 2011-02-03 09:06:38
|
On Wed, Feb 02, 2011 at 05:55:30PM -0800, Steve Singh wrote:
> ==28571== Syscall param msgsnd(msgp->mtext) points to uninitialised byte(s)
...
> typedef _f_msg {
> long mtype;
> unsigned int quit_type;
> char *quit_msg;
> int prolong;
> unsigned long prolong_count;
> unsigned short prolong_type;
> } f_msg;
>
> In my function, I definitely initialize every value in the structure (both
> by clearing with memset and also individually), but I still get this
> message.
Assuming that msgp is f_msg *, I fail to see mtext in f_msg. Is it the
right struct?
With kind regards,
--
Baurzhan Ismagulov
http://www.kz-easy.com/
|
|
From: Baurzhan I. <ib...@ra...> - 2011-02-03 10:13:44
|
On Thu, Feb 03, 2011 at 09:13:56AM +0000, Tom Hughes wrote: > >> In my function, I definitely initialize every value in the structure (both > >> by clearing with memset and also individually), but I still get this > >> message. > > > > Assuming that msgp is f_msg *, I fail to see mtext in f_msg. Is it the > > right struct? > > No, he is passing that struct as mtext. > > The problem is that the struct has padding, which he won't be initialising. I assume he memsets the whole struct, so padding should also be initialized? With kind regards, -- Baurzhan Ismagulov http://www.kz-easy.com/ |