Skip to content

Commit 2c4fd67

Browse files
authored
Merge pull request #1595 from bratpiorka/rrudnick_fix_coverity
Enhance size parsing in MAP_SYNC devdax test
2 parents a12247b + 4d1975c commit 2c4fd67

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

test/provider_devdax_memory.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
// Copyright (C) 2024-2025 Intel Corporation
1+
// Copyright (C) 2024-2026 Intel Corporation
22
// Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

55
#ifndef _WIN32
66
#include <fcntl.h>
7+
#include <limits.h>
78
#include <sys/stat.h>
89
#include <sys/types.h>
910
#endif
1011

12+
#include <cerrno>
13+
1114
#include <umf/experimental/ctl.h>
1215
#include <umf/memory_provider.h>
1316
#include <umf/providers/provider_devdax_memory.h>
@@ -132,7 +135,17 @@ TEST_F(test, test_if_mapped_with_MAP_SYNC) {
132135
GTEST_SKIP() << "Test skipped, UMF_TESTS_DEVDAX_SIZE is not set";
133136
}
134137

135-
size_t size = atol(size_str);
138+
// Parse the size string to an unsigned long long and check for errors
139+
char *end = nullptr;
140+
errno = 0;
141+
unsigned long long parsed_size = strtoull(size_str, &end, 10);
142+
ASSERT_EQ(errno, 0);
143+
ASSERT_NE(end, size_str);
144+
ASSERT_EQ(*end, '\0');
145+
146+
ASSERT_GT(parsed_size, 0);
147+
ASSERT_LE(parsed_size, static_cast<unsigned long long>(SSIZE_MAX));
148+
size_t size = static_cast<size_t>(parsed_size);
136149
umf_devdax_memory_provider_params_handle_t params = NULL;
137150
umf_result = umfDevDaxMemoryProviderParamsCreate(path, size, &params);
138151
ASSERT_EQ(umf_result, UMF_RESULT_SUCCESS);

0 commit comments

Comments
 (0)