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)

defect
Not set
major

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.
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?
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.
Attached file decode.c —
Attached file diffs for fix (obsolete) —
These are also the diffs for bug 324529
Attached file diffs for fix (obsolete) —
Incorporates comments from Mark.
Attachment #209858 - Attachment is obsolete: true
Attached file diffs for fix —
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
Comment on attachment 210533 [details] diffs for fix The patch looks good. Thanks.
Attachment #210533 - Flags: review+
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.

Attachment

General

Creator:
Created:
Updated:
Size: