diff options
| author | Roland McGrath <[email protected]> | 2010-06-30 11:57:19 -0700 |
|---|---|---|
| committer | Roland McGrath <[email protected]> | 2010-06-30 11:57:19 -0700 |
| commit | b645803e9c200ee176432d59ffc0e27769621500 (patch) | |
| tree | 46afb031c7e259ae654a47a41a7a31122ae6920f /src/strings.c | |
| parent | 82a6336fd0b128ee213e03f4e35c73bee91d5c01 (diff) | |
strings: Fix brainos in non-mmap case.
Diffstat (limited to 'src/strings.c')
| -rw-r--r-- | src/strings.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/strings.c b/src/strings.c index b69f2ad2..21380981 100644 --- a/src/strings.c +++ b/src/strings.c @@ -1,5 +1,5 @@ /* Print the strings of printable characters in files. - Copyright (C) 2005, 2006, 2007, 2009 Red Hat, Inc. + Copyright (C) 2005-2010 Red Hat, Inc. This file is part of Red Hat elfutils. Written by Ulrich Drepper <[email protected]>, 2005. @@ -169,9 +169,9 @@ main (int argc, char *argv[]) if (remaining == argc) /* We read from standard input. This we cannot do for a structured file. */ - result = read_fd (STDOUT_FILENO, + result = read_fd (STDIN_FILENO, print_file_name ? "{standard input}" : NULL, - fstat64 (STDOUT_FILENO, &st) == 0 + (fstat64 (STDIN_FILENO, &st) == 0 && S_ISREG (st.st_mode)) ? st.st_size : INT64_C (0x7fffffffffffffff)); else do @@ -548,17 +548,17 @@ read_block_no_mmap (int fd, const char *fname, off64_t from, off64_t fdlen) size_t nb = (size_t) n + ntrailer; if (nb >= min_len_bytes) { - /* We only use complete charactesr. */ + /* We only use complete characters. */ nb &= ~(bytes_per_char - 1); process_chunk (fname, buf, from + nb, nb, &unprinted); - /* If the last bytes of the buffer (module the character + /* If the last bytes of the buffer (modulo the character size) have been printed we are not copying them. */ size_t to_keep = unprinted != NULL ? 0 : min_len_bytes; - memmove (buf, buf + nb - to_keep, to_keep + nb); - ntrailer = to_keep + nb; + memmove (buf, buf + nb - to_keep, to_keep); + ntrailer = to_keep; from += nb; } else @@ -578,8 +578,6 @@ read_block_no_mmap (int fd, const char *fname, off64_t from, off64_t fdlen) static int read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) { - assert ((off64_t) min_len_bytes < fdlen); - if (elfmap == NULL) { /* We need a completely new mapping. */ @@ -597,12 +595,14 @@ read_block (int fd, const char *fname, off64_t fdlen, off64_t from, off64_t to) read pointer. */ // XXX Eventually add flag which avoids this if the position // XXX is known to match. - if (lseek64 (fd, from, SEEK_SET) != from) + if (from != 0 && lseek64 (fd, from, SEEK_SET) != from) error (EXIT_FAILURE, errno, gettext ("lseek64 failed")); return read_block_no_mmap (fd, fname, from, to - from); } + assert ((off64_t) min_len_bytes < fdlen); + if (to < (off64_t) elfmap_off || from > (off64_t) (elfmap_off + elfmap_size)) { /* The existing mapping cannot fit at all. Map the new area. |
