From 61f3298ef20c6a26e9206621a6c79e89b951b1e9 Mon Sep 17 00:00:00 2001 From: Ilan Truanovsky Date: Mon, 6 Feb 2023 07:01:26 -0800 Subject: [PATCH] Fix Coverity `OVERRUN` error for `acl_hal_test.cpp` A function was being passed in the wrong length of a pointer. Fixes: ``` test/acl_hal_test.cpp:362:3: Type: Out-of-bounds access (OVERRUN) test/acl_hal_test.cpp:303:3: 1. path: Condition "acl_set_hal(&simple_hal)", taking false branch. test/acl_hal_test.cpp:303:3: 2. path: Condition "!Utest::getCurrent()->assertTrue(acl_set_hal(&simple_hal), "acl_set_hal(&simple_hal)", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 303)", taking true branch. test/acl_hal_test.cpp:308:3: 3. path: Condition "acl_debug_env", taking true branch. test/acl_hal_test.cpp:308:3: 4. path: Condition "!Utest::getCurrent()->assertTrue(acl_debug_env, "acl_debug_env", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 308)", taking true branch. test/acl_hal_test.cpp:311:3: 5. path: Condition "0 != debug_mode", taking false branch. test/acl_hal_test.cpp:313:3: 6. path: Condition "0 != acl_print_debug_msg("some text")", taking true branch. test/acl_hal_test.cpp:313:3: 7. path: Falling through to end of if statement. test/acl_hal_test.cpp:314:3: 8. path: Condition "0 != acl_print_debug_msg("")", taking true branch. test/acl_hal_test.cpp:314:3: 9. path: Falling through to end of if statement. test/acl_hal_test.cpp:319:3: 10. path: Condition "acl_debug_env", taking true branch. test/acl_hal_test.cpp:319:3: 11. path: Condition "!Utest::getCurrent()->assertTrue(acl_debug_env, "acl_debug_env", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 319)", taking true branch. test/acl_hal_test.cpp:321:3: 12. path: Condition "4 != debug_mode", taking true branch. test/acl_hal_test.cpp:321:3: 13. path: Falling through to end of if statement. test/acl_hal_test.cpp:324:3: 14. path: Condition "acl_debug_env", taking true branch. test/acl_hal_test.cpp:324:3: 15. path: Condition "!Utest::getCurrent()->assertTrue(acl_debug_env, "acl_debug_env", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 324)", taking true branch. test/acl_hal_test.cpp:326:3: 16. path: Condition "3 != debug_mode", taking true branch. test/acl_hal_test.cpp:326:3: 17. path: Falling through to end of if statement. test/acl_hal_test.cpp:329:3: 18. path: Condition "acl_debug_env", taking true branch. test/acl_hal_test.cpp:329:3: 19. path: Condition "!Utest::getCurrent()->assertTrue(acl_debug_env, "acl_debug_env", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 329)", taking true branch. test/acl_hal_test.cpp:331:3: 20. path: Condition "2 != debug_mode", taking true branch. test/acl_hal_test.cpp:331:3: 21. path: Falling through to end of if statement. test/acl_hal_test.cpp:332:3: 22. path: Condition "22UL /* sizeof (test_str) / sizeof (test_str[0]) - 1 */ != acl_print_debug_msg(test_str)", taking true branch. test/acl_hal_test.cpp:332:3: 23. path: Falling through to end of if statement. test/acl_hal_test.cpp:336:3: 24. path: Condition "0 != acl_print_debug_msg("")", taking true branch. test/acl_hal_test.cpp:336:3: 25. path: Falling through to end of if statement. test/acl_hal_test.cpp:339:3: 26. path: Condition "acl_debug_env", taking true branch. test/acl_hal_test.cpp:339:3: 27. path: Condition "!Utest::getCurrent()->assertTrue(acl_debug_env, "acl_debug_env", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 339)", taking true branch. test/acl_hal_test.cpp:341:3: 28. path: Condition "0 != debug_mode", taking false branch. test/acl_hal_test.cpp:342:3: 29. path: Condition "0 != acl_print_debug_msg(test_str)", taking true branch. test/acl_hal_test.cpp:342:3: 30. path: Falling through to end of if statement. test/acl_hal_test.cpp:346:3: 31. path: Condition "1 != hal->query_temperature(0, &temp)", taking false branch. test/acl_hal_test.cpp:347:3: 32. path: Condition "0 != temp", taking false branch. test/acl_hal_test.cpp:353:3: 33. path: Condition "size_returned < 1024", taking true branch. test/acl_hal_test.cpp:353:3: 34. path: Condition "!Utest::getCurrent()->assertTrue(size_returned < 1024, "size_returned < BUF_SIZE", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 353)", taking true branch. test/acl_hal_test.cpp:354:3: 35. path: Condition "strcmp(name, "Test Device") == 0", taking true branch. test/acl_hal_test.cpp:354:3: 36. path: Condition "!Utest::getCurrent()->assertTrue(strcmp(name, "Test Device") == 0, "strcmp(name, \"Test Device\") == 0", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 354)", taking true branch. test/acl_hal_test.cpp:356:3: 37. path: Condition "size_returned < 1024", taking true branch. test/acl_hal_test.cpp:356:3: 38. path: Condition "!Utest::getCurrent()->assertTrue(size_returned < 1024, "size_returned < BUF_SIZE", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 356)", taking true branch. test/acl_hal_test.cpp:357:3: 39. path: Condition "strcmp(name, "Intel(R) Corporation") == 0", taking true branch. test/acl_hal_test.cpp:357:3: 40. path: Condition "!Utest::getCurrent()->assertTrue(strcmp(name, "Intel(R) Corporation") == 0, "strcmp(name, \"Intel(R) Corporation\") == 0", "/__w/fpga-runtime-for-opencl/fpga-runtime-for-opencl/test/acl_hal_test.cpp", 357)", taking true branch. test/acl_hal_test.cpp:362:3: 41. overrun-buffer-arg: Overrunning buffer pointed to by "&temp_u64" of 1 8-byte elements by passing it to a function which accesses it at element index 1 (byte offset 15) using argument "2U". (The function pointer resolves to "acl_hal_mmd_get_profile_data".) src/acl_hal_mmd.cpp:2448:3: 41.1. path: Condition "physical_device_id < num_physical_devices", taking true branch. src/acl_hal_mmd.cpp:2449:3: 41.2. access_dbuff_in_call: Calling "acl_kernel_if_get_profile_data" indexes array "data" with index "length". src/acl_kernel_if.cpp:1870:3: 41.2.1. path: Condition "length > 0", taking true branch. src/acl_kernel_if.cpp:1872:5: 41.2.2. path: Condition "kern->io.printf", taking true branch. src/acl_kernel_if.cpp:1872:5: 41.2.3. path: Condition "kern->io.debug_verbosity > 0", taking true branch. src/acl_kernel_if.cpp:1878:5: 41.2.4. path: Condition "i < length", taking true branch. src/acl_kernel_if.cpp:1878:5: 41.2.5. loop_bounded_by_parm: "length" bounds loop condition "i < length". src/acl_kernel_if.cpp:1879:7: 41.2.6. index_parm_via_loop_bound: Pointer "data" is accessed by "i", whose upper bound is "length" in loop conditional "i < length". ``` --- test/acl_hal_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/acl_hal_test.cpp b/test/acl_hal_test.cpp index 58d29b47..219367a6 100644 --- a/test/acl_hal_test.cpp +++ b/test/acl_hal_test.cpp @@ -359,7 +359,7 @@ TEST(acl_hal, debugging) { uint64_t temp_u64; // Return values in following six calls are defined by the test HAL as // 1-6, simply to verify ordering of the function pointers. - CHECK_EQUAL(1, hal->get_profile_data(0, 1, &temp_u64, 2)); + CHECK_EQUAL(1, hal->get_profile_data(0, 1, &temp_u64, 1)); CHECK_EQUAL(2, hal->reset_profile_counters(0, 1)); CHECK_EQUAL(3, hal->disable_profile_counters(0, 1)); CHECK_EQUAL(4, hal->enable_profile_counters(0, 1));