|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-01-13 18:04 UTC] bugreports at internot dot info
Description:
------------
Hi,
In /ext/fileinfo/libmagic/apprentice.c:
2609 if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
2610 file_oomem(ms, sizeof(*map));
2611 efree(map);
2612 goto error;
2613 }
That goes to error:
2730error:
2731 if (stream) {
2732 php_stream_close(stream);
2733 }
2734 apprentice_unmap(map);
which as you can see, does a double free of 'map'.
The line in the apprentice_unmap function:
499 if (map == NULL)
is kind of useless, because even if it has already been freed, it won't be NULL(unless the php implementation of efree does something different?)
Thanks,
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 07:00:01 2025 UTC |
The lines in if (map == ..) won't be executed ever when using Zend memory manager, because it bails out immediately on OOM error, so the only way to get them executed is to disable Zend MM and go with system MM. man free says: If ptr is NULL, no operation is performed. apprentice_unmap(): if (map == NULL) return; So.. where is the problem here?That's correct, efree() doesn't modify the pointer. But it's already NULL at the time efree() is called, take a look at the if condition: if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) { file_oomem(ms, sizeof(*map)); efree(map); goto error; }