babelouest / ulfius

Web Framework to build REST APIs, Webservices or any HTTP endpoint in C language. Can stream large amount of data, integrate JSON data with Jansson, and create websocket services
https://babelouest.github.io/ulfius
GNU Lesser General Public License v2.1
1.08k stars 182 forks source link

[SOLVED] "MHD-connection" received signal SIGSEGV, Segmentation fault with strlen() #235

Closed elockman closed 2 years ago

elockman commented 2 years ago

I am using ulfius v2.7.8 and orcania v2.2.2 from github distribution on an ARMv7 (SAMA5d2) processor. I'm running into a segmentation fault, which appears to be related to strlen. In orcania, I ran across o_strlen ("a modified version of strlen that don't crash when s is NULL"), so I'm wondering if this problem has crept in before.

Ulfius is providing a webUI to test CZMQ functions. I'm not sure that matters, but thought it was noteworthy.

Are there any considerations needed for using strlen, other than the length fits inside the buffer and the buff is not NULL?

Running GDB, I get:

[New LWP 582]
[New LWP 583]
[New LWP 584]
>>> BIND TO SUBSCRIPTION ENDPOINT: tcp://*:5555
[Detaching after vfork from child process 585]
TX to tcp://[fe80::20f:2ff:fe36:7777%mesh0]:5555
Mesh provisioning CLEARED
[Detaching after vfork from child process 589]

Connect to tcp://[fe80::20f:2ff:fe36:7777%mesh0]:5555
[New LWP 593]
[New LWP 594]

**Thread 4 "MHD-connection" received signal SIGSEGV, Segmentation fault.**
[Switching to LWP 581]
**0xb6d00d64 in strlen () from /lib/libc.so.6**
(gdb)

Does anything else provide bread crumbs that I've missed? At this point, I'm not looking for full support, but guidance. I can try to create a minimal test program to reproduce if I need further support.

babelouest commented 2 years ago

Hello @elockman ,

It's hard to tell where the issue might be just looking at your log output. Can you provide more explanation on the context and maybe a sample code?

babelouest commented 2 years ago

Also, you can try with debugging tools such as valgrind to help you point out where the error should be.

elockman commented 2 years ago

@babelouest

Thanks for your prompt response. I've also run across this online. https://packetstormsecurity.com/files/164152/Ulfius-Web-Framework-Remote-Memory-Corruption.html

I'm really looking for missing background info that may be pertinent.

I'll continue to troubleshoot today to target the trouble code. Once I'm closer, I'll try to compose minimal sample code to reproduce if it isn't resolved. Thanks again.

elockman commented 2 years ago

[SOLVED]

I found my issue. This SegFault was not related to ipv6 comms or czmq. This was pretty dumb actually.

I created a function with an underscore prefix. This prefix is often used in python for internally used functions. In C, the underscore prefix is reserved for the compiler and standard library.

Renaming the function resolved this user issue. Not related to Ulfius...Closing.