Module: wine Branch: master Commit: 88a5c64b9369baa592163e3cdafe1570a17fcabc URL: https://gitlab.winehq.org/wine/wine/-/commit/88a5c64b9369baa592163e3cdafe157...
Author: Alex Henrie alexhenrie24@gmail.com Date: Sun Dec 11 22:15:04 2022 -0700
hhctrl: Handle memory allocation failure in ReadChmSystem (cppcheck).
---
dlls/hhctrl.ocx/chm.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/dlls/hhctrl.ocx/chm.c b/dlls/hhctrl.ocx/chm.c index fb982303a3c..4be86bd165a 100644 --- a/dlls/hhctrl.ocx/chm.c +++ b/dlls/hhctrl.ocx/chm.c @@ -82,7 +82,7 @@ static BOOL ReadChmSystem(CHMInfo *chm) { IStream *stream; DWORD ver=0xdeadbeef, read, buf_size; - char *buf; + char *buf, *new_buf; HRESULT hres;
struct { @@ -101,16 +101,27 @@ static BOOL ReadChmSystem(CHMInfo *chm) IStream_Read(stream, &ver, sizeof(ver), &read); TRACE("version is %lx\n", ver);
- buf = malloc(8 * sizeof(DWORD)); - buf_size = 8*sizeof(DWORD); + buf_size = 8 * sizeof(DWORD); + buf = malloc(buf_size); + if(!buf) { + IStream_Release(stream); + return FALSE; + }
while(1) { hres = IStream_Read(stream, &entry, sizeof(entry), &read); if(hres != S_OK) break;
- if(entry.len > buf_size) - buf = realloc(buf, buf_size=entry.len); + if(entry.len > buf_size) { + new_buf = realloc(buf, entry.len); + if(!new_buf) { + hres = E_OUTOFMEMORY; + break; + } + buf = new_buf; + buf_size = entry.len; + }
hres = IStream_Read(stream, buf, entry.len, &read); if(hres != S_OK)