This bug is there for a long time

Version: 8.2-rc4
OS: Linux, Ubuntu 22, amd64
Description:

The function replace_history_entry() doesn't check for NULL at line
history.c:400

  temp->line = savestring (line);
  temp->data = data;
  ----> temp->timestamp = savestring (old_value->timestamp); <<-----------
  the_history[which] = temp;

If the timestamp is NULL, it causes SIGSEGV. However, there are many checks
in other functions, for example, the function copy_history_entry() has such
a check, and the function history_get_time()  checks timestamp for NULL as
well, so I can assume that timestamp can be NULL. Unfortunately, this
function is specially called from readline_internal_teardown() which makes
use of timestamps mandatory.

Reproduction steps:

1] Forge own HISTSTATE with history allocated using alloc_history_entry,
passing NULL as a timestamp.
2] use history_set_history_state for your state
3] call readline()
4] choose any history item, modify it and press enter
5] SIGSEGV

Fix:
temp->timestamp = old_value->timestamp?savestring (old_value->timestamp):0;

Ondřej Novák

Reply via email to