Bug#1011401: mount: umount bash completion explodes awk on some paths

2023-06-17 Thread наб
Control: found -1 2.38.1-5+b1
Control: tags -1 + fixed-upstream - help

On Sun, Sep 04, 2022 at 12:07:35PM +0200, Andreas Henriksson wrote:
> Thanks for narrowing this down. Could you please submit your findings
> to the upstream mailing list? (util-linux at vger.kernel.org)
You removed me from CC so I didn't get your mail
(submitters don't get bug mail forwarded by default);
re-discovered this report after I got
  nabijaczleweli@tarta:~/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1$ sudo umount 0awk: 
cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range end: 
/^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
  awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
  awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
(yes, same path; same archive) today on bookworm.

I tested the util-linux 2.39 tarball to prepare a patch:
the completion has changed, and now escapes the path before using it as
a regex; I've validated that
  $ (cd ~/uwu/SunOS\ 2.0\ \(Tape\)\ \[Sun-2]/tape1; _umount_points_list)
  awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
  $ . /usr/share/bash-completion/completions/umount
  $ (cd ~/uwu/SunOS\ 2.0\ \(Tape\)\ \[Sun-2]/tape1; _umount_points_list)
  awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
  $ . ./bash-completion/umount
  $ (cd ~/uwu/SunOS\ 2.0\ \(Tape\)\ \[Sun-2]/tape1; _umount_points_list)
  /home/nabijaczleweli
  /proc
  # ...
  /home/nabijaczleweli
  ~/uwu/SunOS\ 2.0\ \(Tape\)\ \[Sun-2\]/tape1/04.d
  ./04.d
  04.d
  /home/nabijaczleweli/uwu/SunOS\ 2.0\ \(Tape\)\ \[Sun-2\]/tape1/04.d

Re-tagging appropriately.

Best,
наб


signature.asc
Description: PGP signature


Bug#1011401: mount: umount bash completion explodes awk on some paths

2022-09-04 Thread Andreas Henriksson
Control: retitle -1 mount: umount bash completion explodes when HOME/PWD 
contains [a-b] in path
Control: tags -1 + confirmed

On Sat, Sep 03, 2022 at 08:30:15PM +0200, наб wrote:
[...]
> -- >8 --
> 
> Which I gamed down to:
> -- >8 --
> $ echo | gawk '{print ($0 ~ "[n-2]")}'
> gawk: cmd. line:1: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
> end: /[n-2]/
> $ echo | mawk '{print ($0 ~ "[n-2]")}'
> 0
> -- >8 --
> 
> So the solution seems to be "don't use paths as regexes lmao".
> The correct spelling of that check would be
>   substr($0, 0, length(ENVIRON["PWD"])) == ENVIRON["PWD"]
> and of the subsequent string manipulation as 
>   reldir = substr($0, length(ENVIRON["PWD"]) + 1)
>   sub("^/", "", reldir)
> for the second branch and
>   substr($0, 0, length(ENVIRON["HOME"])) == ENVIRON["HOME"]
> with
>   homeless = "~" substr($0, length(ENVIRON["HOME"]) + 1)
> for the first (checked on mawk and gawk).
> 
> Best,
> наб

Thanks for narrowing this down. Could you please submit your findings
to the upstream mailing list? (util-linux at vger.kernel.org)

(I've confirmed I can reproduce this. Also making bug title more
specific while at it.)

Regards,
Andreas Henriksson



Bug#1011401: mount: umount bash completion explodes awk on some paths

2022-09-03 Thread наб
Hi!

On Sat, Sep 03, 2022 at 07:43:26PM +0200, Andreas Henriksson wrote:
> On Sun, May 22, 2022 at 12:20:27AM +0200, наб wrote:
> > Package: mount
> > Version: 2.36.1-8+deb11u1
> > Severity: normal
> > 
> > Dear Maintainer,
> > 
> > I just got this:
> > nabijaczleweli@tarta:~/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1$ sudo umount 
> > 04.awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid 
> > range end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
> > dawk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
> > end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
> 
> I have a gut feeling this is because of the awk implementation in use on
> your system. I think it would serve the bug report well if you could
> include this information (I'm guessing mawk).
> ie. `update-alternatives --query awk`

This had been the case in the past ‒ I even opened #956465 at one point ‒
where awk=mawk would either not work or explode for umount always,
which is why I switched back to awk=gawk:
-- >8 --
$ update-alternatives --query awk
Name: awk
Link: /usr/bin/awk
Slaves:
 awk.1.gz /usr/share/man/man1/awk.1.gz
 nawk /usr/bin/nawk
 nawk.1.gz /usr/share/man/man1/nawk.1.gz
Status: auto
Best: /usr/bin/gawk
Value: /usr/bin/gawk

Alternative: /usr/bin/gawk
Priority: 10
Slaves:
 awk.1.gz /usr/share/man/man1/gawk.1.gz
 nawk /usr/bin/gawk
 nawk.1.gz /usr/share/man/man1/gawk.1.gz

Alternative: /usr/bin/mawk
Priority: 5
Slaves:
 awk.1.gz /usr/share/man/man1/mawk.1.gz
 nawk /usr/bin/mawk
 nawk.1.gz /usr/share/man/man1/mawk.1.gz
-- >8 --

With set -x, when bing, I get this (trimmed to show texture):
-- >8 --
+++ findmnt -lno TARGET
+++ awk '{
if ($0 ~ "^"ENVIRON["HOME"]) {
homeless = $0
sub("^"ENVIRON["HOME"], "~", homeless)
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", 
"&", homeless)
print homeless " "
}
if ($0 ~ "^"ENVIRON["PWD"]) {
reldir = $0
sub("^"ENVIRON["PWD"]"/?", "", reldir)
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", 
"&", reldir)
print "./" reldir " "
print reldir " "
}
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", "&")
print $0 " "
}'
awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range end: 
/^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
+ local opt
-- >8 --

If I cunningly override awk=mawk by setting `awk() { mawk "$@"; }`,
I get no explicit error:
-- >8 -:
+++ findmnt -lno TARGET
+++ awk '{
if ($0 ~ "^"ENVIRON["HOME"]) {
homeless = $0
sub("^"ENVIRON["HOME"], "~", homeless)
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", 
"&", homeless)
print homeless " "
}
if ($0 ~ "^"ENVIRON["PWD"]) {
reldir = $0
sub("^"ENVIRON["PWD"]"/?", "", reldir)
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", 
"&", reldir)
print "./" reldir " "
print reldir " "
}
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", "&")
print $0 " "
}'
+++ mawk '{
if ($0 ~ "^"ENVIRON["HOME"]) {
homeless = $0
sub("^"ENVIRON["HOME"], "~", homeless)
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", 
"&", homeless)
print homeless " "
}
if ($0 ~ "^"ENVIRON["PWD"]) {
reldir = $0
sub("^"ENVIRON["PWD"]"/?", "", reldir)
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", 
"&", reldir)
print "./" reldir " "
print reldir " "
}
gsub("[][(){}<>\",:;^&!$=?`|\\'\'' \t\f\n\r\v]", "&")
print $0 " "
}'
+ local opt
-- >8 --
but I also don't get any suggestions or completions.

So:
  gawk explodes
  mawk fails silently

Further analysis of line 8 shows that this is sufficient:
-- >8 --
~/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1$ echo "$PWD" | gawk '{print ($0 ~ 
"^"ENVIRON["PWD"])}'
gawk: cmd. line:1: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range end: 
/^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
~/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1$ echo "$PWD" | mawk '{print ($0 ~ 
"^"ENVIRON["PWD"])}'
0
-- >8 --

Which I gamed down to:
-- >8 --
$ echo | gawk '{print ($0 ~ "[n-2]")}'
gawk: cmd. line:1: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range end: 
/[n-2]/
$ echo | mawk '{print ($0 ~ "[n-2]")}'
0

Bug#1011401: mount: umount bash completion explodes awk on some paths

2022-09-03 Thread Andreas Henriksson
Hello,

On Sun, May 22, 2022 at 12:20:27AM +0200, наб wrote:
> Package: mount
> Version: 2.36.1-8+deb11u1
> Severity: normal
> 
> Dear Maintainer,
> 
> I just got this:
> nabijaczleweli@tarta:~/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1$ sudo umount 
> 04.awk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
> end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/
> dawk: cmd. line:8: (FILENAME=- FNR=1) fatal: invalid regexp: Invalid range 
> end: /^/home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1/


I have a gut feeling this is because of the awk implementation in use on
your system. I think it would serve the bug report well if you could
include this information (I'm guessing mawk).
ie. `update-alternatives --query awk`

If you can confirm the problem exists with one particular awk
implementation (e.g. mawk) and not another one (e.g. gawk which I think
is really the only think upstream considers as awk implementation if I
remember correctly), then it might be a good idea to bring this up
in a discussion with upstream (including this info).

> 
> As the prompt may suggest, I was in
>   /home/nabijaczleweli/uwu/SunOS 2.0 (Tape) [Sun-2]/tape1
> and trying to unmount "04.d" in that same directory,
> with the cursor after the dot.
> 
> Best,
> наб
> 
> -- System Information:
> Debian Release: 11.3
>   APT prefers stable-updates
>   APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
> 'stable-debug'), (500, 'stable')
> Architecture: amd64 (x86_64)
> Foreign Architectures: i386
> 
> Kernel: Linux 5.10.0-14-amd64 (SMP w/24 CPU threads)
> Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_FIRMWARE_WORKAROUND, 
> TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
> Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), 
> LANGUAGE=en_GB:en
> Shell: /bin/sh linked to /usr/bin/dash
> Init: systemd (via /run/systemd/system)
> LSM: AppArmor: enabled
> 
> -- no debconf information

Regards,
Andreas Henriksson