Skip to contentSkip to conversation

block: Save errno before error_setg_errno

PATCH Applied Max Reitz 4 participants 5 messages Nov 5, 2013 – Nov 6, 2013

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 block: Save errno before error_setg_errno

error_setg_errno() may overwrite errno; therefore, its value should be read before calling that function and not afterwards.

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index 58efb5b..0e96a22 100644
@@ -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;
         }
 
Signature · 1 line
1.8.4.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Max Reitz

error_setg_errno() may overwrite errno; therefore, its value should be read before calling that function and not afterwards.

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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?

Quoted 16 lines
block.c +1 -1
index 58efb5b..0e96a22 100644
@@ -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;
         }
 
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 9 lines · Eric Blake
Quoted 7 lines · Max Reitz

error_setg_errno() may overwrite errno; therefore, its value should be read before calling that function and not afterwards.

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines

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

Reviewed-by Benoit Canet on v1 1/1
#3 lore raw
In reply to Max Reitz
Quoted 25 lines · Max Reitz

error_setg_errno() may overwrite errno; therefore, its value should be read before calling that function and not afterwards.

---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index 58efb5b..0e96a22 100644
@@ -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;
         }
 
Signature · 1 line
1.8.4.2
Quoted 1 line