Git Product home page Git Product logo

Comments (6)

nacho avatar nacho commented on June 26, 2024

Hey, can you start providing a patch with the first option so it can be discussed with a MR in place? Thanks

from protobuf-c.

edmonds avatar edmonds commented on June 26, 2024

Hi, @smuellerDD, thanks for the report and the patch.

I don't doubt that you ran into a memory corruption issue but I'm curious if you can provide more details about the exact circumstances that were required in order to get protobuf_c_message_unpack() to return a ProtobufCMessage * with an uninitialized unknown_fields? If protobuf-c were always returning uninitialized memory there I'd expect a lot more crashes and bug reports since that kind of bug would tend to light up Valgrind and the various sanitizers.

After the initial do_alloc() here:

rv = do_alloc(allocator, desc->sizeof_message);

We perform initialization here:

if (desc->message_init != NULL)
protobuf_c_message_init(desc, rv);
else
message_init_generic(desc, rv);

In the first branch, if the message descriptor was generated by the protobuf-c compiler we should eventually end up calling PROTOBUF_C_MESSAGE_INIT which will zero all three fields of the ProtobufCMessage:

#define PROTOBUF_C_MESSAGE_INIT(descriptor) { descriptor, 0, NULL }

In the second branch, we should be calling memset() to zero the whole thing:

memset(message, 0, desc->sizeof_message);

Are you by chance using your own ProtobufCMessageDescriptor rather than one generated by the protobuf-c compiler?

from protobuf-c.

edmonds avatar edmonds commented on June 26, 2024

Also, my preference for fixing this would be to immediately do a *rv = {0}; right after the allocation succeeds, it's a little bit weird that the protobuf-c code base doesn't do this everywhere memory is allocated. Perhaps we should make do_alloc() always do a memset and take the probably negligible performance hit in exchange for more assurance that we're not using uninitialized memory somewhere.

from protobuf-c.

smuellerDD avatar smuellerDD commented on June 26, 2024

from protobuf-c.

edmonds avatar edmonds commented on June 26, 2024

The easiest would be a calloc instead of a malloc. Ciao Stephan

Right, but we can't directly call calloc() since protobuf-c wraps memory allocations using ProtobufCAllocator so that the library user can provide their own allocation functions. So we could either introduce a do_calloc() that calls the alloc function in the allocator and does a memset() or we could make do_alloc() always zero out all memory allocations.

from protobuf-c.

smuellerDD avatar smuellerDD commented on June 26, 2024

from protobuf-c.

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.