Data-UUID
Data-UUID copied to clipboard
Data::UUID->new->from_string(4) doesn't always throw an error.
$ perl -MData::UUID -e'
my $x = "12345678901234567890123456789012";
print Data::UUID->new->from_string($x), "\n";
$x = 4;
print Data::UUID->new->from_string($x), "\n";
print "done\n";
'
xV4▒V4x▒4Vx▒
xV4▒V4x▒4Vx▒
done
That's wrong. If I change C<< $x = 4; >> to C<< undef $x; $x = 4; >>, an error is correctly reported.
xV4▒V4x▒4Vx▒
from_string(4) failed...
Better test case:
$ perl -Mlib=lib,thirdParty/lib/perl5 -MData::UUID -e'
my $x = "3\0" x 16;
print Data::UUID->new->from_string($x), "\n";
print "done\n";
'
done
Fix:
void
from_string(self,str)
uuid_context_t *self;
- char *str;
+ SV *str_sv;
ALIAS:
Data::UUID::from_hexstring = F_HEX
Data::UUID::from_b64string = F_B64
PREINIT:
+ STRLEN len;
+ char *str = SvPV(str_sv, len);
perl_uuid_t uuid;
char *from, *to;
int c;
unsigned int i;
unsigned char buf[4];
PPCODE:
switch(ix) {
case F_BIN:
case F_STR:
case F_HEX:
+ if (len != sizeof(perl_uuid_t)*2)
+ croak("from_string(%s) failed...\n", str);
Untested
Oops, that "fix" only fixes the first code sample, but not the second. Unfortunately, I've already spent too much time on this today.