Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default [Done v155] Uninitialized string offset in function zen_random_name()

    Note: low priority! Received a "PHP Notice: Uninitialized string offset: 26" and many "PHP Notice: String offset cast occurred" while debugging a download problem. The code is in includes/modules/pages/download_header_php.php and has existed since at least version 1.5.1. In function zen_random_name() around line 81 a random number between 1 and 26 is generated to use as an offset in a string of letters from a to z. The random number should be between 0 and 25 I believe, since a sting offset of 0 would be the letter "a" and an offset of 25 would be the letter "z". Changing the arguments of zen_rand from 1,26 to 0,25 should correct the problem.

    The string offset cast is generated because since PHP 5.4, a notice is generated when the string offset is not an integer. Floor generates a float. Perhaps the function intval should replace floor, or enclose the entire expression, or cast with (int). I enclosed the entire expression with intval and the cast offset notices did not reappear.

    Sorry to bother you with such a low priority issue but thought you should know.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Uninitialized string offset in function zen_random_name()

    Agreed. Fortunately it doesn't significantly reduce entropy.

    Corrected code, included in v1.5.5 since the 03-22-2016 zip, reads:
    Code:
    function zen_random_name()
    {
      $letters = 'abcdefghijklmnopqrstuvwxyz';
      $dirname = '.';
      if (defined('DOWNLOADS_SKIP_DOT_PREFIX_ON_REDIRECT') && DOWNLOADS_SKIP_DOT_PREFIX_ON_REDIRECT === TRUE) $dirname = '';
      $length = floor(zen_rand(16,20));
      for ($i = 1; $i <= $length; $i++) {
        $q = floor(zen_rand(0,25));
        $dirname .= $letters[$q];
      }
      return $dirname;
    }
    Affects ZC versions 1.5.2 to 1.5.4 (well, prior versions too, but versions older than v152 don't run properly on PHP 5.4)
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. v151 [Done v1.5.5] PHP 5.4 warnings: Illegal string offset
    By lat9 in forum Bug Reports
    Replies: 38
    Last Post: 28 Dec 2015, 11:13 PM
  2. Illegal string offset 'id' in order.php
    By marcopolo in forum General Questions
    Replies: 16
    Last Post: 25 Jul 2015, 04:31 PM
  3. v151 PHP Warning: Illegal string offset 'id'
    By Nettric in forum Bug Reports
    Replies: 3
    Last Post: 30 May 2014, 06:53 AM
  4. Replies: 1
    Last Post: 30 Sep 2013, 07:39 PM
  5. Replies: 1
    Last Post: 18 Jan 2012, 11:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR