Bug 114996 - using bad data as a pointer
Summary: using bad data as a pointer
Alias: None
Product: Fedora
Classification: Fedora
Component: libwvstreams   
(Show other bugs)
Version: 1
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Harald Hoyer
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2004-02-05 10:03 UTC by d.binderman
Modified: 2007-11-30 22:10 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-07-30 12:54:34 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description d.binderman 2004-02-05 10:03:27 UTC
Description of problem:

I just tried to compile package libwvstreams-3.70-12 from Redhat
Fedora Core 1.

The compiler said


wvstring.cc(88): warning #592: variable "buf" is used before its value
is set

The source code is

    WvStringBuf *buf = (WvStringBuf *)malloc(WVSTRINGBUF_SIZE(buf)
                                             + size + WVSTRING_EXTRA);

buf is clearly used before it's value has been assigned.
I think we've been here before on this one.

Further investigation of macro WVSTRINGBUF_SIZE suggests

#define WVSTRINGBUF_SIZE(s) (s->data - (char *)s)

Accessing uninitialised data is guaranteed trouble.
Using uninitialised data as a valid pointer value is guaranteed 
There could be a core dump if buf has a bad value.

Suggest init buf before first use.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Actual results:

Expected results:

Additional info:

Comment 1 Bart Martens 2004-02-11 02:25:27 UTC
The expression (s->data - (char *)s) will always give the same result,
with any value of s, and regardless the memory s is pointing to. The
memory where s is pointing to, is not accessed during the evaluation
of the expression. We can modify the code to avoid the compiler
warning, or close this bug as not-a-bug.

Comment 2 d.binderman 2004-02-11 09:57:08 UTC
>will always give the same result, with any value of s, 
>and regardless the memory s is pointing to.

I think we are going round in circles on this one.

I'll try to be more explicit.

Where s contains rubbish, it could point anywhere, resulting
in a segmentation violation, have a
not legal pointer value (on some machines pointers have to be a 
multiple of four).

>The memory where s is pointing to, is not accessed during the 
>evaluation of the expression.

>(s->data - (char *)s)

The evaluation of s->data requies s to be read. In doing so,
a segmentation violation could occur.

Comment 3 Harald Hoyer 2004-07-28 13:33:10 UTC
what about
#define WVSTRINGBUF_SIZE(s) (offsetof(struct WvStringBuf, data))

Note You need to log in before you can comment on or make changes to this bug.