#992161 /usr/bin/printf: %q outputs garbage for \1'\1

Package:
coreutils
Source:
coreutils
Description:
GNU core utilities
Submitter:
наб
Date:
2025-12-12 17:15:02 UTC
Severity:
normal
#992161#5
Date:
2021-08-14 14:08:50 UTC
From:
To:
Dear Maintainer,

Consider the following invocation:
	/bin/printf "%q" $'\001'\'$'\001'
(i.e. 1st=dollar+letter q, 2nd=byte 1+apostrophe+byte 1)

What do you expect the output to be? I'd expect something like
	$'\001'\'$'\001'
or, in the, rather verbose, printf format,
	''$'\001'\'''$'\001'

Okay, now what does the invocation output?
	'\001'\'''$'\001'

Uh-oh! And what fill feeding that into an Almquist shell give?
	$ echo -n '\001'\'''$'\001' | hexdump -C
	00000000  5c 30 30 31 27 01                                 |\001'.|
	00000006

Sheesh!

As far as I can tell, a sequence of any string that needs escaping,
followed by an apostrophe, followed by another string that needs
escaping will trigger this, and the example above is the minimal case.

наб

#992161#10
Date:
2025-12-12 17:13:04 UTC
From:
To: