Repository navigation
Make sure to not try freeing an uninitialized pointer - #1463
Conversation
|
|
||
| char **files_in_cue; | ||
| char **files_in_cue = NULL; | ||
| int n = cue_get_files(ents[i], &files_in_cue); |
There was a problem hiding this comment.
The uninitialized pointer happens when cue_get_files returns -1, which happens when cue_from_file returns NULL, which happens if mmap_file fails or the cue parse returns an error.
The fix should be to add an if (n == -1) continue after the cue_get_files call.
There was a problem hiding this comment.
I believe that also if the n is 0 files_in_cue would be null ? (I didn't follow xnew() implementation but I would assume so).
I can check against 'n' instead of checking for files_in_cue being NULL (which anyway is a better check to do here IMO ... because allocation could fail as well inside cue_get_files() and you would still try freeing an invalid address)
but maybe we should check for n being > 0 instead that != -1?
There was a problem hiding this comment.
It's safe to call free on null.
The rest of the code tends to check against != -1. But, since there's not any point in doing the rest of the stuff if it's zero-length, wrapping the rest in an if > 1 makes sense.
Free should still be called if n == 0, but not if n == -1.
There was a problem hiding this comment.
it's true that it is safe to call free on null ... but that pointer was not set to null it was left uninitialized ;)
5f43f10 to
8bef306
Compare
While playing around with cmus and trying to load my Music archive I stumbled upon this bug ... reported as double free but actually trying to free an unitialized pointer.