Closed Bug 14286 Opened 25 years ago Closed 25 years ago

PL_HashString() with CRASH if key is NULL

Categories

(NSPR :: NSPR, defect, P3)

x86
All
defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: sspitzer, Assigned: srinivas)

Details

(Keywords: crash)

PL_HashString(const void *key) will crash if it is passed NULL.

see bug #14285 to see when this happens.
Status: NEW → ASSIGNED
What exactly is the bug?
the bug is you need to add a null check to PL_HashString()
so it won't crash if someone passes it a null.
In mozilla/nsprpub/lib/ds/plhash.h, we have:
    typedef PRUint32 PLHashNumber;

    PR_EXTERN(PLHashNumber)
    PL_HashString(const void *key);

Since PLHashNumber is unsigned, it isn't clear
what PL_HashString should return if someone
passes it a null.  A null is an invalid argument.
The unsigned return type of PLHashNumber makes
it impossible to return a failure status.

This is similar to the string functions in <string.h>.
It is not specified what these functions should return
when they are passed (invalid) null arguments.
That is exactly the point; it is not possible to return a BAD_ARGUMENT error.
If anything, an assert statement should be added to check for null pointers.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
Marking the bug invalid.
Adding crash keyword
Keywords: crash
You need to log in before you can comment on or make changes to this bug.