Skip to content

Commit

Permalink
Use UINT64_MAX instead of UINT_MAX for invalid lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Feb 7, 2024
1 parent fc2b7be commit 8092c70
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/HttpParser.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Authored by Alex Hultman, 2018-2020.
* Authored by Alex Hultman, 2018-2024.
* Intellectual property of third-party.
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -199,18 +199,18 @@ struct HttpParser {
/* This guy really has only 30 bits since we reserve two highest bits to chunked encoding parsing state */
uint64_t remainingStreamingBytes = 0;

/* Returns UINT_MAX on error. Maximum 999999999 is allowed. */
/* Returns UINT64_MAX on error. Maximum 999999999 is allowed. */
static uint64_t toUnsignedInteger(std::string_view str) {
/* We assume at least 64-bit integer giving us safely 999999999999999999 (18 number of 9s) */
if (str.length() > 18) {
return UINT_MAX;
return UINT64_MAX;
}

uint64_t unsignedIntegerValue = 0;
for (char c : str) {
/* As long as the letter is 0-9 we cannot overflow. */
if (c < '0' || c > '9') {
return UINT_MAX;
return UINT64_MAX;
}
unsignedIntegerValue = unsignedIntegerValue * 10ull + ((unsigned int) c - (unsigned int) '0');
}
Expand Down Expand Up @@ -517,7 +517,7 @@ struct HttpParser {
}
} else if (contentLengthString.length()) {
remainingStreamingBytes = toUnsignedInteger(contentLengthString);
if (remainingStreamingBytes == UINT_MAX) {
if (remainingStreamingBytes == UINT64_MAX) {
/* Parser error */
return {HTTP_ERROR_400_BAD_REQUEST, FULLPTR};
}
Expand Down

0 comments on commit 8092c70

Please sign in to comment.