elf2dmp: Fix minor Coverity nits
v2 cover elf2dmp: Fix minor Coverity nits
This is a respin of Peter Maydell series, with slightly different logic on the first patch. Quoting v1 cover [*]:
Coverity complains about a couple of minor issues in elf2dmp:
* we weren't checking the return value from curl_easy_setopt()
* we might divide by zero if presented with a corrupt PDB file
This patchseries fixes those.
Viktor Prutyanov tested the patch but didn't provided a formal Tested-by tag, so I haven't included it in the patches.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Peter Maydell (2):
elf2dmp: Check curl_easy_setopt() return value
elf2dmp: Fail cleanly if PDB file specifies zero block_size
contrib/elf2dmp/download.c | 22 ++++++++++------------ contrib/elf2dmp/pdb.c | 4 ++++ 2 files changed, 14 insertions(+), 12 deletions(-)
Signature · 1 line
2.31.1
PATCH v2 1/2 elf2dmp: Check curl_easy_setopt() return value
From: Peter Maydell <[email protected]>
Coverity points out that we aren't checking the return value from curl_easy_setopt().
---
Informal T-b tag on
https://lore.kernel.org/qemu-devel/[email protected]/
v1 from Peter:
https://lore.kernel.org/qemu-devel/[email protected]/
--- contrib/elf2dmp/download.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
contrib/elf2dmp/download.c +10 -12
@@ -25,21 +25,19 @@ int download_url(const char *name, const char *url) goto out_curl; } -curl_easy_setopt (curl,CURLOPT_URL , url); -curl_easy_setopt (curl,CURLOPT_WRITEFUNCTION ,NULL ); -curl_easy_setopt (curl,CURLOPT_WRITEDATA , file); -curl_easy_setopt (curl,CURLOPT_FOLLOWLOCATION ,1 ); -curl_easy_setopt (curl,CURLOPT_NOPROGRESS ,0 ); - -if (curl_easy_perform (curl) !=CURLE_OK ) { - err =1 ; -fclose (file); +if (curl_easy_setopt (curl,CURLOPT_URL , url) !=CURLE_OK + ||curl_easy_setopt (curl,CURLOPT_WRITEFUNCTION ,NULL ) !=CURLE_OK + ||curl_easy_setopt (curl,CURLOPT_WRITEDATA , file) !=CURLE_OK + ||curl_easy_setopt (curl,CURLOPT_FOLLOWLOCATION ,1 ) !=CURLE_OK + ||curl_easy_setopt (curl,CURLOPT_NOPROGRESS ,0 ) !=CURLE_OK + ||curl_easy_perform (curl) !=CURLE_OK ) {unlink (name); - goto out_curl; +fclose (file); + err =1 ; + }else { + err =fclose (file); } - err =fclose (file); - out_curl:curl_easy_cleanup (curl);
Signature · 1 line
2.31.1
PATCH v2 2/2 elf2dmp: Fail cleanly if PDB file specifies zero block_size
In reply to Philippe Mathieu-DaudéFrom: Peter Maydell <[email protected]>
Coverity points out that if the PDB file we're trying to read has a header specifying a block_size of zero then we will end up trying to divide by zero in pdb_ds_read_file(). Check for this and fail cleanly instead.
Message-Id: <[email protected]>
---
Informal T-b tag on
https://lore.kernel.org/qemu-devel/[email protected]/
--- contrib/elf2dmp/pdb.c | 4 ++++ 1 file changed, 4 insertions(+)
contrib/elf2dmp/pdb.c +4 -0
@@ -215,6 +215,10 @@ out_symbols:static int pdb_reader_ds_init (struct pdb_reader *r,PDB_DS_HEADER *hdr) { +if (hdr->block_size ==0 ) { +return 1 ; + } +memset (r->file_used,0 ,sizeof (r->file_used)); r->ds.header = hdr; r->ds.toc = pdb_ds_read(hdr, (uint32_t *)((uint8_t *)hdr +
Signature · 1 line
2.31.1
Re: [PATCH v2 2/2] elf2dmp: Fail cleanly if PDB file specifies zero block_size
Hi,
Quoted 25 lines · On Fri, 10 Sep 2021 19:06:56 +0200 Philippe Mathieu-Daudé <[email protected]>…
From: Peter Maydell <[email protected]>
Coverity points out that if the PDB file we're trying to read has a header specifying a
block_sizeof zero then we will end up trying to divide by zero inpdb_ds_read_file(). Check for this and fail cleanly instead.Fixes Coverity CID 1458869Signed-off-by Peter Maydell <[email protected]>Reviewed-by Viktor Prutyanov <[email protected]>Message-Id: <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Informal T-b tag on
https://lore.kernel.org/qemu-devel/[email protected]/Tested-by Viktor Prutyanov <[email protected]>--- contrib/elf2dmp/pdb.c | 4 ++++ 1 file changed, 4 insertions(+)contrib/elf2dmp/pdb.c +0
-0
contrib/elf2dmp/pdb.c out_symbols: · line 224
Quoted 10 lines
contrib/elf2dmp/pdb.c +4
-0@@ -215,6 +215,10 @@ out_symbols:static int pdb_reader_ds_init (struct pdb_reader *r,PDB_DS_HEADER *hdr) { +if (hdr->block_size ==0 ) { +return 1 ; + } +memset (r->file_used,0 ,sizeof (r->file_used)); r->ds.header = hdr; r->ds.toc = pdb_ds_read(hdr, (uint32_t *)((uint8_t *)hdr +
Signature · 1 line
Viktor Prutyanov
Re: [PATCH v2 1/2] elf2dmp: Check curl_easy_setopt() return value
In reply to Philippe Mathieu-DaudéHi,
Quoted 49 lines · On Fri, 10 Sep 2021 19:06:55 +0200 Philippe Mathieu-Daudé <[email protected]>…
From: Peter Maydell <[email protected]>
Coverity points out that we aren't checking the return value from
curl_easy_setopt().Fixes Coverity CID 1458895Inspired-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Informal T-b tag on
https://lore.kernel.org/qemu-devel/[email protected]/Tested-by Viktor Prutyanov <[email protected]>v1 from Peter:
https://lore.kernel.org/qemu-devel/[email protected]/--- contrib/elf2dmp/download.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)contrib/elf2dmp/download.c +2
-9@@ -25,21 +25,19 @@ int download_url(const char *name, const char *url) goto out_curl; } -curl_easy_setopt (curl,CURLOPT_URL , url); -curl_easy_setopt (curl,CURLOPT_WRITEFUNCTION ,NULL ); -curl_easy_setopt (curl,CURLOPT_WRITEDATA , file); -curl_easy_setopt (curl,CURLOPT_FOLLOWLOCATION ,1 ); -curl_easy_setopt (curl,CURLOPT_NOPROGRESS ,0 ); - -if (curl_easy_perform (curl) !=CURLE_OK ) { - err =1 ; -fclose (file); +if (curl_easy_setopt (curl,CURLOPT_URL , url) !=CURLE_OK + || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL)!=
CURLE_OK
+ ||curl_easy_setopt(curl, CURLOPT_WRITEDATA, file)!=CURLE_OK
+ ||curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1)!=CURLE_OK
+ ||curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0)!=CURLE_OKcontrib/elf2dmp/download.c +1
-1+ || curl_easy_perform(curl) != CURLE_OK) {unlink (name); - goto out_curl;
contrib/elf2dmp/download.c int download_url(const char *name, const char *url) · line 42
Quoted 10 lines
contrib/elf2dmp/download.c +4
-2+fclose (file); + err =1 ; + }else { + err =fclose (file); } - err =fclose (file); - out_curl:curl_easy_cleanup (curl);
Signature · 1 line
Viktor Prutyanov
Quoted 10 lines · Philippe Mathieu-Daudé
This is a respin of Peter Maydell series, with slightly different logic on the first patch. Quoting v1 cover [*]:
Coverity complains about a couple of minor issues in elf2dmp:
* we weren't checking the return value fromcurl_easy_setopt()
* we might divide by zero if presented with a corrupt PDB fileThis patchseries fixes those.
Quoted 8 lines
Viktor Prutyanov tested the patch but didn't provided a formal Tested-by tag, so I haven't included it in the patches.
[*] https://lore.kernel.org/qemu-devel/[email protected]/
Peter Maydell (2):
elf2dmp: Checkcurl_easy_setopt()return value
elf2dmp: Fail cleanly if PDB file specifies zeroblock_size
Thanks for doing the respin; I'll take this via target-arm.next.
-- PMM