RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 986095 - bash bug, invalid array index of the_history
Summary: bash bug, invalid array index of the_history
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash
Version: 6.4
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Ondrej Oprala
QA Contact: Jan Kepler
URL:
Whiteboard:
Depends On:
Blocks: 1056252 1070830 1126396
TreeView+ depends on / blocked
 
Reported: 2013-07-19 00:55 UTC by Geng Sheng Liu
Modified: 2020-09-09 08:40 UTC (History)
4 users (show)

Fixed In Version: bash-4.1.2-20.el6
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1126396 (view as bug list)
Environment:
Last Closed: 2014-10-14 07:09:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2014:1503 0 normal SHIPPED_LIVE bash bug fix update 2014-10-14 01:28:07 UTC

Description Geng Sheng Liu 2013-07-19 00:55:35 UTC
Description of problem:
I've sent the bug description and fix to bash-bug mail list, please refer to link below.

http://www.mail-archive.com/bug-bash@gnu.org/msg12872.html

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:


http://www.mail-archive.com/bug-bash@gnu.org/msg12872.html

create a new user like jack.

setup the 4 factors to reproduce the problem, user with the following condition would encount this problem.

1.HISTFILESIZE is larger than 0, for example 1000

2.HISTSIZE=0

3..bash_history is not a empty file

4.time stamp is enabled in .bash_history file.

Then we use root user to run su  - jack, bash would hang.

Actual results:

bash hangs there.

Expected results:

we should switch to user jack successfully.


Additional info:

Comment 1 Geng Sheng Liu 2013-07-19 00:56:39 UTC
I did some investigation and I think it should be a bug of bash.


1. if HISTSIZE=0, then the length of array to store history command in memory would be zero.

The global variable the_history[history_length] is the array to store history command, history_length would be set 0 if HISTSIZE=0,

2. if HISTFILESIZE is set to none zero value, for example 1000, bash would truncate .bash_history size to 1000.

    history_truncate_file (".bash_hisotry, 1000);

3. then read_history_range function would be call to put item read from .bash_history file to array the_history[history_length].

    add_history would have this action done,

    void
add_history (string)
     const char *string;
{
  HIST_ENTRY *temp;

  if (history_stifled && (history_length == history_max_entries))
    {
      register int i;

      /* If the history is stifled, and history_length is zero,
         and it equals history_max_entries, we don't save items. */
      if (history_length == 0)
return; <--- we can see that if history_length=0, add_history would return directly, would not add any item.

4. Then it would add try to add timestamp if they are enable in .bash_history.

    if (HIST_TIMESTAMP_START(line_start) == 0)
              {
                add_history (line_start);
                if (last_ts)
                  {
                    add_history_time (last_ts);
                    last_ts = NULL;
                  }
              }

5. Because add_history did not any thing if history_length = 0. and add_history_time would meet a wrong array index exception at

hs = the_history[history_length - 1];

it try to read the_history[-1] which does not exist.


void
add_history_time (string)
     const char *string;
{
  HIST_ENTRY *hs;

  hs = the_history[history_length - 1];
  FREE (hs->timestamp);
  hs->timestamp = savestring (string);
}

6. So the problem happens and shell stops there.

(gdb) where
#0 0x0000000000482027 in add_history_time (string=0x18779b55 "#1357531487") at history.c:322 #1 0x0000000000484d26 in read_history_range (filename=<value optimized out>, from=0, to=4535) at histfile.c:272
#2  0x000000000044de3e in load_history () at bashhist.c:284
#3 0x000000000041b445 in main (argc=<value optimized out>, argv=0x7fff6eee2458, env=0x7fff6eee2468) at shell.c:710
(gdb) f
#0 0x0000000000482027 in add_history_time (string=0x18779b55 "#1357531487") at history.c:322
322      hs = the_history[history_length - 1];

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fix:

We should exit add_history_time if history_length=0.


/* Change the time stamp of the most recent history entry to STRING. */
void
add_history_time (string)
     const char *string;
{
  HIST_ENTRY *hs;

if ( history_length ==0 ) <-----------------------change needs to be done here to avoid invalid array index if history_length=0.
          return;

  hs = the_history[history_length - 1];
  FREE (hs->timestamp);
  hs->timestamp = savestring (string);
}

Gengsheng Liu

RHCE

Redhat GSS Support

Comment 3 RHEL Program Management 2013-10-13 23:22:08 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unable to address this
request at this time.

Red Hat invites you to ask your support representative to
propose this request, if appropriate, in the next release of
Red Hat Enterprise Linux.

Comment 8 errata-xmlrpc 2014-10-14 07:09:48 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1503.html


Note You need to log in before you can comment on or make changes to this bug.