redis / hiredis

Minimalistic C client for Redis >= 1.2
BSD 3-Clause "New" or "Revised" License
6.22k stars 1.81k forks source link

Coredump at sdscatlen #1249

Closed mayursankpal closed 8 months ago

mayursankpal commented 8 months ago

Hiredis version = 0.11.0 OS = Debian GNU/Linux 11 (bullseye) Redis server v=6.0.16 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=6d95e1af3a2c082a

Scenario ==> Inserting data into redis DB ...Called from one of the unit test [googletest] Command ==> "HSET <some_key> state off"

Stack Trace Program received signal SIGSEGV, Segmentation fault. __redisAppendCommand (c=0x0, cmd=0x4daf10 "*4\r\n$4\r\nHSET\r\n$20\r\nsome_key\r\n$5\r\nstate\r\n$3\r\noff\r\n", len=61) at hiredis.c:1186 1186 newbuf = sdscatlen(c->obuf,cmd,len); (gdb) bt

0 __redisAppendCommand (c=0x0,

cmd=0x4daf10 "*4\r\n$4\r\nHSET\r\n$20\r\n**some_key**\r\n$5\r\nstate\r\n$3\r\noff\r\n", len=61)
at hiredis.c:1186

1 0x00007fffff6f461c in redisvAppendCommand (c=0x0, format=, ap=) at hiredis.c:1206

2 0x00007fffff6f4792 in redisvCommand (c=0x0, format=, ap=ap@entry=0x7ffffffed498) at hiredis.c:1267

3 0x00007fffff6f4847 in redisCommand (c=,

format=format@entry=0x4dc530 "HSET runtime.status.comms state off") at hiredis.c:1276
michael-grunder commented 8 months ago

Looks like you aren't making redisConnect is returning a valid context as c=0x0.

So you've got a NULL redisContext making redisContext->obuf just 0 + the offset of that member, which if course is not a valid sds string :smile:

I can't help much more than that without a bit of code that reproduces the issue. Fix should be simple though. Just make sure redisConnect is returning a valid pointer and c->err is not set.

michael-grunder commented 8 months ago

Closing as this doesn't seem to be a bug in hiredis but still happy to answer any other questions you have.