grep segfaults when you ask for context
You can specify the number of surrounding lines that should also be printed out for each match (with -B NUM, -C NUM or just -NUM) as context, but if you do grep with core dump. This is because the check that tests whether the buffer needs to grow is faulty. Due to missing parenthesis it causes the buffer to balloon prematurely and then later not grow when the buffer is no longer big enough, causing a buffer overflow. It's also possible that after growing it still won't be big enough so we need to do the check in a loop.
Updated by Andrew Stormont over 2 years ago
# pstack /var/cores/core.grep.21164 core '/var/cores/core.grep.21164' of 21164: /tmp/grep -2 hello /var/adm/messages fee361a0 memcpy (3, 8047e3f, 0, feeca983, 8047e3f, 0) + 160 08053935 process_file (8047e3f, 0, fedd2a00, feec9d24, fef447cc, 0) + 77 08053a9e process_path (8047e3f, 8047d50, 8054797, d7acdc4, 4b, 8050c98) + 10c 08054335 main (3, 8047d50, 8047d64, 8051bc3, 0, 0) + 7fc 08051be8 _start_crt (4, 8047d50, fefcf323, 0, 0, 0) + 97 08051aba _start (4, 8047e2c, 8047e39, 8047e3f, 0, 0) + 1a
Updated by Electric Monk over 2 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
commit d9241f995480d9097812b34500484c0fff9d7528 Author: Andrew Stormont <firstname.lastname@example.org> Date: 2018-06-01T18:03:01.000Z 9552 grep segfaults when you ask for context Reviewed by: Yuri Pankov <email@example.com> Reviewed by: Toomas Soome <firstname.lastname@example.org> Reviewed by: Andy Fiddaman <email@example.com> Approved by: Robert Mustacchi <firstname.lastname@example.org>