🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #113

Bug#1150294: if HISTFILE is a symlink, history truncation silently breaks

#113
From: Trent W. Buck
Date: Thu, 08 Oct 2026 06:10
152 lines
7510 bytes
This is a multi-part MIME message sent by reportbug.


--===============7071987359477193518==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Package: bash
Version: 5.2.37-2+b10
Severity: minor
File: /usr/bin/bash

I think this is NotABugTM, but I was so surprised I had to write it down/up.
I think the appropriate response is "don't do that, then" and
maybe add a comment in the manpage e.g.

    HISTFILE should point to a regular file, not a symlink

Initially I noticed that every interactive bash process was 85MB RSS.
My ~/.bash_history was 24MB; moving it away fixed bash to be only 6MB RSS.
I increase HISTFILESIZE, but not THAT much.
Its oldest entry was from 2022, when my host was first built.

My ~/.bash_history is a symlink, and
I speculated bash was measuring the length of the symlink and
concluding "it's small enough, nothing to truncate".
i.e. stat vs lstat.

Attached is a test transcript showing truncation is silently skipped
when ~/.bash_history is a symlink to ~/.local/share/bash/history.

Digging through the code, I can't see anything in here:
https://sources.debian.org/src/bash/5.3-4/bashhist.c
I think the underlying issue is in readline:
https://sources.debian.org/src/readline/8.3-4/histfile.c#L572-L581
I think if HISTFILE points to a symlink, readline skips truncation entirely.
However I can't see where bashhist.c ever calls history_truncate_file, so
that may be entirely the wrong function.



-- System Information:
Debian Release: 13.7
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'proposed-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.12.107+deb13-amd64 (SMP w/8 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages bash depends on:
ii  base-files   13.8+deb13u7
ii  debianutils  5.23.2
ii  libc6        2.41-12+deb13u4
ii  libtinfo6    6.5+20250216-2

Versions of packages bash recommends:
ii  bash-completion  1:2.16.0-7

Versions of packages bash suggests:
pn  bash-doc  <none>

-- no debconf information

--===============7071987359477193518==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="bash-histfilesize-transcript.txt"

# First create a completely clean environment, so none of my personal config can cause weirdness.
bash5$ mmdebstrap forky /dev/null --customize-hook='env -i TERM=dumb PATH=/bin:/sbin chroot $1 bash'
I: automatically chosen mode: unshare
I: chroot architecture amd64 is equal to the host's architecture
I: finding correct signed-by value...
done
I: automatically chosen format: null
I: using /tmp/mmdebstrap.tTpw9nfJXg as tempdir
I: running apt-get update...
done
I: downloading packages with apt...
done
I: extracting archives...
done
I: installing essential packages...
done
I: installing remaining packages inside the chroot...
done
done
I: running --customize-hook in shell: sh -c 'env -i TERM=dumb PATH=/bin:/sbin chroot $1 bash' exec /tmp/mmdebstrap.tTpw9nfJXg
root@hera:/# echo echo file was read  >> ~/.bashrc
root@hera:/# echo shopt -s histappend  >> ~/.bashrc
root@hera:/# echo HISTSIZE=3 HISTFILESIZE=5 >> ~/.bashrc
root@hera:/# bash
file was read
root@hera:/# :a
bash: :a: command not found
root@hera:/# : a
root@hera:/# : b
root@hera:/# : c
root@hera:/# : d
root@hera:/# : e
root@hera:/# : f
root@hera:/# exit
exit
root@hera:/# wc -l ~/.bash_history
5 /root/.bash_history
root@hera:/# bash
file was read
root@hera:/# : g
root@hera:/# : h
root@hera:/# exit
root@hera:/# wc -l ~/.bash_history
5 /root/.bash_history
root@hera:/# fmt < ~/.bash_history
: e : f exit : g : h
root@hera:/# mkdir -p ~/.local/share/bash
root@hera:/# mv ~/.bash_history ~/.local/share/bash/history
root@hera:/# ln -s .local/share/bash/history ~/.bash_history
root@hera:/# bash
file was read
root@hera:/# : i
root@hera:/# : j
root@hera:/# : k
root@hera:/# : l
root@hera:/# : m
root@hera:/# exit
exit
root@hera:/# fmt < ~/.bash_history
: e : f exit : g : h : l : m exit
root@hera:/# wc -l ~/.bash_history
8 /root/.bash_history
root@hera:/# # if ~/.bash_history is a symlink, it fails to truncate the file
root@hera:/# mv -b ~/.local/share/bash/history ~/.bash_history
root@hera:/# ls -l ~/.bash_history
-rw------- 1 root root 34 Oct  8 05:05 /root/.bash_history
root@hera:/# bash
file was read
root@hera:/# exit
exit
root@hera:/# ls -l ~/.bash_history
-rw------- 1 root root 22 Oct  8 05:10 /root/.bash_history
root@hera:/# # You can see that going back to a regular file, it gets truncated correctly
root@hera:/# 

