From 6653dfa96f4dde06446fc4eefa1b9fcb56829989 Mon Sep 17 00:00:00 2001 From: Ron Chmara Date: Tue, 5 Sep 2000 01:36:06 +0000 Subject: [PATCH] Updated sample for "/usr/tmp/../../etc/passwd" issue. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@31988 c90b9560-bf6c-de11-be94-00142212c4b1 --- features/file-upload.xml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/features/file-upload.xml b/features/file-upload.xml index 2909edcf1f..7815232d9e 100644 --- a/features/file-upload.xml +++ b/features/file-upload.xml @@ -80,10 +80,20 @@ Send this file: <INPUT NAME="userfile" TYPE="file"> Validating file uploads. <? -$validtmpdir = get_cfg_var("upload_tmp_dir"); -/* make sure you're using an uploaded file */ -if (strstr ("$validtmpdir", "$userfile") != 0){ - copy ("$userfile" "/place/to/put/uploaded/file"); +$validtmpdir = get_cfg_var("upload_tmp_dir"); +// get the path + +$uploaded_path_array = spilt("/","$userfile"); +//split the upload name into its components + +$inverted_path = array_reverse ($uploaded_path_array); +// reverse the array, so any ending pathname will now be first + +$accurate_pathname = "$validtmpdir" . "$inverted_path[0]"; + +if (file_exists($accurate_pathname )){ +//still look for proper temp name + copy ("$accurate_pathname", "/place/to/put/uploaded/file"); } else { echo "Not an uploaded file!"; exit;