Skip to content

Commit

Permalink
Merge pull request #9 from smartdevicelink/fix/bson_iterator_segfault
Browse files Browse the repository at this point in the history
Fixes segfault in `bson_object_iterator_next`
  • Loading branch information
jacobkeeler authored Oct 30, 2017
2 parents a3a1dc6 + dee59a3 commit 854740d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/bson_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,13 @@ MapIterator bson_object_iterator(BsonObject *obj) {
BsonObjectEntry bson_object_iterator_next(MapIterator *iterator) {
MapEntry *entry = emhashmap_iterator_next(iterator);
BsonObjectEntry bsonEntry;
strncpy(bsonEntry.key, entry->key, 255);
bsonEntry.element = (BsonElement *)entry->value;
if(entry == NULL) {
bsonEntry.key[0] = 0x00; //Assign empty string
bsonEntry.element = NULL;
}
else {
strncpy(bsonEntry.key, entry->key, 255);
bsonEntry.element = (BsonElement *)entry->value;
}
return bsonEntry;
}
3 changes: 2 additions & 1 deletion src/bson_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ MapIterator bson_object_iterator(BsonObject *obj);
@param iterator - The iterator to be advanced
@return - The next BSON object entry in the object if it exists,
NULL if the iterator has moved past the end of the entry list
an entry with a NULL element if the iterator has moved past the end
of the entry list
*/
BsonObjectEntry bson_object_iterator_next(MapIterator *iterator);

Expand Down

0 comments on commit 854740d

Please sign in to comment.