Skip to content

Commit

Permalink
Fix rare UB on left-shift signed int overflow
Browse files Browse the repository at this point in the history
By default, most commonly used compilers *define* some behaviour when
this overflow occurs, such that the program will continue normally,
without any negative consequences.

Severity: Minor
Fixes OSS-Fuzz#40201

(cherry picked from commit 2ba963b)
  • Loading branch information
liviuchircu committed Oct 10, 2022
1 parent 4e1363b commit 97e2885
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions parser/parse_hname2.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include "keys.h"
#include "../ut.h" /* q_memchr */

#define LOWER_BYTE(b) ((b) | 0x20)
#define LOWER_DWORD(d) ((d) | 0x20202020)
#define LOWER_BYTE(b) ((b) | 0x20U)
#define LOWER_DWORD(d) ((d) | 0x20202020U)

/*
* Skip all white-chars and return position of the first
Expand Down Expand Up @@ -88,8 +88,17 @@ static inline char* skip_ws(char* p, char *end)
#include "case_repl.h" /* Replaces */


#define READ(val) \
(*(val + 0) + (*(val + 1) << 8) + (*(val + 2) << 16) + (*(val + 3) << 24))
/*
* Read 4-bytes from memory, as an unsigned integer
* Reading byte by byte ensures that the code works also on HW which
* does not allow reading 4-bytes at once from unaligned memory position
* (Sparc for example)
*/
#define READ(addr) \
((unsigned)*((unsigned char *)addr + 0) + \
((unsigned)*((unsigned char *)addr + 1) << 8) + \
((unsigned)*((unsigned char *)addr + 2) << 16) + \
((unsigned)*((unsigned char *)addr + 3) << 24))


#define FIRST_QUATERNIONS \
Expand Down

0 comments on commit 97e2885

Please sign in to comment.