[Top][All Lists]

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

printf %(fmt)T fails with large times in 64-bit linux.

From: Eduardo A . Bustamante López
Subject: printf %(fmt)T fails with large times in 64-bit linux.
Date: Mon, 17 Sep 2012 01:33:46 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

printf %(fmt)T fails when the time given is very large in a 64-bit linux
environment. Looping over the powers of two and feeding it to printf shows
the error, which exits the shell with a SIGSEGV

The problem seems to be in builtins/printf.def, as indicated by the backtrace
attached (gdb.txt).


I'm running the latest bash from the git repository:

    $ echo $BASH_VERSION

    $ uname -a
    Linux claret 3.4.2-2-ARCH #1 SMP PREEMPT Mon Jun 11 22:27:17 CEST 2012
    x86_64 GNU/Linux

    $ lsb_release -a
    LSB Version:    n/a
    Distributor ID: archlinux
    Description:    Arch Linux
    Release:    rolling
    Codename:   n/a


The following snippet reproduces the problem:

    for i in {56..63}; do
    printf '%s ' $i;
    bash -c 'printf %\(%s\)T\\n $((2**$1))' _ $i;

Sample run:

    $ for i in {56..63}; do
    >     printf '%s ' $i;
    >     bash -c 'printf %\(%s\)T\\n $((2**$1))' _ $i;
    >     done
    56 Segmentation fault
    57 Segmentation fault
    58 Segmentation fault
    59 Segmentation fault
    60 Segmentation fault
    61 Segmentation fault
    62 Segmentation fault
    63 Segmentation fault


The simple fix is to check if ``tm == NULL``, and show an error message, or
default to some specific value. A 32-bit machine seems to handle overflow as a
zero. I guess defaulting to zero is one option. I'm not sure which one is the
best approach.

I'm attaching the diff generated by git. It just checks if tm is NULL, and
defaults to zero, but it is only to demonstrate that the bug is there, the code
isn't written correctly.

Eduardo A. Bustamante López

Attachment: gdb.txt
Description: Text document

Attachment: localtime.diff
Description: Text document

reply via email to

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