check ptr against NULL before dereferencing it - #6710
Conversation
| goto test_cleanup; | ||
| } | ||
| if(memcmp(scheme, "HTTP", 5) != 0) { | ||
| if(scheme == NULL || memcmp(scheme, "HTTP", 5) != 0) { |
|
Thanks for super fast approval of both my PRs. I agree the problems "fixed" are benign. I would personally prefer a failed test-case with an error-message instead of a segfault, which is the main effect of this. |
Is it? This uses the internal printf() code, right? It doesn't segfault on a NULL for %s. It outputs |
|
Hi @bagder in this case the segfault would be caused by the EDIT: 72 if(memcmp(scheme, "HTTP", 5) != 0) {
^^^^^^ scheme is dereferenced here, but checked against NULL laterEDIT2: |
cvengler
left a comment
There was a problem hiding this comment.
The C89 standard doesn't define anything for memcmp with a NULL pointer.
See: http://port70.net/~nsz/c/c89/c89-draft.html#4.11.4.1
|
I don't think |
According to CURLINFO_SCHEME it can return NULL so technically he's correct however internally it may currently be an impossibility that it's NULL after the transfer. |
|
A comment mostly FYI: The dereference / That is my reasoning for the fix proposals
|
|
@bagder no offense taken at all. I understand if you guys see many questionable change proposals, so I just wanted to make my reasoning explicitly clear. |
|
Thanks! |
|
And thank you for kindly accepting all my small change proposals 👍 Contributing has been a very pleasant experience |
This is a proposed fix for #6709
There is a small issue of dereferencing a pointer before checking it against NULL.
From tests/libtest/lib1536.c : 72 - 76
I propose to either:
(scheme == NULL ? "NULL" : "invalid")ifschemecan never be NULL