lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 15 May 2024 01:08:04 +0000
From: Abhinav Saxena <xandfury@...il.com>
To: linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	llvm@...ts.linux.dev
Cc: Shuah Khan <shuah@...nel.org>,
	Nathan Chancellor <nathan@...nel.org>,
	Nick Desaulniers <ndesaulniers@...gle.com>,
	Bill Wendling <morbo@...gle.com>,
	Justin Stitt <justinstitt@...gle.com>,
	Abhinav Saxena <xandfury@...il.com>
Subject: [RFC PATCH 3/4] selftests/binderfs: Macro argument 'fd' may be better as '(fd)' to avoid precedence issues

Change the macro argument 'fd' to '(fd)' to avoid potential precedence
issues. Without parentheses, the macro expansion could lead to
unexpected behavior when used with an expression having different
precedence levels.

Example Code:

    #define CALC_SQR_BAD(x) (x*x)
    #define CALC_SQR_GOOD(x) ((x)*(x))

CALC_SQR_BAD(2+3) expands to 2+(3*3)+2, giving 11 as the incorrect
answer. Enclosing with parathesis CALC_SQR_GOOD(2+3) sets the correct
order of precedence and expands to (2+3)*(2+3), giving 25 as the
correct answer.

Signed-off-by: Abhinav Saxena <xandfury@...il.com>
---
 .../testing/selftests/filesystems/binderfs/binderfs_test.c  | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
index 4a149e3d4ba4..d5dba6c1e07f 100644
--- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
+++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c
@@ -30,11 +30,11 @@

 #define close_prot_errno_disarm(fd)      \
 	do {				 \
-		if (fd >= 0) {		 \
+		if ((fd) >= 0) {	 \
 			int _e_ = errno; \
-			close(fd);	 \
+			close((fd));	 \
 			errno = _e_;	 \
-			fd = -EBADF;	 \
+			(fd) = -EBADF;	 \
 		}			 \
 	} while (false)

--
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