Actions
Bug #637
closedSegfault linked to NICK handling
Start date:
2018-10-31
Due date:
% Done:
100%
Estimated time:
Patch Available:
Found in Versions:
Confirmed:
Yes
Branch:
Security:
Help Needed:
Description
Hello,
I've had several crashes using bip 0.9.0-rc1-git
For example:
(gdb) bt #0 0x00005555555638dc in write_line (cn=cn@entry=0x0, line=line@entry=0x5555559427b0 "NICK Trou\r\n") at src/connection.c:430 #1 0x000055555556b6bc in irc_line_write (l=<optimized out>, c=0x0) at src/line.c:41 #2 0x0000555555566d1e in irc_001 (server=0x55555593e970, server=0x55555593e970, line=0x5555559357b0) at src/irc.c:173 #3 irc_dispatch_server (bip=<optimized out>, server=0x55555593e970, line=0x5555559357b0) at src/irc.c:453 #4 0x000055555556900d in irc_dispatch (bip=bip@entry=0x7fffffffb4b0, l=l@entry=0x55555593e970, line=line@entry=0x5555559357b0) at src/irc.c:1260 #5 0x000055555556ac85 in bip_on_event (bip=bip@entry=0x7fffffffb4b0, conn=0x5555558b8750) at src/irc.c:2490 #6 0x000055555556af73 in irc_main (bip=0x7fffffffb4b0) at src/irc.c:2565 #7 0x000055555555b4a0 in main (argc=<optimized out>, argv=<optimized out>) at src/bip.c:1359
I've also another coredump (but for some reason, gdb does not get lines correctly):
Program terminated with signal SIGSEGV, Segmentation fault. #0 0x000055e45d24d8dc in ?? () (gdb) info reg rax 0x55e45d759a80 94439308892800 rbx 0x0 0 rcx 0x7f45d71b5b00 139937938365184 rdx 0x12 18 rsi 0x55e45d7599e0 94439308892640 rdi 0x55e45d759a80 94439308892800 rbp 0x0 0x0 rsp 0x7ffc0674a1c0 0x7ffc0674a1c0 r8 0xeec0 61120 r9 0x20 32 r10 0x747e21756f725420 8394183543729837088 r11 0x312e383740756f72 3543831766742953842 r12 0x7ffc0674a220 140720416793120 r13 0x1 1 r14 0x0 0 r15 0x8 8 rip 0x55e45d24d8dc 0x55e45d24d8dc eflags 0x10206 [ PF IF RF ] (gdb) x/1s $rdi 0x55e45d759a80: ":Trou NICK Trou\r\n" (gdb) x/1s $rsi 0x55e45d7599e0: ":Trou NICK Trou\r\n"
But i'm not quite sure why it crashes.
The following patch should help if there's a race (between increment and realloc) but I think it's unlikely to be the problem.
diff --git a/src/irc.c b/src/irc.c
index f46f4dd..08c9cb9 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -575,10 +575,11 @@ static void bind_to_link(struct link *l, struct link_client *ic)
int i = l->l_clientc;
LINK(ic) = l;
- l->l_clientc++;
- l->l_clientv = bip_realloc(l->l_clientv, l->l_clientc *
+ l->l_clientv = bip_realloc(l->l_clientv, (l->l_clientc + 1) *
sizeof(struct link_client *));
l->l_clientv[i] = ic;
+ /* Increment after, to avoid any race condition */
+ l->l_clientc++;
}
void unbind_from_link(struct link_client *ic)
Actions