jarulraj/sqlcheck

Segfault on stdin EOF

vfaronov opened this issue · 2 comments

Ubuntu 16.04

$ ./sqlcheck <<<'select * from bar;'
-------------------------------------------------
> RISK LEVEL    :: ALL ANTI-PATTERNS
-------------------------------------------------
==================== Results ===================

-------------------------------------------------
SQL Statement: select * from bar;
(HIGH RISK) (QUERY ANTI-PATTERN) SELECT *
[Matching Expression: select *]


==================== Summary ===================
All Anti-Patterns  :: 1
>  High Risk   :: 1
>  Medium Risk :: 0
>  Low Risk    :: 0
*** Error in `./sqlcheck': free(): invalid pointer: 0x00007f0dae4d8060 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f0dadbf07e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f0dadbf937a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f0dadbfd53c]
./sqlcheck(_ZN8sqlcheck5CheckERNS_13ConfigurationE+0xae1)[0x411c91]
./sqlcheck(main+0x28)[0x40de48]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f0dadb99830]
./sqlcheck(_start+0x29)[0x40e0c9]
======= Memory map: ========
00400000-00445000 r-xp 00000000 08:04 1945                               /home/vasiliy/tmp/sqlcheck/prefix/bin/sqlcheck
00644000-00645000 r--p 00044000 08:04 1945                               /home/vasiliy/tmp/sqlcheck/prefix/bin/sqlcheck
00645000-00653000 rw-p 00045000 08:04 1945                               /home/vasiliy/tmp/sqlcheck/prefix/bin/sqlcheck
00653000-00664000 rw-p 00000000 00:00 0 
008cd000-008ff000 rw-p 00000000 00:00 0                                  [heap]
7f0da8000000-7f0da8021000 rw-p 00000000 00:00 0 
7f0da8021000-7f0dac000000 ---p 00000000 00:00 0 
7f0dad870000-7f0dad978000 r-xp 00000000 08:03 131867                     /lib/x86_64-linux-gnu/libm-2.23.so
7f0dad978000-7f0dadb77000 ---p 00108000 08:03 131867                     /lib/x86_64-linux-gnu/libm-2.23.so
7f0dadb77000-7f0dadb78000 r--p 00107000 08:03 131867                     /lib/x86_64-linux-gnu/libm-2.23.so
7f0dadb78000-7f0dadb79000 rw-p 00108000 08:03 131867                     /lib/x86_64-linux-gnu/libm-2.23.so
7f0dadb79000-7f0dadd39000 r-xp 00000000 08:03 131874                     /lib/x86_64-linux-gnu/libc-2.23.so
7f0dadd39000-7f0dadf39000 ---p 001c0000 08:03 131874                     /lib/x86_64-linux-gnu/libc-2.23.so
7f0dadf39000-7f0dadf3d000 r--p 001c0000 08:03 131874                     /lib/x86_64-linux-gnu/libc-2.23.so
7f0dadf3d000-7f0dadf3f000 rw-p 001c4000 08:03 131874                     /lib/x86_64-linux-gnu/libc-2.23.so
7f0dadf3f000-7f0dadf43000 rw-p 00000000 00:00 0 
7f0dadf43000-7f0dadf59000 r-xp 00000000 08:03 136298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f0dadf59000-7f0dae158000 ---p 00016000 08:03 136298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f0dae158000-7f0dae159000 rw-p 00015000 08:03 136298                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f0dae159000-7f0dae2cb000 r-xp 00000000 08:03 392747                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0dae2cb000-7f0dae4cb000 ---p 00172000 08:03 392747                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0dae4cb000-7f0dae4d5000 r--p 00172000 08:03 392747                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0dae4d5000-7f0dae4d7000 rw-p 0017c000 08:03 392747                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0dae4d7000-7f0dae4db000 rw-p 00000000 00:00 0 
7f0dae4db000-7f0dae501000 r-xp 00000000 08:03 131825                     /lib/x86_64-linux-gnu/ld-2.23.so
7f0dae6db000-7f0dae6e0000 rw-p 00000000 00:00 0 
7f0dae6fd000-7f0dae700000 rw-p 00000000 00:00 0 
7f0dae700000-7f0dae701000 r--p 00025000 08:03 131825                     /lib/x86_64-linux-gnu/ld-2.23.so
7f0dae701000-7f0dae702000 rw-p 00026000 08:03 131825                     /lib/x86_64-linux-gnu/ld-2.23.so
7f0dae702000-7f0dae703000 rw-p 00000000 00:00 0 
7ffd868c0000-7ffd868e1000 rw-p 00000000 00:00 0                          [stack]
7ffd86974000-7ffd86976000 r--p 00000000 00:00 0                          [vvar]
7ffd86976000-7ffd86978000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

If I run it interactively and interrupt the read, it exits silently:

$ ./sqlcheck 
-------------------------------------------------
> RISK LEVEL    :: ALL ANTI-PATTERNS
-------------------------------------------------
==================== Results ===================
select * from bar;

-------------------------------------------------
SQL Statement: select * from bar;
(HIGH RISK) (QUERY ANTI-PATTERN) SELECT *
[Matching Expression: select *]

^C

Thanks for reporting the bug. 4ecc312 should fix the segfault on stdin EOF.

./bin/sqlcheck <<< "select * from foo;"
-------------------------------------------------
> RISK LEVEL    :: ALL ANTI-PATTERNS
-------------------------------------------------
==================== Results ===================

-------------------------------------------------
SQL Statement: select * from foo;
(HIGH RISK) (QUERY ANTI-PATTERN) SELECT *
[Matching Expression: select *]

==================== Summary ===================
All Anti-Patterns  :: 1
>  High Risk   :: 1
>  Medium Risk :: 0
>  Low Risk    :: 0

If I run it interactively and interrupt the read, it exits silently.

This is the expected behavior.

Yes, fixed for me in master.