Skip to contentSkip to conversation

x86/pkeys: seftests: off by one in sigsafe_printf()

PATCH New Dan Carpenter 1 participant 1 message Oct 13, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/pkeys: seftests: off by one in sigsafe_printf()

We want "len" to represent the number of characters printed not counting the NUL terminator. At most there will be "DPRINT_IN_SIGNAL_BUF_SIZE - 1" characters printed.

Fixes 5f23f6d082a9 ("x86/pkeys: Add self-tests")
tools/testing/selftests/x86/pkey-helpers.h +2 -2
index b202939..1f21661 100644
@@ -36,8 +36,8 @@ static inline void sigsafe_printf(const char *format, ...)
 		 * len is amount that would have been printed,
 		 * but actual write is truncated at BUF_SIZE.
 		 */
-		if (len > DPRINT_IN_SIGNAL_BUF_SIZE)
-			len = DPRINT_IN_SIGNAL_BUF_SIZE;
+		if (len >= DPRINT_IN_SIGNAL_BUF_SIZE)
+			len = DPRINT_IN_SIGNAL_BUF_SIZE - 1;
 		write(1, dprint_in_signal_buffer, len);
 	}
 	va_end(ap);