xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit 9d4b1415698f8ef27d4f6e278144be3c173a5001

Fixed #163 - buffer overflow in regexp matching. Kudos goes to @phcyso for providing data allowing to reproduce this bug!
Author: Martin Dvorak
Author date (UTC): 2015-11-25 20:20
Committer name: Martin Dvorak
Committer date (UTC): 2015-11-25 20:20
Parent(s): a29bc5e8777b85fe77eb56bf2ed0419b7faeebb0
Signing key:
Tree: d33ee85b0ad1a2b929fc56087756fd3587d173c3
File Lines added Lines deleted
src/hstr.c 7 4
tests/test_bug163.sh 12 0
File src/hstr.c changed (mode: 100644) (index 87e782a..dfe29fb)
... ... char *hstr_print_selection(unsigned maxHistoryItems, char *pattern, Hstr *hstr)
715 715 move(Y_OFFSET_ITEMS, 0); move(Y_OFFSET_ITEMS, 0);
716 716 clrtobot(); clrtobot();
717 717
718 int start, end;
718 int start, count;
719 719 char screenLine[CMDLINE_LNG]; char screenLine[CMDLINE_LNG];
720 720 for (i = 0; i<height; ++i) { for (i = 0; i<height; ++i) {
721 721 if(i<hstr->selectionSize) { if(i<hstr->selectionSize) {
 
... ... char *hstr_print_selection(unsigned maxHistoryItems, char *pattern, Hstr *hstr)
723 723 if(pattern && strlen(pattern)) { if(pattern && strlen(pattern)) {
724 724 if(hstr->historyMatch==HH_MATCH_REGEXP) { if(hstr->historyMatch==HH_MATCH_REGEXP) {
725 725 start=hstr->selectionRegexpMatch[i].rm_so; start=hstr->selectionRegexpMatch[i].rm_so;
726 end=hstr->selectionRegexpMatch[i].rm_eo-start;
726 count=hstr->selectionRegexpMatch[i].rm_eo-start;
727 if(count>CMDLINE_LNG) {
728 count=CMDLINE_LNG-1;
729 }
727 730 strncpy(screenLine, strncpy(screenLine,
728 731 hstr->selection[i]+start, hstr->selection[i]+start,
729 end);
730 screenLine[end]=0;
732 count);
733 screenLine[count]=0;
731 734 } else { } else {
732 735 strcpy(screenLine, pattern); strcpy(screenLine, pattern);
733 736 } }
File tests/test_bug163.sh added (mode: 100755) (index 0000000..21897be)
1 #!/bin/bash
2
3 export HH_CONFIG=hicolor,regexp
4 export HISTFILE=/tmp/hh-bug-163
5
6 cp -vf ~/p/hstr/.bash_history_BUG_163 ${HISTFILE}
7
8 #cd ~/p/hstr/github/hstr/Debug && gdbserver :9999 ./hh
9 cd ~/p/hstr/github/hstr/Debug && ./hh
10 #hh
11
12 # eof
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master