drivers/net/wimax/i2400m/fw.c fix possible double free
Subsystems (2)
Quoted 3 lines · David Miller
Therefore the
krealloc()failure handling in this driver should NULL outi2400m->fw_hdrsand that will fix the double kfree problem as well as trap any stray references.
Yes that is a much better Idea. Thanks for the advice.
It also fixes the i2400m_barker_db problem that I didn't notice before.
Fix double free on krealloc() failure by zeroing pointer
coverity CID: 13455
--- drivers/net/wimax/i2400m/fw.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/wimax/i2400m/fw.c +3 -2
@@ -232,8 +232,9 @@ int i2400m_zrealloc_2x(void **ptr, size_t *_count, size_t el_size, *_count = new_count; *ptr = nptr;return 0 ; - }else -return -ENOMEM ; + } + *ptr =NULL ; +return -ENOMEM ; }
Signature · 1 line
1.6.3.3
Quoted 7 lines · Darren Jenkins
Quoted 3 lines · David Miller
Therefore the
krealloc()failure handling in this driver should NULL outi2400m->fw_hdrsand that will fix the double kfree problem as well as trap any stray references.
Quoted 5 lines
Yes that is a much better Idea. Thanks for the advice.
It also fixes thei2400m_barker_dbproblem that I didn't notice before.Fix double free on
krealloc()failure by zeroing pointer
If krealloc() fails to aallocate a new pointer, the old block is unmodified, so by doing this you are leaking a buffer allocation.
I think this should be solved at the site where i2400m_zrealloc_2x() is called, with a
if (result < 0) {kfree(i2400m->fw_hdrs);i2400m->fw_hdrs = NULL;
goto error_zrealloc;
}
or any other better fix. I am hesitant of having zrealloc_2x free the original pointer because it breaks the traditional semantics that come along being called 'realloc' (realloc if successful, keep the original if not).
Am I missing anything?
Quoted 23 lines
coverity CID: 13455
Signed-off-by Darren Jenkins <[email protected]>--- drivers/net/wimax/i2400m/fw.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)drivers/net/wimax/i2400m/fw.c +3
-2@@ -232,8 +232,9 @@ int i2400m_zrealloc_2x(void **ptr, size_t *_count, size_t el_size, *_count = new_count; *ptr = nptr;return 0 ; - }else -return -ENOMEM ; + } + *ptr =NULL ; +return -ENOMEM ; }