#!/bin/bash # # Copyright (C) 2002 by Ketil Froyn # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA # # # Demonstrate segfault in "rm -rf" when the stack runs full # ulimit -s 64 if [ -e aaa ]; then echo "There is a file or directory already called 'aaa' here. Remove it or"; echo "run this script from somewhere else"; exit fi; echo Creating directory structure perl -e 'for ($i=0; $i < 200; $i++) { unless(mkdir("aaa",0777)) { die "Unable to create dirs: $!"; } chdir "aaa"; }' echo -n "Counting directories created...: " perl -e '$i=0; while (-e "aaa") { unless (chdir "aaa") { die "error: $!"; } $i++; } print "$i\n";' echo "Hit enter to continue" head -1 > /dev/null echo Attempting to remove directory structure with rm \(should segfault\) rm -rf aaa echo "Hit enter to continue" head -1 > /dev/null echo Removing directories \(assuming nothing else has been put in there\) perl -e '$i=0; while ( -e "aaa") { $i++; chdir "aaa"; if (-e "core") {unlink "core";} }; chdir ".."; while ($i--) { unless (rmdir "aaa") { die "Unable to rmdir aaa: $!"; } chdir ".."};'