764 Commits

Author SHA1 Message Date
Johannes Schauer Marin Rodrigues
98f97ad625
debian/tests/mmdebstrap: rename copy-host-apt-config -> copy-host-apt-sources-and-preferences 2023-06-20 20:31:00 +02:00
Johannes Schauer Marin Rodrigues
c2c859ba66
debian/tests/mmdebstrap: use copy-host-apt-config hook
- use the hook provided by mmdebstrap instead of cooking up our own
   thing, thus preventing code duplication
 - this also copies over apt pinning rules which were missing before
2023-06-18 15:42:20 +02:00
Andrej Shadura
3092f84e88
Update the changelog debian/0.5.12-5 2023-06-17 12:34:36 +02:00
Andrej Shadura
cf18b88eed
Extend the GitLab CI test to test with excluded files
See #1038067 for the details.
2023-06-17 12:31:06 +02:00
Helmut Grohne
036e7245d8
dash.postinst: fix installing with --path-exclude=/usr/share/man/*
The symlink might not exist, but we should remove the diversion
anyway.

Closes: #1038067
2023-06-17 11:43:12 +02:00
Andrej Shadura
7261c0b907
Upload to unstable debian/0.5.12-4 2023-06-12 16:17:14 +02:00
Andrej Shadura
1c8817b74f
Finalise the changelog debian/0.5.12-3 2023-04-30 15:54:44 +02:00
Luca Boccassi
0ceaefeb43 Update changelog for 0.5.12-3 release 2023-04-30 13:33:14 +00:00
Luca Boccassi
67b4d826ac dash.postinst: remove unused function 2023-04-30 13:33:14 +00:00
Helmut Grohne
5d0fb11df9 Remove unnecessary diversion in case /bin/sh points to dash.
Closes: #989632
2023-04-30 13:33:14 +00:00
Andrej Shadura
00f95b807d
Add some upgrade/downgrade tests to GitLab CI pipeline 2023-04-30 15:31:51 +02:00
Helmut Grohne
660022ed34
dash.postinst: Remove upgrade path from pre-sarge ash
Closes: #989419
2023-04-29 07:57:24 +02:00
Andrej Shadura
2d06dc1b84
Fix bug number in the patch description 2023-01-05 14:29:55 +01:00
Andrej Shadura
a1570cdf68
Update the changelog debian/0.5.12-2 2023-01-05 14:21:02 +01:00
Andrej Shadura
e97b01793e
Fix the changelog entry 2023-01-05 14:20:21 +01:00
Andrej Shadura
6195613b66
Update the changelog debian/0.5.12-1 2023-01-05 14:06:33 +01:00
Andrej Shadura
daabe7f2ee
Apply upstream patches for hash, ulimit and manpages
Closes: #558607
Closes: #819829
Closes: #850202
Closes: #975326
2023-01-05 14:04:54 +01:00
Andrej Shadura
385c507aa0
Prepare a changelog entry 2022-12-14 18:41:18 +01:00
Andrej Shadura
f6839521da
Refresh patches 2022-12-14 18:30:42 +01:00
Andrej Shadura
d19022cba7
Merge branch 'upstream/latest' into debian/unstable 2022-12-14 18:27:16 +01:00
Andrej Shadura
796d7ad03d New upstream version 0.5.12 upstream/0.5.12 2022-12-14 18:19:35 +01:00
Herbert Xu
4bbf8721a3 Release 0.5.12. 2022-12-11 14:33:43 +08:00
Herbert Xu
d5d616126c eval: Test evalskip before flipping status for NNOT
On Tue, Dec 06, 2022 at 10:15:03AM +0000, Harald van Dijk wrote:
>
> There is a long-standing bug that may or may not be harder to fix if this
> patch goes in, depending on how you want to fix it. Here's a script that
> already fails on current dash.
>
>   f() {
>     if ! return 0
>     then :
>     fi
>   }
>   f
>
> This should return 0, and does return 0 in bash and ksh (and almost all
> shells), but returns 1 in dash.
>
> There are a few possible ways of fixing it. Some of them rely on continuing
> to conditionally set exitstatus.

This can be fixed simply by testing evalskip prior to flipping the
status.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-11 14:29:21 +08:00
Herbert Xu
f0d57fded5 parser: Add VSBIT to ensure subtype is never zero
Harald van Dijk <harald@gigawatt.nl> wrote:
> On 21/11/2022 13:08, Harald van Dijk wrote:
>> On 21/11/2022 02:38, Christoph Anton Mitterer wrote:
>>> reject_filtered_cmd()
>>> {
>>> 	reject_and_die "disallowed command${restrict_path_list:+
>>> (restrict-path: \"${restrict_path_list//|/\", \"}\")}"
>>> }
>>>
>>> reject_filtered_cmd
>>[...]
>> This should either result in the ${...//...} being skipped, or the "Bad
>> substitution" error. Currently, what happens instead is it attempts, but
>> fails, to skip the ${...//...}.
>
> The reason it fails is because the word is cut off.
>
> Variable substitutions are encoded as a CTLVAR special character,
> followed by a byte indicating the type of substitution, followed by the
> rest of the substitution data. The type of substitution is the VSNORMAL,
> VSMINUS, etc. seen in parser.h. An invalid substitution is encoded as a
> value of 0.
>
> When we define a function, we clone the function body in order to
> preserve it. Cloning the function body is done by cloning each node.
> Cloning a "word" node (NARG) involves copying the characters that make
> up the word up to and including the terminating null byte.
>
> These two interact badly. The invalid substitution is seen as
> terminating the word, the rest of the word is not copied, but the
> expansion code does not have any way of seeing that anything got cut off
> and happily continues attempting to process the rest of the word.
>
> If dash decides to issue an error in this case, this is not a problem:
> the null byte is guaranteed to be copied, and if processing is
> guaranteed to stop if a null byte is encountered, everything works out.
>
> If dash decides to not issue an error in this case, the encoding of bad
> substitutions needs to change to a non-null byte. It appears that if we
> set the byte to VSNUL, the expansion logic is already able to handle it,
> but I have not tested this extensively.

Thanks for the analysis Harald!

This patch does basically what you've described except it uses a new
bit to avoid any confusion with a genuine VSNUL.

Fixes: 3df3edd13389 ("[PARSER] Report substition errors at...")
Reported-by: Christoph Anton Mitterer <calestyo@scientia.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Cheers,

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-11 14:29:21 +08:00
Herbert Xu
f42ee97f9e eval: Check eflag after redirection error
>
> This is a POSIX violation, and quite a grave one at that:
> set -e is oft[1] used to guard against precisely this type of error!
>
> The same happens if set -e is executed.
>
> All quotes POSIX.1, Issue 7, TC2:
> sh, OPTIONS:
>  > The -a, -b, -C, -e, -f, -m, -n, -o option, -u, -v, and -x options
>  > are described as part of the set utility in Special Built-In
>  > Utilities.
>
> set, DESCRIPTION, -e:
>  > When this option is on, when any command fails (for any of the
>  > reasons listed in Consequences of Shell Errors or by returning an
>  > exit status greater than zero), the shell immediately shall exit, as
>  > if by executing the exit special built-in utility with no arguments,
>  > with the following exceptions:
>  >
>  > 1. The failure of any individual command in a multi-command pipeline
>  >    shall not cause the shell to exit. Only the failure of the
>  >    pipeline itself shall be considered.
>  > 2. The -e setting shall be ignored when executing the compound list
>  >    following the while, until, if, or elif reserved word, a pipeline
>  >    beginning with the ! reserved word, or any command of an AND-OR
>  >    list other than the last.
>  > 3. If the exit status of a compound command other than a subshell
>  >    command was the result of a failure while -e was being ignored,
>  >    then -e shall not apply to this command.
>
> XCU, 2.9.4: Shell Command Language, Shell Commands, Compound Commands:
> The while Loop:
>  > The format of the while loop is as follows:
>  >
>  > while compound-list-1
>  > do
>  >   compound-list-2
>  > done
> (until is equivalent).
> The if Conditional Construct:
>  > The format for the if construct is as follows:
>  >
>  > if compound-list
>  > then
>  >   compound-list
>  > [elif compound-list
>  > then
>  >   compound-list] ...
>  > [else
>  >   compound-list]
>  > fi
>
> It follows, therefore, that
>  * Exception 1. does not apply as there is no pipeline
>  * Exception 2. does not apply, as the redirection does /not/ follow
>    "while" or "if" directly and is /not/ part of the conditional
>        compound-list
>  * in the "for" case, there is no such provision, so this is likely not
>    a confusion w.r.t. the conditional compound-lists
>  * Exception 3. does not apply as -e was not being ignored while the
>    compound commands were being executed (indeed, the compound commands
>    do not run at all, as evidenced by the program terminating)
>
> [1]: https://salsa.debian.org/glibc-team/glibc/-/merge_requests/6#note_329899
> ----- End forwarded message -----

Yes we should check the exit status after redirections.

Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-07 16:44:57 +08:00
Herbert Xu
7148b08ba5 eval: Always set exitstatus in evaltree
There is no harm in setting exitstatus unconditionally in evaltree.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-07 16:44:57 +08:00
Herbert Xu
9036ee8d71 expand: Add ifsfree to expand to fix a logic error that causes a buffer over-read
On Mon, Jun 20, 2022 at 02:27:10PM -0400, Alex Gorinson wrote:
> Due to a logic error in the ifsbreakup function in expand.c if a
> heredoc and normal command is run one after the other by means of a
> semi-colon, when the second command drops into ifsbreakup the command
> will be evaluated with the ifslastp/ifsfirst struct that was set when
> the here doc was evaluated. This results in a buffer over-read that
> can leak the program's heap, stack, and arena addresses which can be
> used to beat ASLR.
>
> Steps to Reproduce:
> First bug:
> cmd args: ~/exampleDir/example> dash
> $ M='AAAAAAAAAAAAAAAAA'    <note: 17 A's>
> $ q00(){
> $ <<000;echo
> $ ${D?$M$M$M$M$M$M}        <note: 6 $M's>
> $ 000
> $ }
> $ q00                      <note: After the q00 is typed in, the leak
> should be echo'd out; this works with ash, busybox ash, and dash and
> with all option args.>
>
> Patch:
> Adding the following to expand.c will fix both bugs in one go.
> (Thank you to Harald van Dijk and Michael Greenberg for doing the
> heavy lifting for this patch!)
> ==========================
> --- a/src/expand.c
> +++ b/src/expand.c
> @@ -859,6 +859,7 @@
> if (discard)
> return -1;
>
> +ifsfree();
> sh_error("Bad substitution");
> }
>
> @@ -1739,6 +1740,7 @@
> } else
> msg = umsg;
> }
> +ifsfree();
> sh_error("%.*s: %s%s", end - var - 1, var, msg, tail);
>  }
> ==========================

Thanks for the report!

I think it's better to add the ifsfree() call to the exception
handling path as other sh_error calls may trigger this too.

Reported-by: Alex Gorinson <algore3698@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-07 16:27:49 +08:00
Herbert Xu
8f9cca055b expand: Always quote caret when using fnmatch
This patch forces ^ to be a literal when we use fnmatch.

In order to allow for the extra space to quote the caret, the
function _rmescapes will allocate up to twice the memory if the
flag RMESCAPE_GLOB is set.

Fixes: 7638476c18f2 ("shell: Enable fnmatch/glob by default")
Reported-by: Christoph Anton Mitterer <calestyo@scientia.org>
Suggested-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-07 16:27:49 +08:00
Ron Yorston
dcf4ee3802 input: Remove special case for unget EOF
Commit 17db43b5841504b694203952fb0e82246c06a97f (input: Allow two
consecutive calls to pungetc) ensures that EOF is handled like any
other character with respect to unget.  As a result it's possible
to remove the special case for unget of EOF in preadbuffer.

Signed-off-by: Ron Yorston <rmy@frippery.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
2022-12-07 16:27:49 +08:00
Bastian Germann
ee553b6017 d/copyright: Remove files only existing at build-time 2022-09-27 15:55:03 +02:00
Akbarkhon Variskhanov
c9b45f0835
d/dash.postinst: Remove comment referring to dash.preinst
dash.preinst was removed years ago.
2022-09-04 12:40:09 +02:00
Andrej Shadura
5978cba8e8
Update the changelog debian/0.5.11+git20210903+057cd650a4ed-9 2022-09-01 16:12:15 +02:00
Johannes Schauer Marin Rodrigues
e5adfb0497
debian/tests/mmdebstrap: create chroot with the same apt sources as autopkgtest (closes: #1016554) 2022-08-25 15:23:36 +02:00
Andrej Shadura
dbea03349b
Update the changelog debian/0.5.11+git20210903+057cd650a4ed-8 2022-03-14 15:11:10 +01:00
Andrej Shadura
c59f7bce9d
Add another bug number 2022-03-14 15:09:10 +01:00
Andrej Shadura
3554abc7c4
Prepare the new changelog entry 2022-03-11 09:53:35 +01:00
Andrej Shadura
48d2f39237
Remove the remnants of the debconf shell question 2022-03-11 09:52:40 +01:00
Andrej Shadura
05f78d77c5
Update the changelog debian/0.5.11+git20210903+057cd650a4ed-7 2022-03-05 11:32:30 +01:00
Johannes Schauer Marin Rodrigues
0ec43190df
debian/tests/mmdebstrap: fix running on debci and add more comments 2022-03-05 10:58:37 +01:00
Andrej Shadura
a02bfa9647
Update the changelog debian/0.5.11+git20210903+057cd650a4ed-6 2022-03-04 22:19:09 +01:00
Johannes Schauer Marin Rodrigues
e70452a44b Add autopkgtest installing dash into a fresh chroot 2022-03-04 21:09:09 +00:00
Johannes Schauer Marin Rodrigues
64b7925b58
debian/dash.postinst: fix missing ] 2022-03-04 21:49:47 +01:00
Andrej Shadura
41295fbac4
Update the changelog debian/0.5.11+git20210903+057cd650a4ed-5 2022-03-04 18:34:44 +01:00
Johannes Schauer Marin Rodrigues
e70fce688e
debian/dash.postinst: Move check if dfile exists further up
- We use a variable because we reordered the code in the last commit
   such that dfile now always exists, so we check beforehand
 - We also check -L because -e dereferences the symlink
2022-03-04 17:07:12 +01:00
Johannes Schauer Marin Rodrigues
e67d69f6b1
debian/dash.postinst: restore DPKG_ROOT support 2022-03-04 16:56:20 +01:00
Johannes Schauer Marin Rodrigues
f08b4b9613
dpkg-realpath has a /bin/sh shebang and can thus not be used when /bin/sh is temporarily not available 2022-03-04 16:56:20 +01:00
Andrej Shadura
30663bf590
Update the changelog debian/0.5.11+git20210903+057cd650a4ed-4 2022-03-04 12:13:37 +01:00
Johannes Schauer Marin Rodrigues
258d3232cb
Allow downgrades to dash versions before it started using update-shells
This is to allow downgrades to version 0.5.11+git20210903+057cd650a4ed-3 and
earlier which do not use the update-shells trigger of debianutils to manage
/etc/shells.

update-shells will be called at the end of the downgrade because a trigger of
debianutils on the removal of /usr/share/debianutils/shells.d/dash will be
activated when downgrading to a version of dash that doesn't ship that file.
But a non-existing /usr/share/debianutils/shells.d/dash tells update-shells
to remove dash from /etc/shells.

To prevent this from happening, remove /usr/share/debianutils/shells.d/dash
which will be removed by the downgrade anyways, then run update-shells which
will remove dash from /etc/shells and then add it again by running add-shell.
Subsequent calls to update-shells in the debianutils trigger will now not
remove dash from /etc/shells anymore because the update-shells call in this
script updated /var/lib/shells.state with the information that it doesn't
manage dash via update-shells anymore.
2022-03-03 16:38:52 +01:00
Johannes Schauer Marin Rodrigues
6affc9d137
debian/dash.postinst: use symlink target mtime for reproducible mtimes instead of SOURCE_DATE_EPOCH 2022-02-12 12:35:39 +01:00
Johannes Schauer Marin Rodrigues
07d3d34545
debian/dash.postinst: reproducible symlink mtime if SOURCE_DATE_EPOCH is set 2022-02-01 16:46:48 +01:00