Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

Commit

Permalink
PERL-489 fix BSON crash encoding reference to PVNV etc.
Browse files Browse the repository at this point in the history
The prior code could only handle reference to PVs.  The new code
check SvPOK instead.
  • Loading branch information
xdg committed Jan 9, 2015
1 parent 60bb9e0 commit 41349b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Changes
Expand Up @@ -17,6 +17,12 @@
- Removed Data::Types as a test dependency as it was barely used
and not necessary

[Bug fixes]

- PERL-489 references to scalars with both number and string slots internally
would crash on BSON encoding, rather than encode the string part as a
binary.

v0.999.998.1 2014-11-12 15:10:40-05:00 America/New_York (TRIAL RELEASE)

[!!! Incompatible Changes !!!]
Expand Down
21 changes: 12 additions & 9 deletions perl_mongo.c
Expand Up @@ -1393,7 +1393,8 @@ append_sv (bson_t * bson, const char * in_key, SV *sv, stackette *stack, int is_
croak ("type (%s) unhandled", HvNAME(SvSTASH(SvRV(sv))));
}
} else {
switch (SvTYPE (SvRV (sv))) {
SV *deref = SvRV(sv);
switch (SvTYPE (deref)) {
case SVt_PVHV: {
/* hash */
bson_t child;
Expand All @@ -1411,14 +1412,16 @@ append_sv (bson_t * bson, const char * in_key, SV *sv, stackette *stack, int is_
bson_append_array_end(bson, &child);
break;
}
case SVt_PV:
/* binary */

serialize_binary(bson, key, BSON_SUBTYPE_BINARY, SvRV(sv));
break;
default:
sv_dump(SvRV(sv));
croak ("type (ref) unhandled");
default: {
if ( SvPOK(deref) ) {
/* binary */
serialize_binary(bson, key, BSON_SUBTYPE_BINARY, deref);
}
else {
sv_dump(deref);
croak ("type (ref) unhandled");
}
}
}
}
} else {
Expand Down
11 changes: 11 additions & 0 deletions t/bson.t
Expand Up @@ -404,4 +404,15 @@ subtest "Checking hash key unicode support" => sub {
is ( $obj->{$testkey}, 1 );
};

subtest "PERL-489 ref to PVNV" => sub {
my $value = 42.2;
$value = "hello";
is(
exception { $c->insert( { value => \$value } ) },
undef,
"inserting ref to PVNV is not fatal",
);
};


done_testing;

0 comments on commit 41349b3

Please sign in to comment.