Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data::UUID->new->from_string(4) doesn't always throw an error. #8

Open
ikegami opened this issue Mar 11, 2014 · 3 comments
Open

Data::UUID->new->from_string(4) doesn't always throw an error. #8

ikegami opened this issue Mar 11, 2014 · 3 comments

Comments

@ikegami
Copy link

ikegami commented Mar 11, 2014

$ 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...
@ikegami
Copy link
Author

ikegami commented Mar 11, 2014

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

@ikegami
Copy link
Author

ikegami commented Mar 11, 2014

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

@ikegami
Copy link
Author

ikegami commented Mar 11, 2014

Oops, that "fix" only fixes the first code sample, but not the second. Unfortunately, I've already spent too much time on this today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant