Giter Site home page Giter Site logo

Comments (3)

theintz avatar theintz commented on June 12, 2024

The issue happens due to an attempt to free() an uninitialized pointer. More precisely: the pointer reply is created at the top of phpiredis_command_bs() and not initialized. It is then passed into redisGetReply(), where it is normally replaced with a pointer to a valid redisReply object and all is good.

However, when the server goes away, this pointer is never replaced, so when freeReplyObject(reply) is called, it is actually operating on an uninitialized pointer, which causes the segfault.

A similar problem was addressed in bccb042, but never really done properly.

Two ideas on how to avoid the segfault:

  1. As its impossible to check for an uninitialized pointer, the pointer could be set to NULL upon declaration. Later it could be checked for that value and only freed when it is not NULL:
if (reply) freeRedisReply(reply);
  1. When an error occurrs, the err field in the redis context is populated. Depending on the value of this field, the code could decide whether to free or not free the reply:
if (connection->c->err != REDIS_ERR_IO) freeRedisReply();

Number 1 seems cleaner, but we have tried this, and experienced some strange behavior. Maybe someone else knows how to do it properly? Number 2 seems like a hack, and may vreate a memory leak.

from phpiredis.

theintz avatar theintz commented on June 12, 2024

Ok, so initializing the pointer to NULL is really the proper way. I have opened a pull request with that fix. Please review quickly.

from phpiredis.

nrk avatar nrk commented on June 12, 2024

@theintz thanks for the detailed report and PR #21 and sorry for being so late, I'm finally starting to slowly get back to my open-source projects after a long hiatus due to the lack of free time. I just started reviewing your other (and more substantial) pull request.

from phpiredis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.