Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jan 2010 14:30:30 +0000 (UTC)
From:      Colin Percival <cperciva@FreeBSD.org>
To:        cvs-src-old@freebsd.org
Subject:   cvs commit: src/lib/libc/stdio fread.c fwrite.c
Message-ID:  <201001101430.o0AEUfMQ069359@repoman.freebsd.org>

index | next in thread | raw e-mail

cperciva    2010-01-10 14:30:30 UTC

  FreeBSD src repository

  Modified files:
    lib/libc/stdio       fread.c fwrite.c 
  Log:
  SVN rev 201999 on 2010-01-10 14:30:30Z by cperciva
  
  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
  
  Revision  Changes    Path
  1.17      +22 -1     src/lib/libc/stdio/fread.c
  1.14      +18 -2     src/lib/libc/stdio/fwrite.c


help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001101430.o0AEUfMQ069359>