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

protobuf_c_enum_descriptor_get_value_by_name() binary search corner case #35

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
in certain corner cases, e.g. an enum with three values, when
protobuf_c_enum_descriptor_get_value_by_name() is called to look up
a nonexistent name that comes after (in a strcmp() comparison) all 
the possible enum strings, the binary search will attempt to read
beyond the end of the enum_values_by_name array.

the attached patch appears to fix this.  ok to commit?

Original issue reported on code.google.com by robert.e...@gmail.com on 9 Feb 2010 at 1:30

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the bug, but the problem is actually a bug updating "count" a few 
lines.  
Oddly this code is cut-n-pasted 3 times -- it was correct for:
   protobuf_c_message_descriptor_get_field_by_name
and buggy for
   protobuf_c_enum_descriptor_get_value_by_name
   protobuf_c_service_descriptor_get_method_by_name

Fix committed as revision 203.

Original comment by lahike...@gmail.com on 10 Feb 2010 at 12:32

GoogleCodeExporter commented 8 years ago
(might be good to refactor into a single bsearch function... sigh...)

Original comment by lahike...@gmail.com on 10 Feb 2010 at 12:34

GoogleCodeExporter commented 8 years ago
thanks, i've cherry picked this fix for the debian protobuf-c 0.12-2 package.

Original comment by robert.e...@gmail.com on 10 Feb 2010 at 1:09

GoogleCodeExporter commented 8 years ago

Original comment by lahike...@gmail.com on 18 Mar 2010 at 2:44