-
-
Save deoxxa/c85c62baeac6013a1e5b to your computer and use it in GitHub Desktop.
segfault in uv_ip4_name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ mesh lldb mesh | |
Current executable set to 'mesh' (x86_64). | |
(lldb) run | |
Process 41196 launched: '/Users/conrad/Work/scratch/mesh/mesh' (x86_64) | |
status: 0 | |
Recv 8 bytes from 127.0.0.1 | |
Process 41196 stopped | |
* thread #1: tid = 0x46d59, 0x0000000100011de2 libuv.dylib`inet_ntop4 + 33, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x4) | |
frame #0: 0x0000000100011de2 libuv.dylib`inet_ntop4 + 33 | |
libuv.dylib`inet_ntop4 + 33: | |
-> 0x100011de2: movzbl (%rdi), %r9d | |
0x100011de6: movzbl 1(%rdi), %eax | |
0x100011dea: movzbl 2(%rdi), %ecx | |
0x100011dee: movzbl 3(%rdi), %edx | |
(lldb) bt full | |
error: bt [<digit>|all] | |
(lldb) bt | |
* thread #1: tid = 0x46d59, 0x0000000100011de2 libuv.dylib`inet_ntop4 + 33, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x4) | |
frame #0: 0x0000000100011de2 libuv.dylib`inet_ntop4 + 33 | |
frame #1: 0x0000000100011c28 libuv.dylib`uv_inet_ntop + 241 | |
frame #2: 0x00000001000116f1 libuv.dylib`uv_ip4_name + 30 | |
frame #3: 0x0000000100000a94 mesh`on_read(req=0x00007fff5fbff868, nread=0, buf=uv_buf_t at 0x00007fff5fbf7468, addr=0x0000000000000000, flags=0) + 212 at mesh.c:22 | |
frame #4: 0x000000010001014c libuv.dylib`uv__udp_io + 520 | |
frame #5: 0x0000000100013188 libuv.dylib`uv__io_poll + 1354 | |
frame #6: 0x0000000100006325 libuv.dylib`uv_run + 259 | |
frame #7: 0x0000000100000d96 mesh`main(argc=1, argv=0x00007fff5fbff958) + 614 at mesh.c:63 | |
frame #8: 0x00007fff8eaba5fd libdyld.dylib`start + 1 | |
frame #9: 0x00007fff8eaba5fd libdyld.dylib`start + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <uv.h> | |
uv_loop_t* loop; | |
uv_buf_t alloc_buffer(uv_handle_t *handle, size_t suggested_size) { | |
return uv_buf_init(malloc(suggested_size), suggested_size); | |
} | |
void on_read(uv_udp_t *req, ssize_t nread, uv_buf_t buf, struct sockaddr *addr, unsigned flags) { | |
if (nread < 0) { | |
fprintf(stderr, "Read error %s\n", uv_err_name(uv_last_error(loop))); | |
uv_close((uv_handle_t*) req, NULL); | |
return; | |
} | |
char sender[17] = { 0 }; | |
uv_ip4_name((struct sockaddr_in*) addr, sender, 16); | |
fprintf(stderr, "Recv %zu bytes from %s\n", nread, sender); | |
free(buf.base); | |
} | |
void on_send(uv_udp_send_t* req, int status) { | |
printf("status: %d\n", status); | |
free(req->data); | |
} | |
int main(int argc, char** argv) { | |
uv_udp_t fd; | |
int rc; | |
loop = uv_default_loop(); | |
rc = uv_udp_init(loop, &fd); | |
if (rc != 0) { | |
fprintf(stderr, "error initialising socket\n"); | |
return 1; | |
} | |
rc = uv_udp_bind(&fd, uv_ip4_addr("0.0.0.0", 5000), 0); | |
if (rc != 0) { | |
fprintf(stderr, "error binding socket\n"); | |
return 1; | |
} | |
rc = uv_udp_recv_start(&fd, alloc_buffer, on_read); | |
if (rc != 0) { | |
fprintf(stderr, "error listening on socket\n"); | |
return 1; | |
} | |
uv_udp_send_t req; | |
uv_buf_t msg = uv_buf_init(malloc(8), 8); | |
req.data = msg.base; | |
uv_udp_send(&req, &fd, &msg, 1, uv_ip4_addr("127.0.0.1", 5000), on_send); | |
return uv_run(loop, UV_RUN_DEFAULT); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment