pocoproject / poco

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems.
https://pocoproject.org
Other
8.33k stars 2.15k forks source link

adding DOMParser to code leads to stack smashing #4060

Open omerbrandis opened 1 year ago

omerbrandis commented 1 year ago

hello

these are my first steps with Poco::XML I'm trying to follow the tutorial presentations to parse an xml string. i'm currently using poco version 1.11.

simply adding "Poco::XML::DOMParser parser;" to a class method, leads to a stack smashing crash during the function's return. in other words the function ends with Poco::XML::DOMParser parser; return (myStruct);

and the caller : returnStruct = myFunction; std::cout<< "after call" << std::endl;

on execution : does not print out "after call". ( when i remove the definition of the dom parser, the return works as expected ).

i do get :
stack smashing detected : ./PocoWebServer terminated Aborted (core dumped)

here's the stack trace: Program terminated with signal SIGABRT, Aborted.

0 0x00007f897cc52428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54

54 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. [Current thread is 1 (Thread 0x7f897b9b6700 (LWP 6616))] (gdb) bt

0 0x00007f897cc52428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54

1 0x00007f897cc5402a in __GI_abort () at abort.c:89

2 0x00007f897cc947ea in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7f897cdac49f " %s : %s terminated\n") at ../sysdeps/posix/libc_fatal.c:175

3 0x00007f897cd3615c in __GI___fortify_fail (msg=, msg@entry=0x7f897cdac481 "stack smashing detected") at fortify_fail.c:37

4 0x00007f897cd36100 in __stack_chk_fail () at stack_chk_fail.c:28

5 0x000000000047f3f9 in ServeSearchRequestHandler::myfunction() ()

6 0x000000000047b32c in ServeSearchRequestHandler::handleRequest(Poco::Net::HTTPServerRequest&, Poco::Net::HTTPServerResponse&) ()

7 0x00007f897ddd5ba7 in Poco::Net::HTTPServerConnection::run() () at /home/omerbrandis/ffrobotics/poco-1.11.0-all/Net/src/HTTPServerConnection.cpp:85

8 0x00007f897ddf2957 in Poco::Net::TCPServerConnection::start() () at /home/omerbrandis/ffrobotics/poco-1.11.0-all/Net/src/TCPServerConnection.cpp:43

9 0x00007f897dde0a36 in Poco::Net::TCPServerDispatcher::run() () at /home/omerbrandis/ffrobotics/poco-1.11.0-all/Net/src/TCPServerDispatcher.cpp:119

10 0x00007f897e3c38af in Poco::PooledThread::run() () at /home/omerbrandis/ffrobotics/poco-1.11.0-all/Foundation/src/ThreadPool.cpp:199

11 0x00007f897e41cef9 in Poco::ThreadImpl::runnableEntry(void*) () at /home/omerbrandis/ffrobotics/poco-1.11.0-all/Foundation/src/Thread_POSIX.cpp:342

12 0x00007f897d5ea6ba in start_thread (arg=0x7f897b9b6700) at pthread_create.c:333

13 0x00007f897cd2441d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

any ideas would be very welcome. Omer. :-)

omerbrandis commented 1 year ago

hello

this still occurs in poco v 1.12.4 using gcc 8.4.0 .

minimal reproducible example : Poco::AutoPtr pDoc = new Poco::XML::Document; Poco::AutoPtr pRoot = pDoc->createElement("root"); pDoc->appendChild(pRoot);

try { Poco::XML::DOMWriter writer; writer.setNewLine("\n"); writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT); writer.writeNode(std::cout, pDoc); } catch (const Poco::XML::XMLException & Except) { std::cout << "xml writer threw " << Except.displayText() <<std::endl; }

please advise,

omerbrandis commented 1 year ago

gdb bt :

0 0x00007f29266fc428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54

1 0x00007f29266fe02a in __GI_abort () at abort.c:89

2 0x00007f292673e7ea in __libc_message (do_abort=do_abort@entry=1, fmt=fmt@entry=0x7f292685649f " %s : %s terminated\n") at ../sysdeps/posix/libc_fatal.c:175

3 0x00007f29267e015c in __GI___fortify_fail (msg=, msg@entry=0x7f2926856481 "stack smashing detected") at fortify_fail.c:37

4 0x00007f29267e0100 in __stack_chk_fail () at stack_chk_fail.c:28

5 0x00000000004178be in myfunction() ()

6 0x00000000004116de in main ()

omerbrandis commented 1 year ago

seems that the instantiation of the Poco::XML::DOMWriter writer; is enough to cause the error

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 365 days with no activity.