shinberg / cpp-hiredis-cluster

c++ cluster wrapper for hiredis with async and unix sockets features
BSD 3-Clause "New" or "Revised" License
65 stars 26 forks source link

Uninitialized pointer in hirediscommand.h leads to SEGV #25

Open nysenthil opened 7 years ago

nysenthil commented 7 years ago

In the include/hirediscommand.h file, the following method is used heavily in all the hiredis cluster APIs.

    redisReply* processHiredisCommand( Connection *con ) {
        redisReply* reply;
        redisAppendFormattedCommand( con, cmd_, len_ );
        redisGetReply( con, (void**)&reply );
        return reply;
    }

redisReply* reply variable is not initialized. It works fine as long as all the master nodes in the Redis cluster are active. As soon as a master node goes down, redisGetReply method that is being called within the code block shown above returns without altering that uninitialized variable. Now, that uninitialized pointer gets returned to the caller and when accessed by the caller it frequently causes SEGV crash. Please change that one line of code as shown below. That is the safe thing to do.

redisReply* reply = NULL;

I did this change locally in my environment. That eliminated the crashes. After this minor code change, it now properly throws a DisconnectedException which can be caught and dealt with by the end user C/C++ application code.

shinberg commented 7 years ago

Sure, I will. Thanks a lot!