From b9600be207fa1d32e4bd4f032484cd40d177c378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 7 Jan 2020 14:44:27 -0500 Subject: [PATCH] Revert "tests/amdgpu: Fix buffer overflow (v3)" This reverts commit 680542ce086f5d0ba70331f8d350edfae20c534f. --- tests/amdgpu/ras_tests.c | 46 +++++++++++++--------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/tests/amdgpu/ras_tests.c b/tests/amdgpu/ras_tests.c index 810bf172..f745166b 100644 --- a/tests/amdgpu/ras_tests.c +++ b/tests/amdgpu/ras_tests.c @@ -30,9 +30,6 @@ #include #include #include "xf86drm.h" -#include - -#define PATH_SIZE PATH_MAX #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) @@ -501,7 +498,7 @@ static int get_file_contents(char *file, char *buf, int size); static int amdgpu_ras_lookup_id(drmDevicePtr device) { - char path[PATH_SIZE]; + char path[1024]; char str[128]; drmPciBusInfo info; int i; @@ -510,7 +507,7 @@ static int amdgpu_ras_lookup_id(drmDevicePtr device) for (i = 0; i < MAX_CARDS_SUPPORTED; i++) { memset(str, 0, sizeof(str)); memset(&info, 0, sizeof(info)); - snprintf(path, PATH_SIZE, "/sys/kernel/debug/dri/%d/name", i); + sprintf(path, "/sys/kernel/debug/dri/%d/name", i); if (get_file_contents(path, str, sizeof(str)) <= 0) continue; @@ -528,16 +525,16 @@ static int amdgpu_ras_lookup_id(drmDevicePtr device) //helpers static int test_card; -static char sysfs_path[PATH_SIZE]; -static char debugfs_path[PATH_SIZE]; +static char sysfs_path[1024]; +static char debugfs_path[1024]; static uint32_t ras_mask; static amdgpu_device_handle device_handle; static void set_test_card(int card) { test_card = card; - snprintf(sysfs_path, PATH_SIZE, "/sys/class/drm/card%d/device/ras/", devices[card].id); - snprintf(debugfs_path, PATH_SIZE, "/sys/kernel/debug/dri/%d/ras/", devices[card].id); + sprintf(sysfs_path, "/sys/class/drm/card%d/device/ras/", devices[card].id); + sprintf(debugfs_path, "/sys/kernel/debug/dri/%d/ras/", devices[card].id); ras_mask = devices[card].capability; device_handle = devices[card].device_handle; ras_block_mask_inject = devices[card].test_mask.inject_mask; @@ -608,11 +605,10 @@ static int amdgpu_ras_is_feature_supported(enum amdgpu_ras_block block) static int amdgpu_ras_invoke(struct ras_debug_if *data) { - char path[PATH_SIZE]; + char path[1024]; int ret; - snprintf(path, sizeof(path), "%s", get_ras_debugfs_root()); - strncat(path, "ras_ctrl", sizeof(path) - strlen(path)); + sprintf(path, "%s%s", get_ras_debugfs_root(), "ras_ctrl"); ret = set_file_contents(path, (char *)data, sizeof(*data)) - sizeof(*data); @@ -623,16 +619,14 @@ static int amdgpu_ras_query_err_count(enum amdgpu_ras_block block, unsigned long *ue, unsigned long *ce) { char buf[64]; - char name[PATH_SIZE]; + char name[1024]; *ue = *ce = 0; if (amdgpu_ras_is_feature_supported(block) <= 0) return -1; - snprintf(name, sizeof(name), "%s", get_ras_sysfs_root()); - strncat(name, ras_block_str(block), sizeof(name) - strlen(name)); - strncat(name, "_err_count", sizeof(name) - strlen(name)); + sprintf(name, "%s%s%s", get_ras_sysfs_root(), ras_block_str(block), "_err_count"); if (is_file_ok(name, O_RDONLY)) return 0; @@ -843,7 +837,7 @@ static void amdgpu_ras_basic_test(void) int i; int j; uint32_t features; - char path[PATH_SIZE]; + char path[1024]; ret = is_file_ok("/sys/module/amdgpu/parameters/ras_mask", O_RDONLY); CU_ASSERT_EQUAL(ret, 0); @@ -855,15 +849,11 @@ static void amdgpu_ras_basic_test(void) sizeof(features), &features); CU_ASSERT_EQUAL(ret, 0); - snprintf(path, sizeof(path), "%s", get_ras_debugfs_root()); - strncat(path, "ras_ctrl", sizeof(path) - strlen(path)); - + sprintf(path, "%s%s", get_ras_debugfs_root(), "ras_ctrl"); ret = is_file_ok(path, O_WRONLY); CU_ASSERT_EQUAL(ret, 0); - snprintf(path, sizeof(path), "%s", get_ras_sysfs_root()); - strncat(path, "features", sizeof(path) - strlen(path)); - + sprintf(path, "%s%s", get_ras_sysfs_root(), "features"); ret = is_file_ok(path, O_RDONLY); CU_ASSERT_EQUAL(ret, 0); @@ -875,17 +865,11 @@ static void amdgpu_ras_basic_test(void) if (!((1 << j) & ras_block_mask_basic)) continue; - snprintf(path, sizeof(path), "%s", get_ras_sysfs_root()); - strncat(path, ras_block_str(j), sizeof(path) - strlen(path)); - strncat(path, "_err_count", sizeof(path) - strlen(path)); - + sprintf(path, "%s%s%s", get_ras_sysfs_root(), ras_block_str(j), "_err_count"); ret = is_file_ok(path, O_RDONLY); CU_ASSERT_EQUAL(ret, 0); - snprintf(path, sizeof(path), "%s", get_ras_debugfs_root()); - strncat(path, ras_block_str(j), sizeof(path) - strlen(path)); - strncat(path, "_err_inject", sizeof(path) - strlen(path)); - + sprintf(path, "%s%s%s", get_ras_debugfs_root(), ras_block_str(j), "_err_inject"); ret = is_file_ok(path, O_WRONLY); CU_ASSERT_EQUAL(ret, 0); }