Apple recenetly released a new version of iTunes, a program for Mac users to make their own music, to the world last weekend (11/2). However, those that rushed to install this update found that not only did the update not work, but it completely wiped out their hard drives. Apple quickly pulled this version, and rereleased a new version that behaved as expected.
The problem? According to posts on the Slashdot report, it had to do with the Unix underpinings of Mac OS X. Specifically, the installed ran a unix batch file which contained the following:
The values of $1 and $2 were filled in with path information based the OS finding the location of the previous version of iTunes. Certainly nothing terribly wrong with this, but remember that on Macs, it's very common to name folders with spaced embedded in them. If either $1 or $2 had a space, the script would execute normally but could easily delete much of the system.#!/bin/sh # if current iTunes pkg exists, delete it b/c of Installer bug if [ -e $1Library/Receipts/iTunes.pkg ] ; then rm -rf $1Library/Receipts/iTunes.pkg 2> /dev/null fi # if iTunes application currently exists, delete it if [ -e $2Applications/iTunes.app ] ; then rm -rf $2Applications/iTunes.app 2> /dev/null fi
The solution was easy: simply quote the file names to check existance and deletion on.
Relating this to perl, whenever you do system/exec commands in which you are specifying file names that might come from an tainted source, or even if they aren't untained, it's typically always a good idea to quote the filename to prevent any special characters from getting in the way. For example:
And it's nearly always better to use any perl builtin functions over system commands if they perform the same task (eg unlink $file vs system("rm -rf $file")$file = "testdir /"; #oops, typo! system( "rm -rf $file" ); #double oops system( "rm -rf '$file'" ); #will probably get an error # from the command, but your # root dir is still there.
-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com
||
"You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important
In reply to Apple, quoting, and system() by Masem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |