[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Infinite loop in bash

From: Jörg Schön
Subject: Infinite loop in bash
Date: Tue, 11 Sep 2001 22:42:49 +0200

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux
Compiler: gcc -I/usr/src/packages/BUILD/bash-2.05
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux' -DCONF_MACHTYPE='i386-suse-linux' -DCONF_VENDOR='suse' 
-DSHELL -DHAVE_CONFIG_H  -D_FILE_OFFSET_BITS=64  -I. -I/usr/include -I. 
-I./include -I./lib -I/usr/include -O2 -m486 -mcpu=i486 -march=i486 
-D_GNU_SOURCE -Wall -pipe
uname output: Linux obelix 2.4.4 #11 Wed Aug 15 19:43:11 CEST 2001 i686 unknown
Machine Type: i386-suse-linux

Bash Version: 2.05
Patch Level: 0
Release Status: release

        A complicated shell script of mine with a lot of functions and recursive
        calls hangs once in a while in an infinite loop.
        I discovered that in these cases a file "/tmp/sh-thd-0" appears.

        Difficult, since my shell script needs the whole environment of my HOME
        directory. Though I couldn't present a simple case that reproduces the
        bug, I present the cause and a fix below.

        Source code of "bash-2.05/lib/sh/tmpfile.c", routine "sh_mktmpfd",
        lines 121-122 and as well line 156 - 157:

      filenum *= (int)time ((time_t *)0) * dollar_dollar_pid *
                ((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);

        For large values of "time()", "dollar_dollar_pid" and 
        filenum becomes "0" after the multiplication. Since the routine is 
        for an unused file in this routine, using "filenum" as the extension, 
this perpetually
        continues. Result: The shell hangs in an infinite loop!

        SOLUTION: Add a line immediately after that like:

     if(filenum == 0) filenum = 4711;

        or replace the multiplication with something that does not overflow like
        "filenum += ...".

      @ @
  Joerg Schoen; Giessener Str. 6; D-35415 Pohlheim; GERMANY
  PHONE: +49-6403-978580  EMAIL: address@hidden
  WWW: http://home.t-online.de/home/JoergSilkeSchoen

reply via email to

[Prev in Thread] Current Thread [Next in Thread]