Opened 5 years ago

Closed 4 years ago

#13370 closed Bugs (fixed)

Qi: Stack Smash with BOOST_SPIRIT_DEBUG defined

Reported by: chrisfriedt@… Owned by: Joel de Guzman
Milestone: To Be Determined Component: spirit
Version: Boost 1.65.0 Severity: Problem
Keywords: Cc: nok.raven@…

Description

Hi,

I think I've found some code that touches on a boost::spirit soft-spot that causes a stack overflow when BOOST_SPIRIT_DEBUG is defined, but when debug is not defined, just does not work, *specifically* on Linux.

I don't pretend to know why it happens, but it works perfectly well on Mac OS X. The only thing I know is that a stack smash is reported by GCC after boost::spirit::qi::parse() is called.

I have this body of code that uses boost::spirit and thrift. I'm using TDD with gtest and developing primarily on Mac OS X. Recently, I added CI using GitLab and the Docker runner, so the testsuites are being run in a pseudo-GNU / Linux environment, but then I also tried it in a Linux VM with the same results, so it's definitely somehow related to Linux. I even tried compiling with clang under Linux, with the same results.

Sorry for submitting my whole project source, but this is the only way I've been able to trigger it reliably. To build the code

install:

boost thrift gtest

and then run:

sh autogen.sh ./configure --enable-debug make ./example/trigger_boost_stack_smash

It should be reproducible (i.e. the stack will be smashed) on Linux, but not on Mac OS X.

Also, if you remove --enable-debug, clean, and rebuild, then the stack will not be smashed, but the parser will fail under Linux, but not Mac OS X.

The listing named below is an example program that triggers the smashed stack. I've reproduced this with GCC versions as old as 4.6 and as recent as 7.2 and have tried it with boost versions 1.58 and 1.65.1 . The thrift version I'm using is 0.11.0.

example/trigger_boost_stack_smash.cpp

The following two named test suites fail under Linux but pass under Mac OS X.

test/test_set_thread.cpp test/test_report_target_status.cpp

My code is still pre-alpha, so I haven't released it at all yet... but you might guess it's an Apache Thrift interface to GDB's RSP.

I might not have written the best boost::spirit parsers, but regardless, the behaviour should be similar across different compilers and OS's.

Please let me know if I can help isolate the problem. I have tried a ton of things, including valgrind, and just have no idea.

Also, I'm sure that my code is horrible. Please don't judge me, but feel free to offer better suggestions (using boost::spirit) that do not trigger stack smashes :-)

If anyone is able to *not* reproduce the stack smash using Linux, I would also be very curious to hear back about it.

Attachments (1)

gdb-rsp-20171230.tar.gz (56.7 KB ) - added by chrisfriedt@… 5 years ago.
source package

Download all attachments as: .zip

Change History (4)

by chrisfriedt@…, 5 years ago

Attachment: gdb-rsp-20171230.tar.gz added

source package

comment:1 by anonymous, 5 years ago

Gah... nevermind. I just did a fresh build on Mac OS X and the same problems are happening there now.

comment:2 by Nikita Kniazev <nok.raven@…>, 5 years ago

Cc: nok.raven@… added
Summary: Boost Spirit Stack Smash with BOOST_SPIRIT_DEBUG definedQi: Stack Smash with BOOST_SPIRIT_DEBUG defined

Boost periodically run tests with ASAN/UBSAN and I did not see problems. Maybe the bug in your code but not in Spirit. Try to run ASAN (do not forget to enable -fsanitize-address-use-after-scope) on your project.

comment:3 by Joel de Guzman, 4 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.