fix mem leak with local BASH_REMATCH

This commit is contained in:
Chet Ramey
2022-06-03 11:33:35 -04:00
parent eed646cc60
commit ebeba87477
16 changed files with 3081 additions and 2932 deletions
+26
View File
@@ -3644,3 +3644,29 @@ builtins/Makefile.in
shell pid in the filename ($$RECPID).
Inspired by Alexander Kanavin <alex.kanavin@gmail.com> via
https://savannah.gnu.org/patch/?10210
6/2
---
builtins/common.c
- builtin_find_indexed_array: new function, factored common code out
of mapfile and read builtins to find an in-scope indexed array or
create one
builtins/common.h
- builtin_find_indexed_array: extern declaration
builtins/{mapfile,read}.def
- change callers to use builtin_find_indexed_array
variables.c
- unbind_global_variable, unbind_global_variable_noref: new functions
that remove variables from the global_variables table
lib/sh/shmatch.c
- sh_regmatch: use unbind_global_variable_noref to make sure we act on
the copy of BASH_REMATCH in the global scope all the time, ignoring
any local variables that might exist. Tentative fix for memory leak
report from Emanuele Torre <torreemanuele6@gmail.com>
doc/{bash.1,bashref.texi}
- BASH_REMATCH: add caveat about making it a local variable
+33
View File
@@ -1024,6 +1024,39 @@ builtin_bind_var_to_int (name, val, flags)
return v;
}
#if defined (ARRAY_VARS)
SHELL_VAR *
builtin_find_indexed_array (array_name, flags)
char *array_name;
int flags;
{
SHELL_VAR *entry;
if ((flags & 2) && legal_identifier (array_name) == 0)
{
sh_invalidid (array_name);
return (SHELL_VAR *)NULL;
}
entry = find_or_make_array_variable (array_name, 1);
/* With flags argument & 1, find_or_make_array_variable checks for readonly
and noassign variables and prints error messages. */
if (entry == 0)
return entry;
else if (array_p (entry) == 0)
{
builtin_error (_("%s: not an indexed array"), array_name);
return (SHELL_VAR *)NULL;
}
else if (invisible_p (entry))
VUNSETATTR (entry, att_invisible); /* no longer invisible */
if (flags & 1)
array_flush (array_cell (entry));
return entry;
}
#endif /* ARRAY_VARS */
/* Like check_unbind_variable, but for use by builtins (only matters for
error messages). */
int
+1
View File
@@ -235,6 +235,7 @@ extern SHELL_VAR *builtin_bind_variable PARAMS((char *, char *, int));
extern SHELL_VAR *builtin_bind_var_to_int PARAMS((char *, intmax_t, int));
extern int builtin_unbind_variable PARAMS((const char *));
extern SHELL_VAR *builtin_find_indexed_array PARAMS((char *, int));
extern int builtin_arrayref_flags PARAMS((WORD_DESC *, int));
/* variables from evalfile.c */
+3 -18
View File
@@ -167,24 +167,9 @@ mapfile (fd, line_count_goal, origin, nskip, callback_quantum, callback, array_n
/* The following check should be done before reading any lines. Doing it
here allows us to call bind_array_element instead of bind_array_variable
and skip the variable lookup on every call. */
entry = find_or_make_array_variable (array_name, 1);
if (entry == 0 || readonly_p (entry) || noassign_p (entry))
{
if (entry && readonly_p (entry))
err_readonly (array_name);
return (EXECUTION_FAILURE);
}
else if (array_p (entry) == 0)
{
builtin_error (_("%s: not an indexed array"), array_name);
return (EXECUTION_FAILURE);
}
else if (invisible_p (entry))
VUNSETATTR (entry, att_invisible); /* no longer invisible */
if (flags & MAPF_CLEARARRAY)
array_flush (array_cell (entry));
entry = builtin_find_indexed_array (array_name, flags & MAPF_CLEARARRAY);
if (entry == 0)
return EXECUTION_FAILURE;
#ifndef __CYGWIN__
/* If the delimiter is a newline, turn on unbuffered reads for pipes
+3 -17
View File
@@ -869,28 +869,14 @@ assign_vars:
an assign them to `arrayname' in turn. */
if (arrayname)
{
if (legal_identifier (arrayname) == 0)
{
sh_invalidid (arrayname);
free (input_string);
return (EXECUTION_FAILURE);
}
var = find_or_make_array_variable (arrayname, 1);
/* pass 1 for flags arg to clear the existing array + 2 to check for a
valid identifier. */
var = builtin_find_indexed_array (arrayname, 3);
if (var == 0)
{
free (input_string);
return EXECUTION_FAILURE; /* readonly or noassign */
}
if (assoc_p (var))
{
builtin_error (_("%s: cannot convert associative to indexed array"), arrayname);
free (input_string);
return EXECUTION_FAILURE; /* existing associative array */
}
else if (invisible_p (var))
VUNSETATTR (var, att_invisible);
array_flush (array_cell (var));
alist = list_string (input_string, ifs_chars, 0);
if (alist)
+4 -2
View File
@@ -415,7 +415,9 @@ SSHHEELLLL GGRRAAMMMMAARR
Substrings matched by parenthesized subexpressions within the
regular expression are saved in the remaining BBAASSHH__RREEMMAATTCCHH in-
dices. The element of BBAASSHH__RREEMMAATTCCHH with index _n is the portion
of the string matching the _nth parenthesized subexpression.
of the string matching the _nth parenthesized subexpression.
Bash sets BBAASSHH__RREEMMAATTCCHH in the global scope; declaring it as a
local variable will lead to unexpected results.
Expressions may be combined using the following operators,
listed in decreasing order of precedence:
@@ -6645,4 +6647,4 @@ BBUUGGSS
GNU Bash 5.2 2022 May 17 BASH(1)
GNU Bash 5.2 2022 June 3 BASH(1)
+7 -2
View File
@@ -5,12 +5,12 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Tue May 17 09:34:43 EDT 2022
.\" Last Change: Fri Jun 3 10:47:26 EDT 2022
.\"
.\" bash_builtins, strip all but Built-Ins section
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2022 May 17" "GNU Bash 5.2"
.TH BASH 1 "2022 June 3" "GNU Bash 5.2"
.\"
.\" There's some problem with having a `@'
.\" in a tagged paragraph with the BSD man macros.
@@ -791,6 +791,11 @@ indices. The element of
.B BASH_REMATCH
with index \fIn\fP is the portion of the
string matching the \fIn\fPth parenthesized subexpression.
Bash sets
.SM
.B BASH_REMATCH
in the global scope; declaring it as a local variable will lead to
unexpected results.
.if t .sp 0.5
.if n .sp 1
Expressions may be combined using the following operators, listed
+153 -146
View File
@@ -1,9 +1,9 @@
This is bash.info, produced by makeinfo version 6.8 from bashref.texi.
This text is a brief description of the features that are present in the
Bash shell (version 5.2, 2 May 2022).
Bash shell (version 5.2, 3 June 2022).
This is Edition 5.2, last updated 2 May 2022, of 'The GNU Bash
This is Edition 5.2, last updated 3 June 2022, of 'The GNU Bash
Reference Manual', for 'Bash', Version 5.2.
Copyright (C) 1988-2022 Free Software Foundation, Inc.
@@ -26,10 +26,10 @@ Bash Features
*************
This text is a brief description of the features that are present in the
Bash shell (version 5.2, 2 May 2022). The Bash home page is
Bash shell (version 5.2, 3 June 2022). The Bash home page is
<http://www.gnu.org/software/bash/>.
This is Edition 5.2, last updated 2 May 2022, of 'The GNU Bash
This is Edition 5.2, last updated 3 June 2022, of 'The GNU Bash
Reference Manual', for 'Bash', Version 5.2.
Bash contains features that appear in other popular shells, and some
@@ -1144,6 +1144,9 @@ File: bash.info, Node: Conditional Constructs, Next: Command Grouping, Prev:
is the portion of the string matching the Nth parenthesized
subexpression.
Bash sets 'BASH_REMATCH' in the global scope; declaring it as a
local variable will lead to unexpected results.
Expressions may be combined using the following operators, listed
in decreasing order of precedence:
@@ -6148,14 +6151,15 @@ Invoked by remote shell daemon
..............................
Bash attempts to determine when it is being run with its standard input
connected to a network connection, as when executed by the remote shell
daemon, usually 'rshd', or the secure shell daemon 'sshd'. If Bash
determines it is being run in this fashion, it reads and executes
commands from '~/.bashrc', if that file exists and is readable. It will
not do this if invoked as 'sh'. The '--norc' option may be used to
inhibit this behavior, and the '--rcfile' option may be used to force
another file to be read, but neither 'rshd' nor 'sshd' generally invoke
the shell with those options or allow them to be specified.
connected to a network connection, as when executed by the historical
remote shell daemon, usually 'rshd', or the secure shell daemon 'sshd'.
If Bash determines it is being run non-interactively in this fashion, it
reads and executes commands from '~/.bashrc', if that file exists and is
readable. It will not do this if invoked as 'sh'. The '--norc' option
may be used to inhibit this behavior, and the '--rcfile' option may be
used to force another file to be read, but neither 'rshd' nor 'sshd'
generally invoke the shell with those options or allow them to be
specified.
Invoked with unequal effective and real UID/GIDs
................................................
@@ -7652,8 +7656,11 @@ File: bash.info, Node: Job Control Builtins, Next: Job Control Variables, Pre
suspend [-f]
Suspend the execution of this shell until it receives a 'SIGCONT'
signal. A login shell cannot be suspended; the '-f' option can be
used to override this and force the suspension.
signal. A login shell, or a shell without job control enabled,
cannot be suspended; the '-f' option can be used to override this
and force the suspension. The return status is 0 unless the shell
is a login shell or job control is not enabled and '-f' is not
supplied.
When job control is not active, the 'kill' and 'wait' builtins do not
accept JOBSPEC arguments. They must be supplied process IDs.
@@ -12501,138 +12508,138 @@ D.5 Concept Index

Tag Table:
Node: Top882
Node: Introduction2787
Node: What is Bash?3000
Node: What is a shell?4111
Node: Definitions6646
Node: Basic Shell Features9594
Node: Shell Syntax10810
Node: Shell Operation11833
Node: Quoting13123
Node: Escape Character14424
Node: Single Quotes14906
Node: Double Quotes15251
Node: ANSI-C Quoting16526
Node: Locale Translation17833
Node: Creating Internationalized Scripts19141
Node: Comments23255
Node: Shell Commands23870
Node: Reserved Words24805
Node: Simple Commands25558
Node: Pipelines26209
Node: Lists29205
Node: Compound Commands30997
Node: Looping Constructs32006
Node: Conditional Constructs34498
Node: Command Grouping48839
Node: Coprocesses50314
Node: GNU Parallel52974
Node: Shell Functions53888
Node: Shell Parameters61770
Node: Positional Parameters66155
Node: Special Parameters67054
Node: Shell Expansions70265
Node: Brace Expansion72389
Node: Tilde Expansion75120
Node: Shell Parameter Expansion77738
Node: Command Substitution96086
Node: Arithmetic Expansion97438
Node: Process Substitution98403
Node: Word Splitting99520
Node: Filename Expansion101461
Node: Pattern Matching104207
Node: Quote Removal108861
Node: Redirections109153
Node: Executing Commands118810
Node: Simple Command Expansion119477
Node: Command Search and Execution121584
Node: Command Execution Environment123959
Node: Environment126991
Node: Exit Status128651
Node: Signals130432
Node: Shell Scripts133878
Node: Shell Builtin Commands136902
Node: Bourne Shell Builtins138937
Node: Bash Builtins160395
Node: Modifying Shell Behavior191248
Node: The Set Builtin191590
Node: The Shopt Builtin202188
Node: Special Builtins218097
Node: Shell Variables219073
Node: Bourne Shell Variables219507
Node: Bash Variables221608
Node: Bash Features254421
Node: Invoking Bash255431
Node: Bash Startup Files261441
Node: Interactive Shells266541
Node: What is an Interactive Shell?266948
Node: Is this Shell Interactive?267594
Node: Interactive Shell Behavior268406
Node: Bash Conditional Expressions272032
Node: Shell Arithmetic276671
Node: Aliases279612
Node: Arrays282222
Node: The Directory Stack288610
Node: Directory Stack Builtins289391
Node: Controlling the Prompt293648
Node: The Restricted Shell296610
Node: Bash POSIX Mode299217
Node: Shell Compatibility Mode311138
Node: Job Control319164
Node: Job Control Basics319621
Node: Job Control Builtins324620
Node: Job Control Variables330017
Node: Command Line Editing331170
Node: Introduction and Notation332838
Node: Readline Interaction334458
Node: Readline Bare Essentials335646
Node: Readline Movement Commands337426
Node: Readline Killing Commands338383
Node: Readline Arguments340298
Node: Searching341339
Node: Readline Init File343522
Node: Readline Init File Syntax344780
Node: Conditional Init Constructs367976
Node: Sample Init File372169
Node: Bindable Readline Commands375290
Node: Commands For Moving376491
Node: Commands For History378539
Node: Commands For Text383530
Node: Commands For Killing387176
Node: Numeric Arguments390206
Node: Commands For Completion391342
Node: Keyboard Macros395530
Node: Miscellaneous Commands396214
Node: Readline vi Mode402150
Node: Programmable Completion403054
Node: Programmable Completion Builtins410831
Node: A Programmable Completion Example421523
Node: Using History Interactively426767
Node: Bash History Facilities427448
Node: Bash History Builtins430450
Node: History Interaction435455
Node: Event Designators439072
Node: Word Designators440423
Node: Modifiers442180
Node: Installing Bash443988
Node: Basic Installation445122
Node: Compilers and Options448841
Node: Compiling For Multiple Architectures449579
Node: Installation Names451269
Node: Specifying the System Type453375
Node: Sharing Defaults454088
Node: Operation Controls454758
Node: Optional Features455713
Node: Reporting Bugs466928
Node: Major Differences From The Bourne Shell468200
Node: GNU Free Documentation License485047
Node: Indexes510221
Node: Builtin Index510672
Node: Reserved Word Index517496
Node: Variable Index519941
Node: Function Index536712
Node: Concept Index550493
Node: Top884
Node: Introduction2791
Node: What is Bash?3004
Node: What is a shell?4115
Node: Definitions6650
Node: Basic Shell Features9598
Node: Shell Syntax10814
Node: Shell Operation11837
Node: Quoting13127
Node: Escape Character14428
Node: Single Quotes14910
Node: Double Quotes15255
Node: ANSI-C Quoting16530
Node: Locale Translation17837
Node: Creating Internationalized Scripts19145
Node: Comments23259
Node: Shell Commands23874
Node: Reserved Words24809
Node: Simple Commands25562
Node: Pipelines26213
Node: Lists29209
Node: Compound Commands31001
Node: Looping Constructs32010
Node: Conditional Constructs34502
Node: Command Grouping48966
Node: Coprocesses50441
Node: GNU Parallel53101
Node: Shell Functions54015
Node: Shell Parameters61897
Node: Positional Parameters66282
Node: Special Parameters67181
Node: Shell Expansions70392
Node: Brace Expansion72516
Node: Tilde Expansion75247
Node: Shell Parameter Expansion77865
Node: Command Substitution96213
Node: Arithmetic Expansion97565
Node: Process Substitution98530
Node: Word Splitting99647
Node: Filename Expansion101588
Node: Pattern Matching104334
Node: Quote Removal108988
Node: Redirections109280
Node: Executing Commands118937
Node: Simple Command Expansion119604
Node: Command Search and Execution121711
Node: Command Execution Environment124086
Node: Environment127118
Node: Exit Status128778
Node: Signals130559
Node: Shell Scripts134005
Node: Shell Builtin Commands137029
Node: Bourne Shell Builtins139064
Node: Bash Builtins160522
Node: Modifying Shell Behavior191375
Node: The Set Builtin191717
Node: The Shopt Builtin202315
Node: Special Builtins218224
Node: Shell Variables219200
Node: Bourne Shell Variables219634
Node: Bash Variables221735
Node: Bash Features254548
Node: Invoking Bash255558
Node: Bash Startup Files261568
Node: Interactive Shells266696
Node: What is an Interactive Shell?267103
Node: Is this Shell Interactive?267749
Node: Interactive Shell Behavior268561
Node: Bash Conditional Expressions272187
Node: Shell Arithmetic276826
Node: Aliases279767
Node: Arrays282377
Node: The Directory Stack288765
Node: Directory Stack Builtins289546
Node: Controlling the Prompt293803
Node: The Restricted Shell296765
Node: Bash POSIX Mode299372
Node: Shell Compatibility Mode311293
Node: Job Control319319
Node: Job Control Basics319776
Node: Job Control Builtins324775
Node: Job Control Variables330342
Node: Command Line Editing331495
Node: Introduction and Notation333163
Node: Readline Interaction334783
Node: Readline Bare Essentials335971
Node: Readline Movement Commands337751
Node: Readline Killing Commands338708
Node: Readline Arguments340623
Node: Searching341664
Node: Readline Init File343847
Node: Readline Init File Syntax345105
Node: Conditional Init Constructs368301
Node: Sample Init File372494
Node: Bindable Readline Commands375615
Node: Commands For Moving376816
Node: Commands For History378864
Node: Commands For Text383855
Node: Commands For Killing387501
Node: Numeric Arguments390531
Node: Commands For Completion391667
Node: Keyboard Macros395855
Node: Miscellaneous Commands396539
Node: Readline vi Mode402475
Node: Programmable Completion403379
Node: Programmable Completion Builtins411156
Node: A Programmable Completion Example421848
Node: Using History Interactively427092
Node: Bash History Facilities427773
Node: Bash History Builtins430775
Node: History Interaction435780
Node: Event Designators439397
Node: Word Designators440748
Node: Modifiers442505
Node: Installing Bash444313
Node: Basic Installation445447
Node: Compilers and Options449166
Node: Compiling For Multiple Architectures449904
Node: Installation Names451594
Node: Specifying the System Type453700
Node: Sharing Defaults454413
Node: Operation Controls455083
Node: Optional Features456038
Node: Reporting Bugs467253
Node: Major Differences From The Bourne Shell468525
Node: GNU Free Documentation License485372
Node: Indexes510546
Node: Builtin Index510997
Node: Reserved Word Index517821
Node: Variable Index520266
Node: Function Index537037
Node: Concept Index550818

End Tag Table
+115 -112
View File
@@ -2,9 +2,9 @@ This is bashref.info, produced by makeinfo version 6.8 from
bashref.texi.
This text is a brief description of the features that are present in the
Bash shell (version 5.2, 17 May 2022).
Bash shell (version 5.2, 3 June 2022).
This is Edition 5.2, last updated 17 May 2022, of 'The GNU Bash
This is Edition 5.2, last updated 3 June 2022, of 'The GNU Bash
Reference Manual', for 'Bash', Version 5.2.
Copyright (C) 1988-2022 Free Software Foundation, Inc.
@@ -27,10 +27,10 @@ Bash Features
*************
This text is a brief description of the features that are present in the
Bash shell (version 5.2, 17 May 2022). The Bash home page is
Bash shell (version 5.2, 3 June 2022). The Bash home page is
<http://www.gnu.org/software/bash/>.
This is Edition 5.2, last updated 17 May 2022, of 'The GNU Bash
This is Edition 5.2, last updated 3 June 2022, of 'The GNU Bash
Reference Manual', for 'Bash', Version 5.2.
Bash contains features that appear in other popular shells, and some
@@ -1145,6 +1145,9 @@ File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Pre
is the portion of the string matching the Nth parenthesized
subexpression.
Bash sets 'BASH_REMATCH' in the global scope; declaring it as a
local variable will lead to unexpected results.
Expressions may be combined using the following operators, listed
in decreasing order of precedence:
@@ -12530,114 +12533,114 @@ Node: Lists29272
Node: Compound Commands31067
Node: Looping Constructs32079
Node: Conditional Constructs34574
Node: Command Grouping48918
Node: Coprocesses50396
Node: GNU Parallel53059
Node: Shell Functions53976
Node: Shell Parameters61861
Node: Positional Parameters66249
Node: Special Parameters67151
Node: Shell Expansions70365
Node: Brace Expansion72492
Node: Tilde Expansion75226
Node: Shell Parameter Expansion77847
Node: Command Substitution96198
Node: Arithmetic Expansion97553
Node: Process Substitution98521
Node: Word Splitting99641
Node: Filename Expansion101585
Node: Pattern Matching104334
Node: Quote Removal108991
Node: Redirections109286
Node: Executing Commands118946
Node: Simple Command Expansion119616
Node: Command Search and Execution121726
Node: Command Execution Environment124104
Node: Environment127139
Node: Exit Status128802
Node: Signals130586
Node: Shell Scripts134035
Node: Shell Builtin Commands137062
Node: Bourne Shell Builtins139100
Node: Bash Builtins160561
Node: Modifying Shell Behavior191417
Node: The Set Builtin191762
Node: The Shopt Builtin202363
Node: Special Builtins218275
Node: Shell Variables219254
Node: Bourne Shell Variables219691
Node: Bash Variables221795
Node: Bash Features254611
Node: Invoking Bash255624
Node: Bash Startup Files261637
Node: Interactive Shells266768
Node: What is an Interactive Shell?267178
Node: Is this Shell Interactive?267827
Node: Interactive Shell Behavior268642
Node: Bash Conditional Expressions272271
Node: Shell Arithmetic276913
Node: Aliases279857
Node: Arrays282470
Node: The Directory Stack288861
Node: Directory Stack Builtins289645
Node: Controlling the Prompt293905
Node: The Restricted Shell296870
Node: Bash POSIX Mode299480
Node: Shell Compatibility Mode311404
Node: Job Control319433
Node: Job Control Basics319893
Node: Job Control Builtins324895
Node: Job Control Variables330465
Node: Command Line Editing331621
Node: Introduction and Notation333292
Node: Readline Interaction334915
Node: Readline Bare Essentials336106
Node: Readline Movement Commands337889
Node: Readline Killing Commands338849
Node: Readline Arguments340767
Node: Searching341811
Node: Readline Init File343997
Node: Readline Init File Syntax345258
Node: Conditional Init Constructs368457
Node: Sample Init File372653
Node: Bindable Readline Commands375777
Node: Commands For Moving376981
Node: Commands For History379032
Node: Commands For Text384026
Node: Commands For Killing387675
Node: Numeric Arguments390708
Node: Commands For Completion391847
Node: Keyboard Macros396038
Node: Miscellaneous Commands396725
Node: Readline vi Mode402664
Node: Programmable Completion403571
Node: Programmable Completion Builtins411351
Node: A Programmable Completion Example422046
Node: Using History Interactively427293
Node: Bash History Facilities427977
Node: Bash History Builtins430982
Node: History Interaction435990
Node: Event Designators439610
Node: Word Designators440964
Node: Modifiers442724
Node: Installing Bash444535
Node: Basic Installation445672
Node: Compilers and Options449394
Node: Compiling For Multiple Architectures450135
Node: Installation Names451828
Node: Specifying the System Type453937
Node: Sharing Defaults454653
Node: Operation Controls455326
Node: Optional Features456284
Node: Reporting Bugs467502
Node: Major Differences From The Bourne Shell468777
Node: GNU Free Documentation License485627
Node: Indexes510804
Node: Builtin Index511258
Node: Reserved Word Index518085
Node: Variable Index520533
Node: Function Index537307
Node: Concept Index551091
Node: Command Grouping49041
Node: Coprocesses50519
Node: GNU Parallel53182
Node: Shell Functions54099
Node: Shell Parameters61984
Node: Positional Parameters66372
Node: Special Parameters67274
Node: Shell Expansions70488
Node: Brace Expansion72615
Node: Tilde Expansion75349
Node: Shell Parameter Expansion77970
Node: Command Substitution96321
Node: Arithmetic Expansion97676
Node: Process Substitution98644
Node: Word Splitting99764
Node: Filename Expansion101708
Node: Pattern Matching104457
Node: Quote Removal109114
Node: Redirections109409
Node: Executing Commands119069
Node: Simple Command Expansion119739
Node: Command Search and Execution121849
Node: Command Execution Environment124227
Node: Environment127262
Node: Exit Status128925
Node: Signals130709
Node: Shell Scripts134158
Node: Shell Builtin Commands137185
Node: Bourne Shell Builtins139223
Node: Bash Builtins160684
Node: Modifying Shell Behavior191540
Node: The Set Builtin191885
Node: The Shopt Builtin202486
Node: Special Builtins218398
Node: Shell Variables219377
Node: Bourne Shell Variables219814
Node: Bash Variables221918
Node: Bash Features254734
Node: Invoking Bash255747
Node: Bash Startup Files261760
Node: Interactive Shells266891
Node: What is an Interactive Shell?267301
Node: Is this Shell Interactive?267950
Node: Interactive Shell Behavior268765
Node: Bash Conditional Expressions272394
Node: Shell Arithmetic277036
Node: Aliases279980
Node: Arrays282593
Node: The Directory Stack288984
Node: Directory Stack Builtins289768
Node: Controlling the Prompt294028
Node: The Restricted Shell296993
Node: Bash POSIX Mode299603
Node: Shell Compatibility Mode311527
Node: Job Control319556
Node: Job Control Basics320016
Node: Job Control Builtins325018
Node: Job Control Variables330588
Node: Command Line Editing331744
Node: Introduction and Notation333415
Node: Readline Interaction335038
Node: Readline Bare Essentials336229
Node: Readline Movement Commands338012
Node: Readline Killing Commands338972
Node: Readline Arguments340890
Node: Searching341934
Node: Readline Init File344120
Node: Readline Init File Syntax345381
Node: Conditional Init Constructs368580
Node: Sample Init File372776
Node: Bindable Readline Commands375900
Node: Commands For Moving377104
Node: Commands For History379155
Node: Commands For Text384149
Node: Commands For Killing387798
Node: Numeric Arguments390831
Node: Commands For Completion391970
Node: Keyboard Macros396161
Node: Miscellaneous Commands396848
Node: Readline vi Mode402787
Node: Programmable Completion403694
Node: Programmable Completion Builtins411474
Node: A Programmable Completion Example422169
Node: Using History Interactively427416
Node: Bash History Facilities428100
Node: Bash History Builtins431105
Node: History Interaction436113
Node: Event Designators439733
Node: Word Designators441087
Node: Modifiers442847
Node: Installing Bash444658
Node: Basic Installation445795
Node: Compilers and Options449517
Node: Compiling For Multiple Architectures450258
Node: Installation Names451951
Node: Specifying the System Type454060
Node: Sharing Defaults454776
Node: Operation Controls455449
Node: Optional Features456407
Node: Reporting Bugs467625
Node: Major Differences From The Bourne Shell468900
Node: GNU Free Documentation License485750
Node: Indexes510927
Node: Builtin Index511381
Node: Reserved Word Index518208
Node: Variable Index520656
Node: Function Index537430
Node: Concept Index551214

End Tag Table
+5
View File
@@ -1335,6 +1335,11 @@ expression are saved in the remaining @code{BASH_REMATCH} indices.
The element of @code{BASH_REMATCH} with index @var{n} is the portion of the
string matching the @var{n}th parenthesized subexpression.
Bash sets
@code{BASH_REMATCH}
in the global scope; declaring it as a local variable will lead to
unexpected results.
Expressions may be combined using the following operators, listed
in decreasing order of precedence:
+3 -3
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2022 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Tue May 17 09:37:52 EDT 2022
@set LASTCHANGE Fri Jun 3 10:47:05 EDT 2022
@set EDITION 5.2
@set VERSION 5.2
@set UPDATED 17 May 2022
@set UPDATED-MONTH May 2022
@set UPDATED 3 June 2022
@set UPDATED-MONTH June 2022
+12 -4
View File
@@ -2,7 +2,7 @@
* shmatch.c -- shell interface to posix regular expression matching.
*/
/* Copyright (C) 2003-2015 Free Software Foundation, Inc.
/* Copyright (C) 2003-2022 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -41,6 +41,10 @@
extern int glob_ignore_case, match_ignore_case;
#if defined (ARRAY_VARS)
extern SHELL_VAR *builtin_find_indexed_array (char *, int);
#endif
int
sh_regmatch (string, pattern, flags)
const char *string;
@@ -92,11 +96,15 @@ sh_regmatch (string, pattern, flags)
/* Store the parenthesized subexpressions in the array BASH_REMATCH.
Element 0 is the portion that matched the entire regexp. Element 1
is the part that matched the first subexpression, and so on. */
unbind_variable_noref ("BASH_REMATCH");
#if 1
unbind_global_variable_noref ("BASH_REMATCH");
rematch = make_new_array_variable ("BASH_REMATCH");
amatch = array_cell (rematch);
#else
rematch = builtin_find_indexed_array ("BASH_REMATCH", 1);
#endif
amatch = rematch ? array_cell (rematch) : (ARRAY *)0;
if (matches && (flags & SHMAT_SUBEXP) && result == EXECUTION_SUCCESS && subexp_str)
if (matches && amatch && (flags & SHMAT_SUBEXP) && result == EXECUTION_SUCCESS && subexp_str)
{
for (subexp_ind = 0; subexp_ind <= regex.re_nsub; subexp_ind++)
{
BIN
View File
Binary file not shown.
+2685 -2627
View File
File diff suppressed because it is too large Load Diff
+29 -1
View File
@@ -2370,7 +2370,7 @@ find_global_variable (name)
var = var_lookup (name, global_variables);
if (var && nameref_p (var))
var = find_variable_nameref (var);
var = find_variable_nameref (var); /* XXX - find_global_variable_noref? */
if (var == 0)
return ((SHELL_VAR *)NULL);
@@ -3840,6 +3840,34 @@ unbind_variable_noref (name)
return 0;
}
int
unbind_global_variable (name)
const char *name;
{
SHELL_VAR *v, *nv;
int r;
v = var_lookup (name, global_variables);
/* This starts at the current scope, just like find_global_variable; should we
use find_global_variable_nameref here? */
nv = (v && nameref_p (v)) ? find_variable_nameref (v) : (SHELL_VAR *)NULL;
r = nv ? makunbound (nv->name, shell_variables) : makunbound (name, global_variables);
return r;
}
int
unbind_global_variable_noref (name)
const char *name;
{
SHELL_VAR *v;
v = var_lookup (name, global_variables);
if (v)
return makunbound (name, global_variables);
return 0;
}
int
check_unbind_variable (name)
const char *name;
+2
View File
@@ -328,6 +328,8 @@ extern int unbind_variable PARAMS((const char *));
extern int check_unbind_variable PARAMS((const char *));
extern int unbind_nameref PARAMS((const char *));
extern int unbind_variable_noref PARAMS((const char *));
extern int unbind_global_variable PARAMS((const char *));
extern int unbind_global_variable_noref PARAMS((const char *));
extern int unbind_func PARAMS((const char *));
extern int unbind_function_def PARAMS((const char *));
extern int delete_var PARAMS((const char *, VAR_CONTEXT *));