[PHP-DEV] Bug #590: File Upload Seg Fault From: jwalsh <email protected>
Date: 07/28/98

From: jwalsh <email protected>
Operating system: Solaris 2.5x
PHP version: 3.0.2a
PHP Bug Type: Reproduceable crash
Bug description:
Configuration: See http://sac.verio.net/info.php3

Problem: As soon as the "Import Passwords" button is clicked, I get a "Document Contains no Data" and the following error in the error_log.

     [Tue Jul 28 10:02:02 1998] [notice] httpd: child pid 10902 exit signal Segmentation Fault (11)

This worked fine with PHP 3.0, but not with 3.0.1 either.

Code Chunk:

<?
function MyErr() {
        print ("
<html>
<head><title>CCAPTA: Error!</title></head>
<body bgcolor=\"#9eb8df\">
<p align=\"center\"><img src=\"http://www.ccapta.org/CCAPTALogo.GIF\"
WIDTH=\"551\" HEIGHT=\"103\"></p>
<table border=\"0\" width=\"550\" cellspacing=\"0\" align=\"center\">
  <tr>
    <td bgcolor=\"#808080\" align=\"center\"><font
    size=\"4\"><strong>Error!</strong></font></td>
  </tr>
  <tr>
    <td>File not uploaded correctly</td>
  </tr>
</table>
</body>
</html>
          ");
          exit;
}

if( $mode == "update" ) {
        if( $file == "none" ) {
            MyErr();
        } else {
            echo "<p align=\"center\">Conversion In Progress . . .<BR>\n";
            /* echo "Original file name: $upfile_name<BR>\n";
            echo "File in upload_tmp_dir: $upfile<BR>\n";
            echo "File size: $upfile_size<BR>\n";
            echo "File type: $upfile_type<BR>\n"; */
                echo "This operation may take up to 2 minutes.<BR>\n";

                $htpasswd = "/home/virtual/Rabbits/members/.htpasswd";
                exec( "cp $upfile /home/virtual/Rabbits/admin/." );
                $fp = fopen( $upfile, "r+" );
                $original = fread( $fp, filesize( $upfile ) );
                $new = ereg_replace( "\r", "\n", $original );
                fwrite( $fp, $new, filesize( $upfile ) );
                fclose( $fp );
                $rawfile =  <email protected>( $upfile );
                $fp = fopen( $htpasswd, "w" );

                for( $i = 0; $i <= count( $rawfile ); $i++ ) {
                        $rawline = $rawfile[$i];
                        $rawline = explode( ",", ereg_replace( "\"", "", $rawline ) );
                        $newline = $rawline[0].":".crypt( $rawline[1], substr( $rawline[1], 1, 2 ) )."\n";
                        fputs( $fp, $newline);
                }

                fclose( $fp );
                exec( "rm $upfile" );
        }
        
        echo "Password file conversion complete.</p>\n";
} else {
        echo "Normal<BR>\n";
}
?>
<html>
<head>
<title>CCAPTA Password Admin</title>
</head>

<body bgcolor="#9eb8df">

<p align="center"><img src="http://www.ccapta.org/CCAPTALogo.GIF" WIDTH="551"
HEIGHT="103"></p>
<div align="center"><center>

<table border="0" width="550" cellspacing="0">
  <tr>
    <td bgcolor="#808080" align="center"><font size="4"><strong>Web Password
    Administration</strong></font></td>
  </tr>
  <tr>
    <td>Please click on &quot;Browse&quot; button to
    select which file you would like to upload and click the
    &quot;Import Passwords&quot; button to update the protected site
    access list. The file used to update the password list must be
    saved as a comma delimited, quote encapsulated ASCII file.&nbsp;
    The file name you use to update the list can be whatever you want
    it to be <b>but the file name cannot include special characters
    such as &amp;, $, !, #, @, %, *, or ^.</b>
    <form enctype="multipart/form-data" action="<? echo $PHP_SELF ?>" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="200000">
        <input type="hidden" name="mode" value="update">
    <p>File to Upload: <input type="file" name="upfile" size="40"
    maxlength="255"></p>
    <div align="center"><input type="submit" value="Import Passwords"></div>
    </form>
    </td>
  </tr>
  <tr>
    <td align="center"><font size="2"><br>
    Please report any problems with this web application to <a
    href="mailto:webmaster <email protected>">webmaster <email protected></a>.</font></td>
  </tr>
</table>
</center></div>
</body>
</html>