瀏覽代碼

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 5 年之前
父節點
當前提交
24a2f4f300
共有 1 個文件被更改,包括 1 次插入1 次删除
  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,
 	strncpy(s_test_directory,
 	        path,
 	        path,
-	        sizeof(s_test_directory) / sizeof(s_test_directory[0]));
+	        sizeof(s_test_directory) - 1);
 }
 }