Opened 13 months ago

Closed 8 weeks 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@…



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


boost thrift gtest

and then run:

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.


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@… 13 months ago.
source package

Download all attachments as: .zip

Change History (4)

Changed 13 months ago by chrisfriedt@…

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

source package

comment:1 Changed 13 months ago by anonymous

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

comment:2 Changed 13 months ago by Nikita Kniazev <nok.raven@…>

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 Changed 8 weeks ago by Joel de Guzman

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