<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div dir="auto" style="direction: ltr; margin: 0; padding: 0; font-family: sans-serif; font-size: 11pt; color: black; ">
Very nice catch David... Countless times I've gotten bit by this one!<span id="ms-outlook-android-cursor"></span><br>
<br>
</div>
<div dir="auto" style="direction: ltr; margin: 0; padding: 0; font-family: sans-serif; font-size: 11pt; color: black; ">
<span id="OutlookSignature">
<div dir="auto" style="direction: ltr; margin: 0; padding: 0; font-family: sans-serif; font-size: 11pt; color: black; ">
Get <a href="https://aka.ms/AAb9ysg">Outlook for Android</a></div>
</span><br>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> virtio-fs-bounces@redhat.com <virtio-fs-bounces@redhat.com> on behalf of Dr. David Alan Gilbert (git) <dgilbert@redhat.com><br>
<b>Sent:</b> Thursday, May 6, 2021 1:56:30 PM<br>
<b>To:</b> qemu-devel@nongnu.org <qemu-devel@nongnu.org>; groug@kaod.org <groug@kaod.org>; jose.carlos.venegas.munoz@intel.com <jose.carlos.venegas.munoz@intel.com>; ma.mandourr@gmail.com <ma.mandourr@gmail.com><br>
<b>Cc:</b> virtio-fs@redhat.com <virtio-fs@redhat.com>; vgoyal@redhat.com <vgoyal@redhat.com><br>
<b>Subject:</b> [Virtio-fs] [PULL 01/12] virtiofsd: Fix side-effect in assert()</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">External email: Use caution opening links or attachments<br>
<br>
<br>
From: Greg Kurz <groug@kaod.org><br>
<br>
It is bad practice to put an expression with a side-effect in<br>
assert() because the side-effect won't happen if the code is<br>
compiled with -DNDEBUG.<br>
<br>
Use an intermediate variable. Consolidate this in an macro to<br>
have proper line numbers when the assertion is hit.<br>
<br>
virtiofsd: ../../tools/virtiofsd/passthrough_ll.c:2797: lo_getxattr:<br>
 Assertion `fchdir_res == 0' failed.<br>
Aborted<br>
<br>
  2796          /* fchdir should not fail here */<br>
=>2797          FCHDIR_NOFAIL(lo->proc_self_fd);<br>
  2798          ret = getxattr(procname, name, value, size);<br>
  2799          FCHDIR_NOFAIL(lo->root.fd);<br>
<br>
Fixes: bdfd66788349 ("virtiofsd: Fix xattr operations")<br>
Cc: misono.tomohiro@jp.fujitsu.com<br>
Signed-off-by: Greg Kurz <groug@kaod.org><br>
Message-Id: <20210409100627.451573-1-groug@kaod.org><br>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com><br>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com><br>
---<br>
 tools/virtiofsd/passthrough_ll.c | 21 +++++++++++++--------<br>
 1 file changed, 13 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c<br>
index 1553d2ef45..6592f96f68 100644<br>
--- a/tools/virtiofsd/passthrough_ll.c<br>
+++ b/tools/virtiofsd/passthrough_ll.c<br>
@@ -2723,6 +2723,11 @@ static int xattr_map_server(const struct lo_data *lo, const char *server_name,<br>
     return -ENODATA;<br>
 }<br>
<br>
+#define FCHDIR_NOFAIL(fd) do {                         \<br>
+        int fchdir_res = fchdir(fd);                   \<br>
+        assert(fchdir_res == 0);                       \<br>
+    } while (0)<br>
+<br>
 static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,<br>
                         size_t size)<br>
 {<br>
@@ -2789,9 +2794,9 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,<br>
         ret = fgetxattr(fd, name, value, size);<br>
     } else {<br>
         /* fchdir should not fail here */<br>
-        assert(fchdir(lo->proc_self_fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->proc_self_fd);<br>
         ret = getxattr(procname, name, value, size);<br>
-        assert(fchdir(lo->root.fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->root.fd);<br>
     }<br>
<br>
     if (ret == -1) {<br>
@@ -2864,9 +2869,9 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)<br>
         ret = flistxattr(fd, value, size);<br>
     } else {<br>
         /* fchdir should not fail here */<br>
-        assert(fchdir(lo->proc_self_fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->proc_self_fd);<br>
         ret = listxattr(procname, value, size);<br>
-        assert(fchdir(lo->root.fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->root.fd);<br>
     }<br>
<br>
     if (ret == -1) {<br>
@@ -3000,9 +3005,9 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,<br>
         ret = fsetxattr(fd, name, value, size, flags);<br>
     } else {<br>
         /* fchdir should not fail here */<br>
-        assert(fchdir(lo->proc_self_fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->proc_self_fd);<br>
         ret = setxattr(procname, name, value, size, flags);<br>
-        assert(fchdir(lo->root.fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->root.fd);<br>
     }<br>
<br>
     saverr = ret == -1 ? errno : 0;<br>
@@ -3066,9 +3071,9 @@ static void lo_removexattr(fuse_req_t req, fuse_ino_t ino, const char *in_name)<br>
         ret = fremovexattr(fd, name);<br>
     } else {<br>
         /* fchdir should not fail here */<br>
-        assert(fchdir(lo->proc_self_fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->proc_self_fd);<br>
         ret = removexattr(procname, name);<br>
-        assert(fchdir(lo->root.fd) == 0);<br>
+        FCHDIR_NOFAIL(lo->root.fd);<br>
     }<br>
<br>
     saverr = ret == -1 ? errno : 0;<br>
--<br>
2.31.1<br>
<br>
_______________________________________________<br>
Virtio-fs mailing list<br>
Virtio-fs@redhat.com<br>
<a href="https://listman.redhat.com/mailman/listinfo/virtio-fs">https://listman.redhat.com/mailman/listinfo/virtio-fs</a><br>
</div>
</span></font></div>
</body>
</html>