Skip to content

Commit

Permalink
safety
Browse files Browse the repository at this point in the history
  • Loading branch information
vlm committed Aug 2, 2017
1 parent d88bea9 commit 39837e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions skeletons/asn_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,12 @@ typedef unsigned int uint32_t;
#endif /* __GNUC__ */
#endif /* MIN */

#ifndef SIZE_MAX
#define SIZE_MAX ULONG_MAX
#endif

#ifndef RSIZE_MAX /* C11, Annex K */
#define RSIZE_MAX (SIZE_MAX >> 1)
#endif

#endif /* ASN_SYSTEM_H */
3 changes: 3 additions & 0 deletions skeletons/oer_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ oer_fetch_length(const void *bufptr, size_t size, size_t *len_r) {
len = (len << 8) + *b;
}

if(len > RSIZE_MAX) /* A bit of C11 validation */
return -1;

*len_r = len;
assert(len_len + 1 == bend - (const uint8_t *)bufptr);
return len_len + 1;
Expand Down

0 comments on commit 39837e6

Please sign in to comment.