Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when tried to access request->map_post_body #184

Closed
NakedSolidSnake opened this issue Feb 7, 2021 · 4 comments
Closed

Segfault when tried to access request->map_post_body #184

NakedSolidSnake opened this issue Feb 7, 2021 · 4 comments
Labels
can't reproduce Can't reproduce the issue

Comments

@NakedSolidSnake
Copy link

Describe the issue
I'm getting a segfault when I'm trying to get the post data. I'm using simple_example as a guide.

To Reproduce
To reproduce the bug get the project in https://github.com/NakedSolidSnake/C_Webserver_Registry
I'm using postman to send message in POST
endpoint: /insert
data: fname=Name&faddress=Address&fage=42

Expected behavior
I want to get variable values

System (please complete the following information):
AME="Linux Mint"
VERSION="19.1 (Tessa)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 19.1"
VERSION_ID="19.1"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.ubuntu.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=tessa
UBUNTU_CODENAME=bionic

Additional context
Thread 3 "MHD-connection" hit Breakpoint 1, callback_insert (request=0x7fffe4000b70, response=0x7fffe4001900, user_data=0x0)
at /media/cssouza/SOLIDCRIS/repositories/C_Language/C_Webserver_Registry/src/main.c:73
73 char *url_params = print_map(request->map_url);
(gdb) p *request
$1 = {http_protocol = 0x7fffe4000e90 "HTTP/1.1", http_verb = 0x7fffe4000eb0 "POST", http_url = 0x7fffe4000e10 "/insert", url_path = 0x0,
proxy = 0x1 <error: Cannot access memory at address 0x1>, network_type = 0, check_server_certificate = 0, check_server_certificate_flag = -469758256, check_proxy_certificate = 32767,
check_proxy_certificate_flag = 0, follow_redirect = 0, ca_path = 0x0, timeout = 140737018596336, client_address = 0x7fffe4000c20, auth_basic_user = 0x7fffe4000c50 "",
auth_basic_password = 0x7fffe4000c80 "", map_url = 0x7fffe4000fb0, map_header = 0x27, map_cookie = 0x35, map_post_body = 0x0, binary_body = 0x7fffe4000cd0,
binary_body_length = 140737018596528, callback_position = 3959459072, client_cert = 0x0, client_cert_file = 0x35 <error: Cannot access memory at address 0x35>,
client_key_file = 0xd <error: Cannot access memory at address 0xd>, client_key_password = 0x7fffe40016c0 "\360\016"}
(gdb) c
Continuing.

Thread 3 "MHD-connection" received signal SIGSEGV, Segmentation fault.
0x0000555555554fa5 in print_map (map=0x7fffe4000fb0) at /media/cssouza/SOLIDCRIS/repositories/C_Language/C_Webserver_Registry/src/main.c:20
20 for (i=0; keys[i] != NULL; i++) {
(gdb) bt
#0 0x0000555555554fa5 in print_map (map=0x7fffe4000fb0) at /media/cssouza/SOLIDCRIS/repositories/C_Language/C_Webserver_Registry/src/main.c:20
#1 0x000055555555501a in callback_insert (request=0x7fffe4000b70, response=0x7fffe4001900, user_data=0x0)
at /media/cssouza/SOLIDCRIS/repositories/C_Language/C_Webserver_Registry/src/main.c:73
#2 0x00007ffff7bc6e21 in ?? () from /usr/lib/libulfius.so.2.2
#3 0x00007ffff73b45f5 in ?? () from /usr/lib/x86_64-linux-gnu/libmicrohttpd.so.12
#4 0x00007ffff73b61a8 in ?? () from /usr/lib/x86_64-linux-gnu/libmicrohttpd.so.12
#5 0x00007ffff73b8016 in ?? () from /usr/lib/x86_64-linux-gnu/libmicrohttpd.so.12
#6 0x00007ffff73bb558 in ?? () from /usr/lib/x86_64-linux-gnu/libmicrohttpd.so.12
#7 0x00007ffff6f946db in start_thread (arg=0x7ffff0e38700) at pthread_create.c:463
#8 0x00007ffff76ee88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

@babelouest
Copy link
Owner

Hello @NakedSolidSnake ,

I can't reproduce your bug by using your code and executing the curl command:

$ curl -i --data "fname=Name&faddress=Address&fage=42" http://localhost:8095/insert
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 0
Access-Control-Allow-Origin: *
Date: Sun, 07 Feb 2021 14:26:28 GMT

Besides the fact that your issue is in a useless part of the code in your case (you don't use url_params anywhere after setting it), there is no problem with your code that could lead to a segfault. I believe your problem is elsewhere.

How did you install ulfius? did you compile from the source? Or install a package downloaded from github? Or something else?
If you installed a package that may be the problem: there is no package for Linux Mint.
I suggest to build ulfius from the source and retry.

@babelouest babelouest added the can't reproduce Can't reproduce the issue label Feb 7, 2021
@NakedSolidSnake
Copy link
Author

NakedSolidSnake commented Feb 7, 2021

How did you install ulfius?
did you compile from the source?
Or install a package downloaded from github? Or something else?
R: I downloaded from github, compiled and installed.
If you installed a package that may be the problem: there is no package for Linux Mint.
I suggest to build ulfius from the source and retry.
C: Yeah I tried both, but no one works fine, maybe can be the operation system flavor, I'll try in another.
But there is some strange about addresses showed in gdb when I printed variable request. Is there somewhere that I need to initialize the request buffers to works fine?
I saw in the samples there is no need. But who knows?

@NakedSolidSnake
Copy link
Author

Yeah, You're right. Doesn't work in that Linux flavor. I ran on my raspberry pi works fine. Thanks for your attention.

@babelouest
Copy link
Owner

Thanks for the confirmation, I'll try to test it with a Linux Mint to try to reproduce the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce Can't reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants