aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/regex
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2010-01-10 14:30:30 +0000
committerColin Percival <cperciva@FreeBSD.org>2010-01-10 14:30:30 +0000
commitc6a96a84419241bb3929c780799d96fe34b39472 (patch)
treee83a1bc4cb465b204318f65cb4f56fac5a48eddf /lib/libc/regex
parent3c20163a70a8c484fc00cdd20af36f569945fa5f (diff)
downloadsrc-c6a96a84419241bb3929c780799d96fe34b39472.tar.gz
src-c6a96a84419241bb3929c780799d96fe34b39472.zip
Give a less silly response to a silly request.
Prior to this commit, fread/fwrite calls with size * nmemb > SIZE_MAX were handled by reading or writing (size_t)(size * nmemb) bytes; for example, on 32-bit platforms, fread(ptr, 641, 6700417, f) would read 1 byte and indicate that the requested 6700417 blocks had been read. This commit adds a check for such integer overflows, and treats them as if an overly large request was passed to read/write; i.e., it sets errno to EINVAL, sets the error indicator on the file, and returns a short object count (0, to be specific). The overflow check involves an integer division, so as a performance optimization we check first to see if both size and nmemb are less than 2^16; if they are, no overflow is possible and we avoid the division. We assume here that size_t is at least 32 bits; this appears to be true on all platforms FreeBSD supports. Although this commit fixes an integer overflow, it is not likely to have any security implications, since any program which would be affected by this bug fix is quite clearly already very confused. Reviewed by: kib MFC after: 1 month
Notes
Notes: svn path=/head/; revision=201999
Diffstat (limited to 'lib/libc/regex')
0 files changed, 0 insertions, 0 deletions