PHP 7 and comments in .cfg files


Squid

Recommended Posts

With PHP 7 now included with 6.2RC3, there exists a potential issue with regards to the generated .cfg files stored on the flash drive.

 

These files are all headed by a comment line such as

# Generated settings:

 

Parsing these .cfg files via php's built-in parse_ini_file (or parse_ini_string) could potentially cause issues because during php5, comments starting with # was deprecated (but still accepted), and now via php7 they are no longer treated as comments (http://php.net/manual/en/function.parse-ini-file.php)

 

My concern is that while those lines do not currently *appear* to cause any ill effects and are still processed  under php7 as before, this may change in the future patches to php and may bring strange issues to those processes which use parse_ini_file against .cfg files stored on the flash drive.

 

Quick (very quick) searches of what's currently in my plugin directory reveal that some plugins which may be affected by this are

 

Preclear_disk

Community Applications

and, more worryingly dynamix.vm.manager

 

all of which access the .cfg files through parse_ini_file.  This is just what I have installed on my system, and only takes into account those routines that have the /boot/config/xxx.cfg file directly referenced, and not using a variable which may or may not reference those files.

 

Unfortunately, many other routines may also access those .cfg files through bash, so the simple solution of simply changing the comment character from a # to the accepted ; brings in even more complications.

 

Since none of my processes access those .cfg files via bash, I believe that unRaid should bring those .cfg files into compliance with what is accepted by php to avoid possible problems in the future if/when the authors of php decide to actually enforce their specification.

 

Probably the absolute easiest solution that will conform with both php and bash routines would be to simply remove the comment line at the start and leave it at that.

 

 

 

Link to comment

unRAID (emhttp) itself uses bash shell to read the .cfg files. Changing a hash character for a semi-colon character won't work here.

 

Some quick testing shows that at the moment there is no negative impact when reading a file with a # comment line using the parse_ini_file function of PHP.

 

Safest solution would be to not include comments in the .cfg files though.

 

Link to comment

It'll probably mess up if there's ever an = in the comments but why take the chance.

 

(and the # sign signifying a comment has been deprecated but still functional since php5 -> i.e. plenty of warning was given before they now disallow it according to spec)

 

Sent from my LG-D852 using Tapatalk

 

Link to comment

The best solution is going to be avoiding the use of parse_ini_file() and parse_ini_string() and instead write wrapper functions, maybe my_parse_ini_flile() and my_parse_ini_string() which will filter out lines that being with hash.  Sure it would be nice to switch comments in cfg files to semi-colons, or eliminate comment support, or go back in time and do something different, but there are lots and lots of servers out there and cases where people downgrade for one reason or another.  Messing with cfg file API is not a good idea.

Link to comment

function my_parse_ini_file($file,$mode=false,$scanner_mode=INI_SCANNER_NORMAL) {
  return parse_ini_string(preg_replace('/^#.*\\n/m', "", @file_get_contents($file)),$mode,$scanner_mode);
}

function my_parse_ini_string($string, $mode=false,$scanner_mode=INI_SCANNER_NORMAL) {
  return parse_ini_string(preg_replace('/^#.*\\n/m', "", $string),$mode,$scanner_mode);
}

EDIT: forgot about the process sections flag

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.