Explorar o código

Fix a potential buffer overflow

strncpy wouldn't append the null byte in case the source
string length is >= destination buffer.

's_test_directory' is already zero initialized. So leaving
the last byte alone is enough ensure the buffer is null byte
terminated.

Signed-off-by: Ponnuvel Palaniyappan <pponnuvel@gmail.com>
Ponnuvel Palaniyappan %!s(int64=5) %!d(string=hai) anos
pai
achega
24a2f4f300
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      unittest/shared.c

+ 1 - 1
unittest/shared.c

@@ -44,5 +44,5 @@ set_test_directory(const char *const path)
 {
 	strncpy(s_test_directory,
 	        path,
-	        sizeof(s_test_directory) / sizeof(s_test_directory[0]));
+	        sizeof(s_test_directory) - 1);
 }