Changeset 4790


Ignore:
Timestamp:
Sep 23, 2015, 2:36:59 PM (3 years ago)
Author:
hongpum
Message:

Fixed a remaining issue (out of bound) in CL4788

If the file ends with a CR, we will try to access one more byte past the
buffer to look for an LF. Since we stop mmaping sentinel bytes, this byte is
now out of the mapped memory region and won't cause SIGBUS, but it's now a
"normal" out-of-bound case and may read garbage or cause segfault.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/do_grep.cpp

    r4788 r4790  
    9999                line_end--;
    100100            } else if (end_byte == 0x0D) {
    101                 // Check for line_end on first byte of CRLF;  note that to safely
    102                 // access past line_end, even at the end of buffer, we require the
    103                 // MMAP_SENTINEL_BYTES >= 1.
    104                 if (buffer[line_end + 1] == 0x0A) {
     101                // Check for line_end on first byte of CRLF;  note that we don't
     102                // want to access past the end of buffer.
     103                if ((buffer + line_end + 1 < mFileBuffer + mFileSize) && (buffer[line_end + 1] == 0x0A)) {
    105104                    // Found CRLF; preserve both bytes.
    106105                    line_end++;
Note: See TracChangeset for help on using the changeset viewer.