Skip to content

Commit 2cc97a4

Browse files
authored
Merge pull request #48 from olifre/fix-assert-curl-write
scitokens_internal: Fix undefined behaviour in CURL write functions.
2 parents 946df64 + 97b6e6d commit 2cc97a4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/scitokens_internal.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class SimpleCurlGet {
4646
}
4747

4848
if (m_maxbytes > 0) {
49-
m_data.reserve(std::min(m_maxbytes, 8*1024));
49+
size_t new_size = std::min(m_maxbytes, 8*1024);
50+
if (m_data.size() < new_size) {
51+
m_data.resize(new_size);
52+
}
5053
}
5154

5255
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
@@ -82,7 +85,9 @@ class SimpleCurlGet {
8285
if (myself->m_maxbytes > 0 && (new_length > static_cast<size_t>(myself->m_maxbytes))) {
8386
return 0;
8487
}
85-
myself->m_data.reserve(new_length);
88+
if (myself->m_data.size() < new_length) {
89+
myself->m_data.resize(new_length);
90+
}
8691
memcpy(&(myself->m_data[myself->m_len]), buffer, new_data);
8792
myself->m_len = new_length;
8893
return new_data;

0 commit comments

Comments
 (0)