shiyilei / protobuf-c

Automatically exported from code.google.com/p/protobuf-c
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

NULL required string member causes seg fault in required_field_get_packed_size #13

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This looks like a judgment call.

When I give a string member, but leave that string member NULL I get a
segmentation fault in required_field_get_packed_size(). I think seg
faulting is correct, but I figured I'd bring it up. 

    case PROTOBUF_C_TYPE_STRING:
      {
        size_t len = strlen (*(char * const *) member);
        return rv + uint32_size (len) + len;
      }

When the member is NULL, it blows up. 

Original issue reported on code.google.com by pfeff...@gmail.com on 26 Jan 2009 at 7:13

GoogleCodeExporter commented 8 years ago
I agree that the behavior is arguably correct, but not very user-friendly.  The 
truth
is that since it's difficult to get the name here we probably need to help the 
user
in some way.

One option would be to print an error message if the string is NULL.  This is a
little inconsistent with its behavior for say, integers, though.

Of course it should probably treat NULL as an empty string...

Likewise, NULL submessages should probably be serialized as 0-length data.

This probably needs to affect the get_packed_size(), pack() and pack_to_buffer()
functions... so 2 field-types (strings + messages) times 3 functions.

Alternately, we could have an optional way to print a warning in this case.  
e.g. a
global boolean.

um, patches welcome?

Original comment by lahike...@gmail.com on 28 Jan 2009 at 12:18

GoogleCodeExporter commented 8 years ago
i committed the fix described to subversion.

Original comment by lahike...@gmail.com on 29 Jan 2009 at 2:29

GoogleCodeExporter commented 8 years ago

Original comment by lahike...@gmail.com on 29 Jan 2009 at 2:30