Skip to content

Commit 8236cc3

Browse files
authored
Merge pull request #1132 from CrowCpp/1127-small-oob-read-in-qs_scanvalue-when-the-key-is-not-found
fix for issue #1127 Small oob read in `qs_scanvalue` when the key is not found - increment qs only if '&' was found
2 parents 7e41d9f + 2e0f203 commit 8236cc3

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

include/crow/query_string.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,28 +245,28 @@ inline std::unique_ptr<std::pair<std::string, std::string>> qs_dict_name2kv(cons
245245

246246
inline char * qs_scanvalue(const char * key, const char * qs, char * val, size_t val_len)
247247
{
248-
size_t i, key_len;
249-
const char * tmp;
248+
const char * tmp= strchr(qs, '?');
250249

251250
// find the beginning of the k/v substrings
252-
if ( (tmp = strchr(qs, '?')) != NULL )
251+
if ( tmp != nullptr )
253252
qs = tmp + 1;
254253

255-
key_len = strlen(key);
256-
while(qs[0] != '#' && qs[0] != '\0')
254+
const size_t key_len = strlen(key);
255+
while(*qs != '#' && *qs != '\0')
257256
{
258257
if ( qs_strncmp(key, qs, key_len) == 0 )
259258
break;
260-
qs += strcspn(qs, "&") + 1;
259+
qs += strcspn(qs, "&");
260+
if (*qs=='&') qs++;
261261
}
262262

263-
if ( qs[0] == '\0' ) return NULL;
263+
if ( qs[0] == '\0' ) return nullptr;
264264

265265
qs += strcspn(qs, "=&#");
266266
if ( qs[0] == '=' )
267267
{
268268
qs++;
269-
i = strcspn(qs, "&=#");
269+
size_t i = strcspn(qs, "&=#");
270270
#ifdef _MSC_VER
271271
strncpy_s(val, val_len, qs, (val_len - 1)<(i + 1) ? (val_len - 1) : (i + 1));
272272
#else

0 commit comments

Comments
 (0)