Closed
Bug 324525
Opened 20 years ago
Closed 20 years ago
Memory error in ber_get_stringal/ber_bvfree
Categories
(Directory Graveyard :: LDAP C SDK, defect)
Directory Graveyard
LDAP C SDK
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: richm, Assigned: mcs)
Details
Attachments
(2 files, 2 obsolete files)
If the malloc is done to allocate the *bv, but then an lber error is encountered while doing the ber_skip_tag (due to a bad or malicious client), the bv->bv_val is set to a random value. If you then try to use ber_bvfree to free the bv, it may call free on this uninitialized value, and badness ensues. I think the proper fix is for ber_get_stringal to set (*bv)->bv_val to NULL and (*bv)->bv_len to 0 just after the malloc.
| Assignee | ||
Comment 1•20 years ago
|
||
I agree this is a bug and that your proposed fix sounds OK. Another approach would be to use calloc() instead or free the berval before returning an error. Which do you think is best?
| Reporter | ||
Comment 2•20 years ago
|
||
I figured you used malloc instead of calloc for performance reasons. Malloc + NULL assignment should be faster than calloc and it's just as safe in this case.
| Reporter | ||
Comment 3•20 years ago
|
||
| Reporter | ||
Comment 4•20 years ago
|
||
These are also the diffs for bug 324529
| Reporter | ||
Comment 5•20 years ago
|
||
Incorporates comments from Mark.
Attachment #209858 -
Attachment is obsolete: true
| Reporter | ||
Comment 6•20 years ago
|
||
I needed to use ber_svecfree to free the char** and ber_bvecfree to free the
berval**, not NSLBERI_FREE. The arrays may have individual elements that have
been allocated, and those must be freed as well. See later in the code, the
switch statement that tries to clean up upon error.
Attachment #210149 -
Attachment is obsolete: true
| Assignee | ||
Comment 7•20 years ago
|
||
Comment on attachment 210533 [details]
diffs for fix
The patch looks good. Thanks.
Attachment #210533 -
Flags: review+
| Reporter | ||
Comment 8•20 years ago
|
||
Checking in decode.c;
/cvsroot/mozilla/directory/c-sdk/ldap/libraries/liblber/decode.c,v <-- decode.c
new revision: 5.3; previous revision: 5.2
done
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•