* [Qemu-devel] [PATCH] block: Save errno before error_setg_errno
@ 2013-11-05 19:03 Max Reitz
2013-11-05 19:26 ` Eric Blake
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Max Reitz @ 2013-11-05 19:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz
error_setg_errno() may overwrite errno; therefore, its value should be
read before calling that function and not afterwards.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 58efb5b..0e96a22 100644
--- a/block.c
+++ b/block.c
@@ -1084,8 +1084,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
snprintf(backing_filename, sizeof(backing_filename),
"%s", filename);
} else if (!realpath(filename, backing_filename)) {
- error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
ret = -errno;
+ error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
goto fail;
}
--
1.8.4.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Save errno before error_setg_errno
2013-11-05 19:03 [Qemu-devel] [PATCH] block: Save errno before error_setg_errno Max Reitz
@ 2013-11-05 19:26 ` Eric Blake
2013-11-06 10:32 ` Stefan Hajnoczi
2013-11-05 20:04 ` Benoît Canet
2013-11-06 10:32 ` Stefan Hajnoczi
2 siblings, 1 reply; 5+ messages in thread
From: Eric Blake @ 2013-11-05 19:26 UTC (permalink / raw)
To: Max Reitz, qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
[-- Attachment #1: Type: text/plain, Size: 1308 bytes --]
On 11/05/2013 12:03 PM, Max Reitz wrote:
> error_setg_errno() may overwrite errno; therefore, its value should be
> read before calling that function and not afterwards.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
Still, wouldn't it be easier to patch error_setg_errno (and friends) to
guarantee that errno is unchanged on exit compared to its value on
entrance, rather than having to audit for other mistakes like this?
>
> diff --git a/block.c b/block.c
> index 58efb5b..0e96a22 100644
> --- a/block.c
> +++ b/block.c
> @@ -1084,8 +1084,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
> snprintf(backing_filename, sizeof(backing_filename),
> "%s", filename);
> } else if (!realpath(filename, backing_filename)) {
> - error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
> ret = -errno;
> + error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
> goto fail;
> }
>
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Save errno before error_setg_errno
2013-11-05 19:03 [Qemu-devel] [PATCH] block: Save errno before error_setg_errno Max Reitz
2013-11-05 19:26 ` Eric Blake
@ 2013-11-05 20:04 ` Benoît Canet
2013-11-06 10:32 ` Stefan Hajnoczi
2 siblings, 0 replies; 5+ messages in thread
From: Benoît Canet @ 2013-11-05 20:04 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi
Le Tuesday 05 Nov 2013 à 20:03:33 (+0100), Max Reitz a écrit :
> error_setg_errno() may overwrite errno; therefore, its value should be
> read before calling that function and not afterwards.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/block.c b/block.c
> index 58efb5b..0e96a22 100644
> --- a/block.c
> +++ b/block.c
> @@ -1084,8 +1084,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
> snprintf(backing_filename, sizeof(backing_filename),
> "%s", filename);
> } else if (!realpath(filename, backing_filename)) {
> - error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
> ret = -errno;
> + error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
> goto fail;
> }
>
> --
> 1.8.4.2
>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Save errno before error_setg_errno
2013-11-05 19:03 [Qemu-devel] [PATCH] block: Save errno before error_setg_errno Max Reitz
2013-11-05 19:26 ` Eric Blake
2013-11-05 20:04 ` Benoît Canet
@ 2013-11-06 10:32 ` Stefan Hajnoczi
2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-11-06 10:32 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi
On Tue, Nov 05, 2013 at 08:03:33PM +0100, Max Reitz wrote:
> error_setg_errno() may overwrite errno; therefore, its value should be
> read before calling that function and not afterwards.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH] block: Save errno before error_setg_errno
2013-11-05 19:26 ` Eric Blake
@ 2013-11-06 10:32 ` Stefan Hajnoczi
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2013-11-06 10:32 UTC (permalink / raw)
To: Eric Blake; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi, Max Reitz
On Tue, Nov 05, 2013 at 12:26:41PM -0700, Eric Blake wrote:
> On 11/05/2013 12:03 PM, Max Reitz wrote:
> > error_setg_errno() may overwrite errno; therefore, its value should be
> > read before calling that function and not afterwards.
> >
> > Signed-off-by: Max Reitz <mreitz@redhat.com>
> > ---
> > block.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
> Still, wouldn't it be easier to patch error_setg_errno (and friends) to
> guarantee that errno is unchanged on exit compared to its value on
> entrance, rather than having to audit for other mistakes like this?
Agreed, that can be done as a separate patch.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-11-06 10:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-05 19:03 [Qemu-devel] [PATCH] block: Save errno before error_setg_errno Max Reitz
2013-11-05 19:26 ` Eric Blake
2013-11-06 10:32 ` Stefan Hajnoczi
2013-11-05 20:04 ` Benoît Canet
2013-11-06 10:32 ` Stefan Hajnoczi
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).