Skip to content

Commit

Permalink
[Secztn] Fix integer overflow check in DecodeUrl()
Browse files Browse the repository at this point in the history
Using pointers in expressions that may cause overflow leads to
undefined behavior. See also https://lwn.net/Articles/278137/
  • Loading branch information
amadio committed Nov 26, 2024
1 parent c3b458a commit 58bb106
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/XrdSecztn/XrdSecztn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <limits>

#ifndef __FreeBSD__
#include <alloca.h>
Expand Down Expand Up @@ -81,7 +82,10 @@ namespace
int DecodeUrl(const char *decode, size_t num_decode, char *out, size_t &num_out)
{
// No integer overflows please.
if ((decode + num_decode) < decode || (out + num_out) < out)
if (num_decode > std::numeric_limits<size_t>::max() - (size_t)decode)
return 1;

if (num_out > std::numeric_limits<size_t>::max() - (size_t)out)
return 1;

if (num_out < DecodeBytesNeeded(num_decode))
Expand Down

0 comments on commit 58bb106

Please sign in to comment.