Potential bug ?

kspecial_at_linuxmail.org
Date: 09/30/04

  • Next message: Staale: "Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)"
    Date: 29 Sep 2004 18:08:01 -0700
    
    

    Hey, i've got some code here that i've been having problems with, I
    have crunched my brain and have resorted to this very place. For some
    reason the variable @logins in the following code is being undefined
    when there is absolutely nothing that is using @logins in such a way
    that it would be undefined, the two functions are out of a lot longer
    bit of code but I have put them together here in such a manor that you
    can run the following code yourself as a file and get an eye to what's
    going on, please excuse any bad syntax, unless it's having to do with
    something i've done wrong that causes this problem. Here is the code:

    --- CODE ---

    @logins = ('K-sPecial perl.freak o (kspecial)');

    logout_user(\@logins, "K-sPecial",
    "d41d8cd98f00b204e9800998ecf8427e");

    sub logout_user {
            my ($logins, $name, $pass) = @_;
            print "Logins ($logins) in logout_user: @$logins\r\n";
            foreach (@$logins) {
                    if (m/^\s*$name\s+/i) {
                            #my $rname = get_rname($logins, "$name", ' ',
    1);
                            my $md5 = ub_value ("$rname", 1);
                            print "Now logins ($logins) in logout_user:
    @$logins\r\n";
                            print "Got $rname and $name then $md5 and
    $pass\r\n";
                            if ("$pass" eq "$md5") {
                                    #my $return = del_login($logins,
    "$name");
                                    return ($return);
                            }
                    }
                    return(0);
            }
    }

    sub ub_value {
            my ($user, @values) = @_;
            #$user = rem_re($user);
            my $userline;
            open (FH, "<fool.txt") or return (undef);
            while (<FH>) {
                    $userline = $_ if m/^$user:/i;
            }
            close(FH);
            print "Userline is $userline";
            if ($userline) {
                    my @results;
                    foreach(@values) {
                            push(@results, (split(':', "$userline"))[$_]);
                    }
                    print "Gots the @results\r\n";
                    return ("$results[0]") if scalar(@values) == 1;
                    return("@results");
            }
            else {
                    print "returning 0\r\n";
                    return(0);
            }
    }

    --- END CODE ---

    So i'm going to run that code exactly as is and show you it's output:

    --- OUTPUT ---

    kspecial@xzziroz:~$ perl borked.pl
    Logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
    (kspecial)
    Userline is returning 0
    Now logins (ARRAY(0x814490c)) in logout_user:
    Got and K-sPecial then 0 and d41d8cd98f00b204e9800998ecf8427e

    --- END OUTPUT ---

    Look! @logins is completely being undefined with no apparent reason!
    Now try taking out the call to ub_value ( my $md5 = ub_value
    ("$rname", 1); ) now @logins is fine. It prints this:

    --- OUTPUT ---
    kspecial@xzziroz:~$ perl borked.pl
    Logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
    (kspecial)
    Now logins (ARRAY(0x814490c)) in logout_user: K-sPecial perl.freak o
    (kspecial)
    Got and K-sPecial then and d41d8cd98f00b204e9800998ecf8427e

    --- END OUTPUT ---

    Just as it should... now i'm not very good with the perl debugger but
    I did manage to get a glimpse at what was happening, at the user
    level.

    Here is the debugging:

    --- DEBUGGING ---
    main::ub_value(borked.pl:24): my ($user, @values) = @_;
      DB<3> s
    main::ub_value(borked.pl:26): my $userline;
      DB<3> p "@logins"
    K-sPecial perl.freak o (kspecial)
      DB<4> s
    main::ub_value(borked.pl:27): open (FH, "<fool.txt") or
    return (undef);
      DB<4> p "@logins"
    K-sPecial perl.freak o (kspecial)
      DB<5> s
    main::ub_value(borked.pl:28): while (<FH>) {
      DB<5> p "@logins"
    K-sPecial perl.freak o (kspecial)
      DB<6> s
    main::ub_value(borked.pl:29): $userline = $_ if
    m/^$user:/i;
      DB<6> p "@logins"
    kspecial:d41d8cd98f00b204e9800998ecf8427e:ow:-1:::
      DB<7> s
    main::ub_value(borked.pl:29): $userline = $_ if
    m/^$user:/i;
      DB<7> p "@logins"
    xemp:c4ca4238a0b923820dcc509a6f75849b:o:1000:::
      DB<8> s
    main::ub_value(borked.pl:29): $userline = $_ if
    m/^$user:/i;
      DB<8> p "@logins"
    coprime:c81e728d9d4c2f636f067f89cc14862c:v:9999:::

    --- END DEBUGGING ---

    Of course that's assuming your fool.txt looks like this:

    --- START fool.txt ---
    kspecial:d41d8cd98f00b204e9800998ecf8427e:ow:-1:::
    xemp:c4ca4238a0b923820dcc509a6f75849b:o:1000:::
    coprime:c81e728d9d4c2f636f067f89cc14862c:v:9999:::
    --- END fool.txt ---

    Oddly the line " $userline = $_ if m/^$user:/i " is assigning $_ to
    @logins on every loop......I'm gonig to also send this same message
    using 'perlbug' if i'm able to.

    --K-sPecial


  • Next message: Staale: "Re: Sample perl code does not work (from Perl cookbook, 2nd ed.)"

    Relevant Pages

    • Re: Single user with Domain Auth Issue
      ... and backup terms was indeed for that reason, ... metrics makes a difference when pertaining to logins but if the case ...
      (microsoft.public.windows.server.setup)
    • Some login sites dont work
      ... I am having problems with some sites which need passwords or logins. ... some reason after filling out my user name and password correctly I still ... On my other computer (not laptop) everything seems to work fine... ...
      (microsoft.public.windows.inetexplorer.ie6.browser)
    • Re: Disabling Logins?
      ... I'd like to disable all logins at the XDM level. ... The reason is ... to prevent users logging on while maintenance is performed. ... maintenance is completed, I'd then want to re-enable logins. ...
      (comp.unix.tru64)
    • Re: wtmp utmp
      ... Just had a thought - I only login using ssh and on a freak occasion VNC. ... Could that be a reason? ... Mine records remote logins using ssh. ...
      (alt.os.linux.suse)
    • Re: DBD::Oracle
      ... yes that file has rwxr-xr-x permission ... in one login perl is working fine and in the another login the perl ... the settings are same for both logins ...
      (comp.lang.perl.modules)