--===============7071987359477193518==--
Technical Details
Message-ID: <NLPui-4dxt-3@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod
From: "Trent W. Buck" <trentbuck@gmail.com>
Newsgroups: linux.debian.bugs.dist
Subject: Bug#1150294: if HISTFILE is a symlink, history truncation silently breaks
Date: Thu, 08 Oct 2026 08:10:02 +0200
Message-ID: <NLPui-4dxt-3@gated-at.bofh.it>
X-Original-To: Debian Bug Tracking System <submit@bugs.debian.org>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Thu Oct  8 06:01:13 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: -0.548
Reply-To: "Trent W. Buck" <trentbuck@gmail.com>, 1150294@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: doko@debian.org
X-Debian-Pr-Message: report 1150294
X-Debian-Pr-Package: bash
X-Debian-Pr-Source: bash
X-Gm-Message-State: AFuF++nZDr2BkjZfBNXm1X/ZMbQ3LwcSXUnWgAZ8aCqKnvegYlgjz78I
	h18YAToxkpsLsIkj1gycF7RDQK136pOuuuLoAzizv3uzwvfzdwvJl+KieUte1Q==
X-Gm-Gg: AYBFou0MpS+9LKr6Q5Hjn70MmeBRmpRgOWcXqzQxwY/xCaB9v4Q6DkQQWJkoapWQSxQ
	+YTa+5qhUzsJQlQebQnZJ7sVGqSLrIWEbRmItmqf0HF/V6udKWAC7JDBrfKo9F060I8dyuUdRvJ
	P12o6H4G3pAPjXBVfQ4oz0uFMRw2lX8EjQ1BZz2fw8hKFOZeu1nrGoD439+iAhFUPuJofAMvYn8
	Vpuwahr1b8DSu08YPDlv+X376/Y0dPNbmtnNV00J9QDNYMnOVfg4w+82GLiXy+uLr4dzMJAtJaC
	nGeAhqd1oA/QoVzo94KrKjk3QQESE2j3Dd+i7qDJ18nRSb1xmHMVEAH0ny5Mr7e609B0WkqJlhC
	++1diIZ47sQU4sJSx+n/nCO549xHxIxUXTqE48L2hR5c5e4cOn3gDHHSF5Y3iOB/9Bf/eVHRevf
	d6K3ah7riix0SWiMLAnX9k3I9nnj06qUrPn2zwW89Q0MIadR06fxNZlA0M7QN+Ye5hzday2vUtL
	8M76neHCjM=
X-Received: by 2002:a05:6a20:430a:b0:3dd:85aa:d267 with SMTP id adf61e73a8af0-3e134062b0emr4330196637.31.1791439166623;
        Wed, 07 Oct 2026 22:59:26 -0700 (PDT)
Content-Type: multipart/mixed; boundary="===============7071987359477193518=="
MIME-Version: 1.0
X-Mailer: reportbug 13.2.0
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/1995661
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 152
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Thu, 08 Oct 2026 16:59:19 +1100
X-Original-Message-ID: <179143915927.2801402.5440031542042266481.reportbug@hera>