in reply to Re: opening files: link checking and race conditions
in thread opening files: link checking and race conditions

Erm, that just reverses the race-condition. Now all an attacker needs to do is to replace the link with an actual file after it's opened.

  • Comment on Re^2: opening files: link checking and race conditions

Replies are listed 'Best First'.
Re^3: opening files: link checking and race conditions
by anonymized user 468275 (Curate) on Aug 03, 2005 at 13:15 UTC
    okay but if that is a problem too, doesn't this fix both?
    my $lflag = ( -l 'foo' ); # check before opening $lflag or open my $fh, ">>foo" or ErrorHandler( $?, $! ); $lflag = ( -l 'foo' ); # and again after opening unless( $lflag } { # process file } $lflag or close $fh;

    One world, one people

      Google "atomicity" and "race case" for more information, but here's a brief way how that would die: (P1 is process 1, P2 is process 2, they're not actually in the same program, but the commands from each are interleaved here since that can happen in reality)
      P1: my $lflag = ( -l 'foo' ); # seems good P2: makes foo a link - uh oh! P1: $lflag or open my $fh, ">>foo"; # does it fine, since $lflag was s +et before P2: remove that link, lickity-split! P1: $lflag = ( -l 'foo' ); # whups, everything *seems* ok...
      Make sense? Dave_the_m's code will exactly perform the actions for P2, btw. (Eimi's earlier explanation did exactly what your code does, too - look it over, the -l check happens before and after.)