Skip to content

Commit

Permalink
CBL-5507: Fix index-past-end in CookieStore (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
callumbirks authored Apr 3, 2024
1 parent 26f530f commit d2d92c5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Networking/HTTP/CookieStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ namespace litecore::net {
if ( expires == 0 ) { return; }
}
} else if ( key == "max-age" ) {
char* valEnd = &val[val.size()];
long maxAge = strtol(&val[0], &valEnd, 10);
if ( valEnd != &val[val.size()] || val.empty() ) {
size_t pos{};
try {
long maxAge = stol(val, &pos);
if ( pos != val.length() || val.empty() ) {
Warn("Couldn't parse Max-Age in cookie");
return;
}
expires = created + maxAge;
} catch ( std::exception& e ) {
Warn("Couldn't parse Max-Age in cookie");
return;
}
expires = created + maxAge;
}
}

Expand Down

0 comments on commit d2d92c5

Please sign in to comment.