New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
check ptr against NULL before dereferencing it #6710
Conversation
@@ -69,7 +69,7 @@ int test(char *URL) | |||
__FILE__, __LINE__, res, curl_easy_strerror(res)); | |||
goto test_cleanup; | |||
} | |||
if(memcmp(scheme, "HTTP", 5) != 0) { | |||
if(scheme == NULL || memcmp(scheme, "HTTP", 5) != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, makes sense.
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 later EDIT2: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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")
ifscheme
can never be NULL