fix for completing quoted filenames with show-all-if-ambiguous set; avoid signed int overflow in intrand32

This commit is contained in:
Chet Ramey
2023-01-10 10:23:14 -05:00
parent 8fd8cd8f7b
commit 0647e53bd1
8 changed files with 83 additions and 18 deletions
+17 -1
View File
@@ -2037,9 +2037,25 @@ rl_complete_internal (int what_to_do)
text = rl_copy_text (start, end);
matches = gen_completion_matches (text, start, end, our_func, found_quote, quote_char);
/* If TEXT contains quote characters, it will be dequoted as part of
generating the matches, and the matches will not contain any quote
characters. We need to dequote TEXT before performing the comparison.
Since compare_match performs the dequoting, and we only want to do it
once, we don't call compare_matches after dequoting TEXT; we call
strcmp directly. */
/* nontrivial_lcd is set if the common prefix adds something to the word
being completed. */
nontrivial_lcd = matches && compare_match (text, matches[0]) != 0;
if (rl_filename_completion_desired && rl_filename_quoting_desired &&
rl_completion_found_quote && rl_filename_dequoting_function)
{
char *t;
t = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
xfree (text);
text = t;
nontrivial_lcd = matches && strcmp (text, matches[0]) != 0;
}
else
nontrivial_lcd = matches && strcmp (text, matches[0]) != 0;
if (what_to_do == '!' || what_to_do == '@')
tlen = strlen (text);
xfree (text);
+2 -2
View File
@@ -1,6 +1,6 @@
/* random.c -- Functions for managing 16-bit and 32-bit random numbers. */
/* Copyright (C) 2020,2022 Free Software Foundation, Inc.
/* Copyright (C) 2020,2022,2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -75,7 +75,7 @@ intrand32 (u_bits32_t last)
/* Can't seed with 0. */
ret = (last == 0) ? 123459876 : last;
h = ret / 127773;
l = ret - (127773 * h);
l = ret % 127773;
t = 16807 * l - 2836 * h;
ret = (t < 0) ? t + 0x7fffffff : t;