Fix unchecked calloc bug in network.c #492
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, i just read this Blog-post by @fluca1978 and stumbled across another bug in the same function. See below.
Also I'm curious as to why
sport
is heap-allocated in the first place? Wouldn't it be more efficient (and remove some error checking) if it was stack-allocated? In that case i would like to update the patch to convertsport
into a stack-allocated, fixed size string.Problem summary
At line 636
sport
will always be non-NULL because it has already been checked in line 608 using early return on error. Meanwhileresult
has never been checked against NULL and is subsequently used in line 696. Probable cause of the bug is inadequate copy-and-pasting of code. I assume this changes it to the intended behavior.Disclaimer
I did not try to compile or even checkout the code locally. This bug was found through static-analysis/code-review only.
Please verify that it compiles and passes any automatic tests before merging!