diff options
| author | whichbug <whichbug@github.com> | 2022-02-03 12:01:31 -0500 | 
|---|---|---|
| committer | whichbug <whichbug@github.com> | 2022-02-04 16:07:37 -0500 | 
| commit | 50044ec7fe129e0a74d3a679dd29fe17ce30e6bf (patch) | |
| tree | fa49ccb1eba50d924d4e490268fa7ef4c8c9b88f /babeld | |
| parent | a89a78236cb03a2afa6dcc4227598964e6ca1a31 (diff) | |
babeld: fix #10487 by adding a check on packet length
The body length of a packet should satisfy the condition:
packetlen >= bodylen + 4. Otherwise, heap overflows may happen.
Signed-off-by: whichbug <whichbug@github.com>
Diffstat (limited to 'babeld')
| -rw-r--r-- | babeld/message.c | 13 | 
1 files changed, 6 insertions, 7 deletions
diff --git a/babeld/message.c b/babeld/message.c index 5c2e29d8b3..3a29b6a60f 100644 --- a/babeld/message.c +++ b/babeld/message.c @@ -288,13 +288,18 @@ channels_len(unsigned char *channels)  static int  babel_packet_examin(const unsigned char *packet, int packetlen)  { -    unsigned i = 0, bodylen; +    int i = 0, bodylen;      const unsigned char *message;      unsigned char type, len;      if(packetlen < 4 || packet[0] != 42 || packet[1] != 2)          return 1;      DO_NTOHS(bodylen, packet + 2); +    if(bodylen + 4 > packetlen) { +        debugf(BABEL_DEBUG_COMMON, "Received truncated packet (%d + 4 > %d).", +                 bodylen, packetlen); +        return 1; +    }      while (i < bodylen){          message = packet + 4 + i;          type = message[0]; @@ -366,12 +371,6 @@ parse_packet(const unsigned char *from, struct interface *ifp,      DO_NTOHS(bodylen, packet + 2); -    if(bodylen + 4 > packetlen) { -        flog_err(EC_BABEL_PACKET, "Received truncated packet (%d + 4 > %d).", -                 bodylen, packetlen); -        bodylen = packetlen - 4; -    } -      i = 0;      while(i < bodylen) {          message = packet + 4 + i;  | 
