<div dir="ltr">i saw you complaining about memory errors on your blog, talking about writing your own infrastructure... why not just `export ASAN=1`?<div><br></div><div>/tmp$ git clone <a href="https://github.com/landley/toybox.git">https://github.com/landley/toybox.git</a> toybox<br>Cloning into 'toybox'...<br>remote: Enumerating objects: 25806, done.<br>remote: Counting objects: 100% (2750/2750), done.<br>remote: Compressing objects: 100% (905/905), done.<br>remote: Total 25806 (delta 1933), reused 2165 (delta 1833), pack-reused 23056<br>Receiving objects: 100% (25806/25806), 11.12 MiB | 7.71 MiB/s, done.<br>Resolving deltas: 100% (18574/18574), done.<br>/tmp$ cd toybox/<br>/tmp/toybox$ vi .config <br>/tmp/toybox$ export ASAN=1<br>/tmp/toybox$ make<br>scripts/make.sh<br><br>warning: using unfinished code from toys/pending<br>generated/{flags.h}<br>Compile toybox......................................................................................................................toys/pending/diff.c: In function 'do_diff':<br>toys/pending/diff.c:621:14: warning: variable 'b' set but not used [-Wunused-but-set-variable]<br>  621 |       long a,b;<br>      |              ^<br>......................toys/posix/grep.c: In function 'do_grep':<br>toys/posix/grep.c:208:26: warning: 'regexec0' accessing 8 bytes in a region of size 4 [-Wstringop-overflow=]<br>  208 |               shoe->rc = regexec0(&shoe->r, start, ulen-(start-line), 1,<br>      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>  209 |                                   &shoe->m, start==line ? 0 : REG_NOTBOL);<br>      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>toys/posix/grep.c:208:26: note: referencing argument 5 of type 'regmatch_t *'<br>In file included from ./toys.h:70,<br>                 from toys/posix/grep.c:68:<br>./lib/lib.h:272:5: note: in a call to function 'regexec0'<br>  272 | int regexec0(regex_t *preg, char *string, long len, int nmatch,<br>      |     ^~~~~~~~<br>.....toys/pending/diff.c: At top level:<br>cc1: note: unrecognized command-line option '-Wno-string-plus-int' may have been intended to silence earlier diagnostics<br>.........toys/posix/grep.c: At top level:<br>cc1: note: unrecognized command-line option '-Wno-string-plus-int' may have been intended to silence earlier diagnostics<br>............................<br>/tmp/toybox$ seq 1 100000 > one<br>/tmp/toybox$ seq 1 4 100000 > two<br>/tmp/toybox$ ./toybox diff -u one two > /dev/null<br>=================================================================<br>==2475581==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000000f at pc 0x7fa9e6019ab7 bp 0x7fffa8f4a9b0 sp 0x7fffa8f4a160<br>READ of size 1 at 0x60200000000f thread T0<br>    #0 0x7fa9e6019ab6 in printf_common ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:553<br>    #1 0x7fa9e601a1ca in __interceptor_vprintf ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1660<br>    #2 0x7fa9e601a2a6 in __interceptor_printf ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:1718<br>    #3 0x560bf7b183d7 in show_label toys/pending/diff.c:548<br><br>0x60200000000f is located 1 bytes to the left of 4-byte region [0x602000000010,0x602000000014)<br>allocated by thread T0 here:<br>    #0 0x7fa9e606c7cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145<br>    #1 0x560bf7ad1bbb in xmalloc lib/xwrap.c:71<br>    #2 0x560bf7b182af in quote_filename toys/pending/diff.c:537<br>    #3 0x560bf7b183a4 in show_label toys/pending/diff.c:547<br>    #4 0x560bf7b190ed in do_diff toys/pending/diff.c:610<br>    #5 0x560bf7b1b258 in diff_main toys/pending/diff.c:837<br>    #6 0x560bf7ad68c0 in toy_exec_which /tmp/toybox/main.c:220<br>    #7 0x560bf7ad6ad6 in toybox_main /tmp/toybox/main.c:246<br>    #8 0x560bf7ad68c0 in toy_exec_which /tmp/toybox/main.c:220<br>    #9 0x560bf7ad6ad6 in toybox_main /tmp/toybox/main.c:246<br>    #10 0x560bf7abe776 in main /tmp/toybox/main.c:293<br>    #11 0x7fa9e5caa7fc in __libc_start_main ../csu/libc-start.c:332<br><br>SUMMARY: AddressSanitizer: heap-buffer-overflow ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors_format.inc:553 in printf_common<br>Shadow bytes around the buggy address:<br>  0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<br>  0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<br>  0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<br>  0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<br>  0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00<br>=>0x0c047fff8000: fa[fa]04 fa fa fa 00 03 fa fa 00 03 fa fa fd fd<br>  0x0c047fff8010: fa fa 00 07 fa fa fa fa fa fa fa fa fa fa fa fa<br>  0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa<br>  0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa<br>  0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa<br>  0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa<br>Shadow byte legend (one shadow byte represents 8 application bytes):<br>  Addressable:           00<br>  Partially addressable: 01 02 03 04 05 06 07 <br>  Heap left redzone:       fa<br>  Freed heap region:       fd<br>  Stack left redzone:      f1<br>  Stack mid redzone:       f2<br>  Stack right redzone:     f3<br>  Stack after return:      f5<br>  Stack use after scope:   f8<br>  Global redzone:          f9<br>  Global init order:       f6<br>  Poisoned by user:        f7<br>  Container overflow:      fc<br>  Array cookie:            ac<br>  Intra object redzone:    bb<br>  ASan internal:           fe<br>  Left alloca redzone:     ca<br>  Right alloca redzone:    cb<br>  Shadow gap:              cc<br>==2475581==ABORTING<br>/tmp/toybox$ <br></div><div><br></div></div>