Commit graph

7 commits

Author SHA1 Message Date
Thibault Charbonnier
5ab8205859
Fix of wrong zsh extended history (with timestamps) SEGFAULT and parsing #409 (#410)
This patch fixes a segfault when .zsh_history contains commands starting
with `:` and longer than 15 characters long.

Considering the history line:

    : 1592444398:0;:vspman epoll_ctl

The ranked item's line will be:

    :vspman epoll_ctl

When building the prioritized history, we used to apply the zsh extended
history offset if the line starts with `:` (and if the command is longer
than `15`, defined by `ZSH_HISTORY_ITEM_OFFSET`), which then makes the
item point to:

    tl

This makes the `r->item` pointer invalid, which causes the segfault
observed in #408 within `prioritized_history_destroy`.

---

This patch prevents the same issue from arising again (even if the
line is wrongly interpreted) since it avoids any pointer arithmetic
between assignment and freeing.

Additionally, the patch also greatly improves the heuristics used in
determining whether a line is of extended history format or not, since
the non-extended format is also supported by zsh.

---

Fix #410
Fix #399
2020-11-19 07:13:30 +01:00
Martin Dvorak
4976bab73f Polishing sources (copyrights, test refactoring). 2019-12-21 07:53:11 +01:00
Martin Dvorak
4c46770566 HSTR/HH reconciliation in tests. 2018-08-21 17:46:45 +02:00
Martin Dvorak
52726718e4 HH > HSTR rollback. 2018-08-21 17:31:56 +02:00
Martin Dvorak
3d90d463b1 hstr / hh reconciliation. 2018-08-21 11:31:27 +02:00
Martin Dvorak
ade822ff4a Adding Unity C test framework. 2018-08-13 17:02:53 +02:00
Martin Dvorak
742c51c756 Introducing new main() to enable creation of UNIT tests. 2018-08-13 17:02:53 +02:00