Bug 114996 - using bad data as a pointer
using bad data as a pointer
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: libwvstreams (Show other bugs)
1
All Linux
medium Severity medium
: ---
: ---
Assigned To: Harald Hoyer
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-02-05 05:03 EST by d.binderman
Modified: 2007-11-30 17:10 EST (History)
1 user (show)

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


Attachments (Terms of Use)

  None (edit)
Description d.binderman 2004-02-05 05:03:27 EST
Description of problem:

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

The compiler said

1.

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 
trouble. 
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:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:
Comment 1 Bart Martens 2004-02-10 21:25:27 EST
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 04:57:08 EST
>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 09:33:10 EDT
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.