Make WordPress Core

Ticket #47783: 47783-magic_quotes_deprecation-PclZip.patch

File 47783-magic_quotes_deprecation-PclZip.patch, 13.8 KB (added by ayeshrajans, 6 years ago)

Juliette - Thanks you are right PclZip was missing in the patches. This one does it, and it turned out to be a rather big patch because the library had 2 methods to disable and swam back magic quotes functionality. Since this class is from 2009, there is no access indivators. However, I decided to remove the methods themselves and the class property because they started with name priv in properties, and the class property wasn't used anywhere else.

  • src/wp-admin/includes/class-pclzip.php

    diff --git a/src/wp-admin/includes/class-pclzip.php b/src/wp-admin/includes/class-pclzip.php
    index ae0af7a8f1..32fb6b3a36 100644
    a b class PclZip 
    199199    var $error_code = 1;
    200200    var $error_string = '';
    201201
    202     // ----- Current status of the magic_quotes_runtime
    203     // This value store the php configuration for magic_quotes
    204     // The class can then disable the magic_quotes and reset it after
    205     var $magic_quotes_status;
    206 
    207202  // --------------------------------------------------------------------------------
    208203  // Function : PclZip()
    209204  // Description :
    function __construct($p_zipname) 
    224219    // ----- Set the attributes
    225220    $this->zipname = $p_zipname;
    226221    $this->zip_fd = 0;
    227     $this->magic_quotes_status = -1;
    228222
    229223    // ----- Return
    230224    return;
    function delete() 
    10411035      }
    10421036    }
    10431037
    1044     // ----- Magic quotes trick
    1045     $this->privDisableMagicQuotes();
    10461038
    10471039    // ----- Call the delete fct
    10481040    $v_list = array();
    10491041    if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
    1050       $this->privSwapBackMagicQuotes();
    10511042      unset($v_list);
    10521043      return(0);
    10531044    }
    10541045
    1055     // ----- Magic quotes trick
    1056     $this->privSwapBackMagicQuotes();
    1057 
    10581046    // ----- Return
    10591047    return $v_list;
    10601048  }
    function properties() 
    10961084    // ----- Reset the error handler
    10971085    $this->privErrorReset();
    10981086
    1099     // ----- Magic quotes trick
    1100     $this->privDisableMagicQuotes();
    11011087
    11021088    // ----- Check archive
    11031089    if (!$this->privCheckFormat()) {
    1104       $this->privSwapBackMagicQuotes();
    11051090      return(0);
    11061091    }
    11071092
    function properties() 
    11171102      // ----- Open the zip file
    11181103      if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
    11191104      {
    1120         $this->privSwapBackMagicQuotes();
    11211105
    11221106        // ----- Error log
    11231107        PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
    function properties() 
    11301114      $v_central_dir = array();
    11311115      if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
    11321116      {
    1133         $this->privSwapBackMagicQuotes();
    11341117        return 0;
    11351118      }
    11361119
    function properties() 
    11431126      $v_prop['status'] = 'ok';
    11441127    }
    11451128
    1146     // ----- Magic quotes trick
    1147     $this->privSwapBackMagicQuotes();
    11481129
    11491130    // ----- Return
    11501131    return $v_prop;
    function privCreate($p_filedescr_list, &$p_result_list, &$p_options) 
    21312112    $v_result=1;
    21322113    $v_list_detail = array();
    21332114
    2134     // ----- Magic quotes trick
    2135     $this->privDisableMagicQuotes();
    21362115
    21372116    // ----- Open the file in write mode
    21382117    if (($v_result = $this->privOpenFd('wb')) != 1)
    function privCreate($p_filedescr_list, &$p_result_list, &$p_options) 
    21472126    // ----- Close
    21482127    $this->privCloseFd();
    21492128
    2150     // ----- Magic quotes trick
    2151     $this->privSwapBackMagicQuotes();
    2152 
    21532129    // ----- Return
    21542130    return $v_result;
    21552131  }
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    21762152      // ----- Return
    21772153      return $v_result;
    21782154    }
    2179     // ----- Magic quotes trick
    2180     $this->privDisableMagicQuotes();
    21812155
    21822156    // ----- Open the zip file
    21832157    if (($v_result=$this->privOpenFd('rb')) != 1)
    21842158    {
    2185       // ----- Magic quotes trick
    2186       $this->privSwapBackMagicQuotes();
    2187 
    21882159      // ----- Return
    21892160      return $v_result;
    21902161    }
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    21942165    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
    21952166    {
    21962167      $this->privCloseFd();
    2197       $this->privSwapBackMagicQuotes();
    21982168      return $v_result;
    21992169    }
    22002170
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    22082178    if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
    22092179    {
    22102180      $this->privCloseFd();
    2211       $this->privSwapBackMagicQuotes();
    22122181
    22132182      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
    22142183
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    22412210      fclose($v_zip_temp_fd);
    22422211      $this->privCloseFd();
    22432212      @unlink($v_zip_temp_name);
    2244       $this->privSwapBackMagicQuotes();
    22452213
    22462214      // ----- Return
    22472215      return $v_result;
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    22692237          fclose($v_zip_temp_fd);
    22702238          $this->privCloseFd();
    22712239          @unlink($v_zip_temp_name);
    2272           $this->privSwapBackMagicQuotes();
    22732240
    22742241          // ----- Return
    22752242          return $v_result;
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    23012268    {
    23022269      // ----- Reset the file list
    23032270      unset($v_header_list);
    2304       $this->privSwapBackMagicQuotes();
    23052271
    23062272      // ----- Return
    23072273      return $v_result;
    function privAdd($p_filedescr_list, &$p_result_list, &$p_options) 
    23182284    // ----- Close the temporary file
    23192285    @fclose($v_zip_temp_fd);
    23202286
    2321     // ----- Magic quotes trick
    2322     $this->privSwapBackMagicQuotes();
    2323 
    23242287    // ----- Delete the zip file
    23252288    // TBC : I should test the result ...
    23262289    @unlink($this->zipname);
    function privList(&$p_list) 
    31533116  {
    31543117    $v_result=1;
    31553118
    3156     // ----- Magic quotes trick
    3157     $this->privDisableMagicQuotes();
    31583119
    31593120    // ----- Open the zip file
    31603121    if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
    31613122    {
    3162       // ----- Magic quotes trick
    3163       $this->privSwapBackMagicQuotes();
    3164 
    31653123      // ----- Error log
    31663124      PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
    31673125
    function privList(&$p_list) 
    31733131    $v_central_dir = array();
    31743132    if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
    31753133    {
    3176       $this->privSwapBackMagicQuotes();
    31773134      return $v_result;
    31783135    }
    31793136
    function privList(&$p_list) 
    31813138    @rewind($this->zip_fd);
    31823139    if (@fseek($this->zip_fd, $v_central_dir['offset']))
    31833140    {
    3184       $this->privSwapBackMagicQuotes();
    3185 
    31863141      // ----- Error log
    31873142      PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
    31883143
    function privList(&$p_list) 
    31963151      // ----- Read the file header
    31973152      if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
    31983153      {
    3199         $this->privSwapBackMagicQuotes();
    32003154        return $v_result;
    32013155      }
    32023156      $v_header['index'] = $i;
    function privList(&$p_list) 
    32093163    // ----- Close the zip file
    32103164    $this->privCloseFd();
    32113165
    3212     // ----- Magic quotes trick
    3213     $this->privSwapBackMagicQuotes();
    3214 
    32153166    // ----- Return
    32163167    return $v_result;
    32173168  }
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    32793230  {
    32803231    $v_result=1;
    32813232
    3282     // ----- Magic quotes trick
    3283     $this->privDisableMagicQuotes();
    3284 
    32853233    // ----- Check the path
    32863234    if (   ($p_path == "")
    32873235            || (   (substr($p_path, 0, 1) != "/")
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    33093257    // ----- Open the zip file
    33103258    if (($v_result = $this->privOpenFd('rb')) != 1)
    33113259    {
    3312       $this->privSwapBackMagicQuotes();
    33133260      return $v_result;
    33143261    }
    33153262
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    33193266    {
    33203267      // ----- Close the zip file
    33213268      $this->privCloseFd();
    3322       $this->privSwapBackMagicQuotes();
    33233269
    33243270      return $v_result;
    33253271    }
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    33383284      {
    33393285        // ----- Close the zip file
    33403286        $this->privCloseFd();
    3341         $this->privSwapBackMagicQuotes();
    33423287
    33433288        // ----- Error log
    33443289        PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    33533298      {
    33543299        // ----- Close the zip file
    33553300        $this->privCloseFd();
    3356         $this->privSwapBackMagicQuotes();
    33573301
    33583302        return $v_result;
    33593303      }
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    34463390          if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
    34473391                      && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
    34483392
    3449               $this->privSwapBackMagicQuotes();
    3450 
    34513393              PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
    34523394                                               "Filename '".$v_header['stored_filename']."' is "
    34533395                                                           ."compressed by an unsupported compression "
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    34653407          if (   (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
    34663408                      && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
    34673409
    3468               $this->privSwapBackMagicQuotes();
    3469 
    34703410              PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
    34713411                                               "Unsupported encryption for "
    34723412                                                           ." filename '".$v_header['stored_filename']
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    34823422                                                        $p_file_list[$v_nb_extracted++]);
    34833423          if ($v_result != 1) {
    34843424              $this->privCloseFd();
    3485               $this->privSwapBackMagicQuotes();
    34863425              return $v_result;
    34873426          }
    34883427
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35003439          // ----- Close the zip file
    35013440          $this->privCloseFd();
    35023441
    3503           $this->privSwapBackMagicQuotes();
    3504 
    35053442          // ----- Error log
    35063443          PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
    35073444
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35183455          $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
    35193456          if ($v_result1 < 1) {
    35203457            $this->privCloseFd();
    3521             $this->privSwapBackMagicQuotes();
    35223458            return $v_result1;
    35233459          }
    35243460
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35273463          {
    35283464            // ----- Close the zip file
    35293465            $this->privCloseFd();
    3530             $this->privSwapBackMagicQuotes();
    35313466
    35323467            return $v_result;
    35333468          }
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35503485          $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
    35513486          if ($v_result1 < 1) {
    35523487            $this->privCloseFd();
    3553             $this->privSwapBackMagicQuotes();
    35543488            return $v_result1;
    35553489          }
    35563490
    35573491          // ----- Get the only interesting attributes
    35583492          if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
    35593493            $this->privCloseFd();
    3560             $this->privSwapBackMagicQuotes();
    35613494            return $v_result;
    35623495          }
    35633496
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35753508                                                                                          $p_options);
    35763509          if ($v_result1 < 1) {
    35773510            $this->privCloseFd();
    3578             $this->privSwapBackMagicQuotes();
    35793511            return $v_result1;
    35803512          }
    35813513
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35843516          {
    35853517            // ----- Close the zip file
    35863518            $this->privCloseFd();
    3587             $this->privSwapBackMagicQuotes();
    35883519
    35893520            return $v_result;
    35903521          }
    function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all 
    35993530
    36003531    // ----- Close the zip file
    36013532    $this->privCloseFd();
    3602     $this->privSwapBackMagicQuotes();
    36033533
    36043534    // ----- Return
    36053535    return $v_result;
    function privErrorReset() 
    53145244      $this->error_string = '';
    53155245    }
    53165246  }
    5317   // --------------------------------------------------------------------------------
    5318 
    5319   // --------------------------------------------------------------------------------
    5320   // Function : privDisableMagicQuotes()
    5321   // Description :
    5322   // Parameters :
    5323   // Return Values :
    5324   // --------------------------------------------------------------------------------
    5325   function privDisableMagicQuotes()
    5326   {
    5327     $v_result=1;
    5328 
    5329     // ----- Look if function exists
    5330     if (   (!function_exists("get_magic_quotes_runtime"))
    5331             || (!function_exists("set_magic_quotes_runtime"))) {
    5332       return $v_result;
    5333         }
    5334 
    5335     // ----- Look if already done
    5336     if ($this->magic_quotes_status != -1) {
    5337       return $v_result;
    5338         }
    5339 
    5340         // ----- Get and memorize the magic_quote value
    5341         $this->magic_quotes_status = @get_magic_quotes_runtime();
    5342 
    5343         // ----- Disable magic_quotes
    5344         if ($this->magic_quotes_status == 1) {
    5345           @set_magic_quotes_runtime(0);
    5346         }
    5347 
    5348     // ----- Return
    5349     return $v_result;
    5350   }
    5351   // --------------------------------------------------------------------------------
    53525247
    5353   // --------------------------------------------------------------------------------
    5354   // Function : privSwapBackMagicQuotes()
    5355   // Description :
    5356   // Parameters :
    5357   // Return Values :
    5358   // --------------------------------------------------------------------------------
    5359   function privSwapBackMagicQuotes()
    5360   {
    5361     $v_result=1;
    5362 
    5363     // ----- Look if function exists
    5364     if (   (!function_exists("get_magic_quotes_runtime"))
    5365             || (!function_exists("set_magic_quotes_runtime"))) {
    5366       return $v_result;
    5367         }
    5368 
    5369     // ----- Look if something to do
    5370     if ($this->magic_quotes_status != -1) {
    5371       return $v_result;
    5372         }
    5373 
    5374         // ----- Swap back magic_quotes
    5375         if ($this->magic_quotes_status == 1) {
    5376           @set_magic_quotes_runtime($this->magic_quotes_status);
    5377         }
    5378 
    5379     // ----- Return
    5380     return $v_result;
    5381   }
    53825248  // --------------------------------------------------------------------------------
    53835249
    53845250  }