* [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size()
@ 2025-10-30 1:53 alistair23
2025-10-30 1:53 ` [PATCH 2/3] hw/core/loader: Free the image file descriptor on error alistair23
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: alistair23 @ 2025-10-30 1:53 UTC (permalink / raw)
To: philmd, alistair.francis, vishalc, qemu-devel; +Cc: alistair23
From: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
hw/core/loader.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 590c5b02aa..73564a2a46 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -75,14 +75,20 @@ int64_t get_image_size(const char *filename, Error **errp)
{
int fd;
int64_t size;
+
fd = qemu_open(filename, O_RDONLY | O_BINARY, errp);
- if (fd < 0)
+
+ if (fd < 0) {
return -1;
+ }
+
size = lseek(fd, 0, SEEK_END);
+
if (size < 0) {
error_setg_errno(errp, errno, "lseek failure: %s", filename);
return -1;
}
+
close(fd);
return size;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/3] hw/core/loader: Free the image file descriptor on error
2025-10-30 1:53 [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() alistair23
@ 2025-10-30 1:53 ` alistair23
2025-10-30 8:24 ` Philippe Mathieu-Daudé
2025-10-30 8:27 ` Vishal Chourasia
2025-10-30 1:53 ` [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str() alistair23
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: alistair23 @ 2025-10-30 1:53 UTC (permalink / raw)
To: philmd, alistair.francis, vishalc, qemu-devel; +Cc: alistair23
From: Alistair Francis <alistair.francis@wdc.com>
Coverity: CID 1642764
Fixes: f62226f7dc4 ("hw/core/loader: improve error handling in image loading functions")
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
hw/core/loader.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 73564a2a46..1598dca03c 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -86,6 +86,7 @@ int64_t get_image_size(const char *filename, Error **errp)
if (size < 0) {
error_setg_errno(errp, errno, "lseek failure: %s", filename);
+ close(fd);
return -1;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] hw/core/loader: Free the image file descriptor on error
2025-10-30 1:53 ` [PATCH 2/3] hw/core/loader: Free the image file descriptor on error alistair23
@ 2025-10-30 8:24 ` Philippe Mathieu-Daudé
2025-10-30 8:27 ` Vishal Chourasia
1 sibling, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-30 8:24 UTC (permalink / raw)
To: alistair23, alistair.francis, vishalc, qemu-devel
On 30/10/25 02:53, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Coverity: CID 1642764
> Fixes: f62226f7dc4 ("hw/core/loader: improve error handling in image loading functions")
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/core/loader.c | 1 +
> 1 file changed, 1 insertion(+)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 2/3] hw/core/loader: Free the image file descriptor on error
2025-10-30 1:53 ` [PATCH 2/3] hw/core/loader: Free the image file descriptor on error alistair23
2025-10-30 8:24 ` Philippe Mathieu-Daudé
@ 2025-10-30 8:27 ` Vishal Chourasia
1 sibling, 0 replies; 9+ messages in thread
From: Vishal Chourasia @ 2025-10-30 8:27 UTC (permalink / raw)
To: alistair23; +Cc: philmd, alistair.francis, qemu-devel
On Thu, Oct 30, 2025 at 11:53:05AM +1000, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Coverity: CID 1642764
> Fixes: f62226f7dc4 ("hw/core/loader: improve error handling in image loading functions")
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/core/loader.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 73564a2a46..1598dca03c 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -86,6 +86,7 @@ int64_t get_image_size(const char *filename, Error **errp)
>
> if (size < 0) {
> error_setg_errno(errp, errno, "lseek failure: %s", filename);
> + close(fd);
> return -1;
> }
Reviewed-by: Vishal Chourasia <vishalc@linux.ibm.com>
>
> --
> 2.51.0
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str()
2025-10-30 1:53 [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() alistair23
2025-10-30 1:53 ` [PATCH 2/3] hw/core/loader: Free the image file descriptor on error alistair23
@ 2025-10-30 1:53 ` alistair23
2025-10-30 8:26 ` Philippe Mathieu-Daudé
2025-10-31 1:10 ` Alistair Francis
2025-10-30 8:23 ` [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() Vishal Chourasia
2025-10-30 8:26 ` Philippe Mathieu-Daudé
3 siblings, 2 replies; 9+ messages in thread
From: alistair23 @ 2025-10-30 1:53 UTC (permalink / raw)
To: philmd, alistair.francis, vishalc, qemu-devel; +Cc: alistair23
From: Alistair Francis <alistair.francis@wdc.com>
The string needs be be freed with g_free() according to the functions
documentation.
Coverity: CID 1642762
Fixes: f62226f7dc44 ("hw/core/loader: improve error handling in image loading functions")
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
hw/core/loader.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 1598dca03c..e83d245202 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -153,8 +153,12 @@ ssize_t load_image_targphys_as(const char *filename,
}
if (size > max_sz) {
+ char *size_str = size_to_str(max_sz);
+
error_setg(errp, "%s exceeds maximum image size (%s)",
- filename, size_to_str(max_sz));
+ filename, size_str);
+
+ g_free(size_str);
return -1;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str()
2025-10-30 1:53 ` [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str() alistair23
@ 2025-10-30 8:26 ` Philippe Mathieu-Daudé
2025-10-31 1:10 ` Alistair Francis
1 sibling, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-30 8:26 UTC (permalink / raw)
To: alistair23, alistair.francis, vishalc, qemu-devel
On 30/10/25 02:53, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
>
> The string needs be be freed with g_free() according to the functions
> documentation.
>
> Coverity: CID 1642762
> Fixes: f62226f7dc44 ("hw/core/loader: improve error handling in image loading functions")
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/core/loader.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 1598dca03c..e83d245202 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -153,8 +153,12 @@ ssize_t load_image_targphys_as(const char *filename,
> }
>
> if (size > max_sz) {
> + char *size_str = size_to_str(max_sz);
> +
> error_setg(errp, "%s exceeds maximum image size (%s)",
> - filename, size_to_str(max_sz));
> + filename, size_str);
> +
> + g_free(size_str);
Or g_autofree. Anyhow,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> return -1;
> }
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str()
2025-10-30 1:53 ` [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str() alistair23
2025-10-30 8:26 ` Philippe Mathieu-Daudé
@ 2025-10-31 1:10 ` Alistair Francis
1 sibling, 0 replies; 9+ messages in thread
From: Alistair Francis @ 2025-10-31 1:10 UTC (permalink / raw)
To: philmd, alistair.francis, vishalc, qemu-devel
On Thu, Oct 30, 2025 at 11:53 AM <alistair23@gmail.com> wrote:
>
> From: Alistair Francis <alistair.francis@wdc.com>
>
> The string needs be be freed with g_free() according to the functions
> documentation.
>
> Coverity: CID 1642762
> Fixes: f62226f7dc44 ("hw/core/loader: improve error handling in image loading functions")
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Thanks!
Applied to riscv-to-apply.next
Alistair
> ---
> hw/core/loader.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 1598dca03c..e83d245202 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -153,8 +153,12 @@ ssize_t load_image_targphys_as(const char *filename,
> }
>
> if (size > max_sz) {
> + char *size_str = size_to_str(max_sz);
> +
> error_setg(errp, "%s exceeds maximum image size (%s)",
> - filename, size_to_str(max_sz));
> + filename, size_str);
> +
> + g_free(size_str);
> return -1;
> }
>
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size()
2025-10-30 1:53 [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() alistair23
2025-10-30 1:53 ` [PATCH 2/3] hw/core/loader: Free the image file descriptor on error alistair23
2025-10-30 1:53 ` [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str() alistair23
@ 2025-10-30 8:23 ` Vishal Chourasia
2025-10-30 8:26 ` Philippe Mathieu-Daudé
3 siblings, 0 replies; 9+ messages in thread
From: Vishal Chourasia @ 2025-10-30 8:23 UTC (permalink / raw)
To: alistair23, philmd, alistair.francis, qemu-devel
LGTM
Reviewed-by:Vishal Chourasia <vishalc@linux.ibm.com>
On 30/10/25 07:23, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/core/loader.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 590c5b02aa..73564a2a46 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -75,14 +75,20 @@ int64_t get_image_size(const char *filename, Error **errp)
> {
> int fd;
> int64_t size;
> +
> fd = qemu_open(filename, O_RDONLY | O_BINARY, errp);
> - if (fd < 0)
> +
> + if (fd < 0) {
> return -1;
> + }
> +
> size = lseek(fd, 0, SEEK_END);
> +
> if (size < 0) {
> error_setg_errno(errp, errno, "lseek failure: %s", filename);
> return -1;
> }
> +
> close(fd);
> return size;
> }
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size()
2025-10-30 1:53 [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() alistair23
` (2 preceding siblings ...)
2025-10-30 8:23 ` [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() Vishal Chourasia
@ 2025-10-30 8:26 ` Philippe Mathieu-Daudé
3 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-30 8:26 UTC (permalink / raw)
To: alistair23, alistair.francis, vishalc, qemu-devel
On 30/10/25 02:53, alistair23@gmail.com wrote:
> From: Alistair Francis <alistair.francis@wdc.com>
>
> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
> ---
> hw/core/loader.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-10-31 1:13 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-30 1:53 [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() alistair23
2025-10-30 1:53 ` [PATCH 2/3] hw/core/loader: Free the image file descriptor on error alistair23
2025-10-30 8:24 ` Philippe Mathieu-Daudé
2025-10-30 8:27 ` Vishal Chourasia
2025-10-30 1:53 ` [PATCH 3/3] hw/core/loader: Free the allocated string from size_to_str() alistair23
2025-10-30 8:26 ` Philippe Mathieu-Daudé
2025-10-31 1:10 ` Alistair Francis
2025-10-30 8:23 ` [PATCH 1/3] hw/core/loader: Fixup whitespace for get_image_size() Vishal Chourasia
2025-10-30 8:26 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).