diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command_match.c | 2 | ||||
| -rw-r--r-- | lib/skiplist.c | 4 | ||||
| -rw-r--r-- | lib/stream.c | 4 | ||||
| -rw-r--r-- | lib/stream.h | 18 |
4 files changed, 23 insertions, 5 deletions
diff --git a/lib/command_match.c b/lib/command_match.c index ad3ec2492e..62e7c63068 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -28,7 +28,7 @@ DEFINE_MTYPE_STATIC(LIB, CMD_MATCHSTACK, "Command Match Stack") -#define MAXDEPTH 64 +#define MAXDEPTH 256 #ifdef TRACE_MATCHER #define TM 1 diff --git a/lib/skiplist.c b/lib/skiplist.c index 7acc78f563..a546bb44c0 100644 --- a/lib/skiplist.c +++ b/lib/skiplist.c @@ -593,8 +593,8 @@ static void *scramble(int i) { uintptr_t result; - result = (i & 0xff) << 24; - result |= (i >> 8); + result = (unsigned)(i & 0xff) << 24; + result |= (unsigned)i >> 8; return (void *)result; } diff --git a/lib/stream.c b/lib/stream.c index 577fa257df..f88689f677 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -394,7 +394,7 @@ u_int32_t stream_getl_from(struct stream *s, size_t from) return 0; } - l = s->data[from++] << 24; + l = (unsigned)(s->data[from++]) << 24; l |= s->data[from++] << 16; l |= s->data[from++] << 8; l |= s->data[from]; @@ -426,7 +426,7 @@ u_int32_t stream_getl(struct stream *s) return 0; } - l = s->data[s->getp++] << 24; + l = (unsigned)(s->data[s->getp++]) << 24; l |= s->data[s->getp++] << 16; l |= s->data[s->getp++] << 8; l |= s->data[s->getp++]; diff --git a/lib/stream.h b/lib/stream.h index 33dd64c4a3..7dcdca69f6 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -239,4 +239,22 @@ extern struct stream *stream_fifo_head(struct stream_fifo *fifo); extern void stream_fifo_clean(struct stream_fifo *fifo); extern void stream_fifo_free(struct stream_fifo *fifo); +/* This is here because "<< 24" is particularly problematic in C. + * This is because the left operand of << is integer-promoted, which means + * an uint8_t gets converted into a *signed* int. Shifting into the sign + * bit of a signed int is theoretically undefined behaviour, so - the left + * operand needs to be cast to unsigned. + * + * This is not a problem for 16- or 8-bit values (they don't reach the sign + * bit), for 64-bit values (you need to cast them anyway), and neither for + * encoding (because it's downcasted.) + */ +static inline uint8_t *ptr_get_be32(uint8_t *ptr, uint32_t *out) +{ + uint32_t tmp; + memcpy(&tmp, ptr, sizeof(tmp)); + *out = ntohl(tmp); + return ptr + 4; +} + #endif /* _ZEBRA_STREAM_H */ |
