system.3: Document bug when the command name starts with a hypen
RFC 1/1 system.3: Document bug when the command name starts with a hypen
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029
glibc bug: 27143
https://sourceware.org/bugzilla/show_bug.cgi?id=27143
When a command name starts with a hyphen (which is a valid one), the shell's '-c' option interprets the command name as antoher option. This can be workarounded by prepending the command name with a space, as Ciprian pointed out in his bug report.
---
Hi Ciprian,
If you report a bug to the Austin Group, please CC [email protected],
so that we can add the URL and update the BUGS section if it is ever fixed.
man3/system.3 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
man3/system.3 +34 -0
@@ -250,6 +250,39 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +./" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +./" [glibc 27143](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined +(See the +.B \-c +option in +.BR sh (1).). +This behavior is mandated by POSIX. +To work around this problem, +prepend the command with a space as below: +.PP +.RS 4 +.EX +/* system_hyphen.c */ + +#include <stdlib.h> + +int +main(void) +{ + system(" -echo Hello world!"); + exit(EXIT_SUCCESS); +} +.PP +.RB "$" " sudo ln \-s \-T /usr/bin/echo /usr/bin/\-echo;" +.RB "$" " cc \-o system_hyphen system_hyphen.c;" +.RB "$" " ./system_hyphen;" +Hello world! +.EE +.RE .SH SEE ALSO .BR sh (1),
.BR execve (2),
Signature · 1 line
2.29.2
Quoted 4 lines · Alejandro Colomar
If you report a bug to the Austin Group, please CC [email protected],
so that we can add the URL and update the BUGS section if it is ever fixed.
As notified on the glibc and man-pages issue tracker (sorry for the duplicate notifications), the POSIX issue has been opened at:
https://www.austingroupbugs.net/view.php?id=1440
Thanks,
Ciprian.
PATCH 1/1 system.3: Document bug and workaround when the command name starts with a hypen
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029
--- man3/system.3 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
man3/system.3 +34 -0
@@ -250,6 +250,40 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +./" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +./" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +./" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined +(See the +.B \-c +option in +.BR sh (1).). +To work around this problem, +prepend the command with a space as below: +.PP +.RS 4 +.EX +/* system_hyphen.c */ + +#include <stdlib.h> + +int +main(void) +{ + system(" -echo Hello world!"); + exit(EXIT_SUCCESS); +} +.PP +.RB "$" " sudo ln \-s \-T /usr/bin/echo /usr/bin/\-echo;" +.RB "$" " cc \-o system_hyphen system_hyphen.c;" +.RB "$" " ./system_hyphen;" +Hello world! +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 1 line
2.29.2
Re: [PATCH] system.3: Document bug and workaround when the command name starts with a hypen
Hi Michael,
See a few corrections below.
Cheers,
Alex
Quoted 19 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>--- man3/system.3 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)man3/system.3 +1
-0@@ -250,6 +250,40 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS
man3/system.3 are not executed. · line 263
Quoted 10 lines
man3/system.3 +10
-0+./" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +./" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +./" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined +(See the +.B \-c +option in
option to
Quoted 4 lines
man3/system.3 +4
-0+.BR sh (1).). +To work around this problem, +prepend the command with a space as below: +.PP
man3/system.3 are not executed. · line 277
Quoted 10 lines
man3/system.3 +10
-0+.RS 4 +.EX +/* system_hyphen.c */ + +#include <stdlib.h> + +int +main(void) +{ + system(" -echo Hello world!");
\-echo
Quoted 13 lines
man3/system.3 +9
-0+ exit(EXIT_SUCCESS); +} +.PP +.RB "$" " sudo ln \-s \-T /usr/bin/echo /usr/bin/\-echo;" +.RB "$" " cc \-o system_hyphen system_hyphen.c;" +.RB "$" " ./system_hyphen;" +Hello world! +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Re: [PATCH] system.3: Document bug and workaround when the command name starts with a hypen
D'oh
Quoted 19 lines · Alejandro Colomar (man-pages)
Hi Michael,
See a few corrections below.
Cheers,
Alex
Quoted 10 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>--- man3/system.3 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
Quoted 12 lines
man3/system.3 are not executed. · line 256
Quoted 12 lines
man3/system.3 +4
-0@@ -250,6 +250,40 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +./" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +./" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +./" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440)
s%/%\\%
Quoted 41 lines
man3/system.3 are not executed. · line 263
Quoted 7 lines
man3/system.3 +7
-0+If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined +(See the +.B \-c +option inoption to
Quoted 4 lines
man3/system.3 +4
-0+.BR sh (1).). +To work around this problem, +prepend the command with a space as below: +.PPman3/system.3 are not executed. · line 277
Quoted 10 lines
man3/system.3 +10
-0+.RS 4 +.EX +/* system_hyphen.c */ + +#include <stdlib.h> + +int +main(void) +{ + system(" -echo Hello world!");\-echo
Quoted 13 lines
man3/system.3 +9
-0+ exit(EXIT_SUCCESS); +} +.PP +.RB "$" " sudo ln \-s \-T /usr/bin/echo /usr/bin/\-echo;" +.RB "$" " cc \-o system_hyphen system_hyphen.c;" +.RB "$" " ./system_hyphen;" +Hello world! +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
PATCH v2 1/1 system.3: Document bug and workaround when the command name starts with a hypen
In reply to Alejandro Colomarman-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029
Complete workaround
(it was too long for the page, but it may be useful here):
......
$ sudo ln \-s \-T /usr/bin/echo /usr/bin/\-echo; $ cc -o system_hyphen -x c - ;
int
main(void)
{
system(" -echo Hello world!");
exit(EXIT_SUCCESS);
}$ ./system_hyphen; Hello world!
--- man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
man3/system.3 +20 -0
@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 1 line
2.29.2
PATCH v3 1/1 system.3: Document bug and workaround when the command name starts with a hypen
In reply to Alejandro Colomarman-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029
Complete workaround
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ;
int
main(void)
{
system(" -echo Hello world!");
exit(EXIT_SUCCESS);
}$ ./system_hyphen; Hello world!
---
Hi Michael,
I forgot to remove some escapings in the commit message in v2. I hope it arrives in time :)
Cheers,
Alex
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
man3/system.3 +20 -0
@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 1 line
2.29.2
PATCH v4 1/1 system.3: Document bug and workaround when the command name starts with a hypen
In reply to Alejandro Colomarman-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029
Complete workaround
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>
int
main(void)
{
system(" -echo Hello world!");
exit(EXIT_SUCCESS);
}$ ./system_hyphen; Hello world!
---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
man3/system.3 +20 -0
@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 1 line
2.29.2
Re: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
Quoted 4 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround example
Quoted 60 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Ping: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
Hi Michael,
Ping!
And now I noticed a typo in the subject:
s/hypen/hyphen/
Thanks,
Alex
Quoted 73 lines · Alejandro Colomar (man-pages)
Quoted 4 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround exampleQuoted 60 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Re: Ping: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
Quoted 6 lines · Alejandro Colomar (man-pages)
Hi Michael,
Ping!
And now I noticed a typo in the subject:
s/hypen/hyphen/
D'oh! I missed that.
In cases like these, where there's already two amendments to the patch, perhaps better is a new complete patch, rather than a ping :-).
Thanks,
Michael
Quoted 76 lines · Alejandro Colomar (man-pages)
Quoted 73 lines · Alejandro Colomar
Quoted 4 lines
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround exampleQuoted 60 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Re: Ping: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
[removed some CCs]
Quoted 5 lines · Michael Kerrisk (man-pages)
Quoted 4 lines · Alejandro Colomar (man-pages)
Hi Michael,
Ping!
Quoted 7 lines
Quoted 2 lines
And now I noticed a typo in the subject:
s/hypen/hyphen/D'oh! I missed that.
In cases like these, where there's already two amendments to the patch, perhaps better is a new complete patch, rather than a ping :-).
Yup, I considered that for a moment...
Should've listened to myself :/
BTW, I don't understand why you ffixed to use .RS/.RE.
See
https://lore.kernel.org/linux-man/[email protected]/T/
Thanks,
Alex
Quoted 84 lines
Thanks,
Michael
Quoted 76 lines · Alejandro Colomar (man-pages)
Quoted 73 lines · Alejandro Colomar
Quoted 4 lines
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround exampleQuoted 60 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Re: Ping: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
Hi Alex,
Quoted 13 lines · Alejandro Colomar (man-pages)
[removed some CCs]
Quoted 10 lines · Michael Kerrisk (man-pages)
Quoted 6 lines · Alejandro Colomar (man-pages)
Hi Michael,
Ping!
And now I noticed a typo in the subject:
s/hypen/hyphen/D'oh! I missed that.
Quoted 8 lines
Quoted 2 lines
In cases like these, where there's already two amendments to the patch, perhaps better is a new complete patch, rather than a ping :-).
Yup, I considered that for a moment...
Should've listened to myself :/BTW, I don't understand why you ffixed to use .RS/.RE.
Cause that's what we do around code blocks. See man-pages(7), and all of the other pages :-).
The conclusion of the mail thread on this topic was that .RS/RE don't do correct relative indents, IIRC.
Thanks,
Michael
Quoted 93 lines
See
https://lore.kernel.org/linux-man/[email protected]/T/Thanks,
Alex
Quoted 84 lines
Thanks,
Michael
Quoted 76 lines · Alejandro Colomar (man-pages)
Quoted 73 lines · Alejandro Colomar
Quoted 4 lines
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround exampleQuoted 60 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Re: Ping: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
Quoted 23 lines · Michael Kerrisk (man-pages)
Hi Alex,
Quoted 20 lines · Alejandro Colomar (man-pages)
[removed some CCs]
Quoted 5 lines · Michael Kerrisk (man-pages)
Quoted 4 lines · Alejandro Colomar (man-pages)
Hi Michael,
Ping!
Quoted 7 lines
Quoted 2 lines
And now I noticed a typo in the subject:
s/hypen/hyphen/D'oh! I missed that.
In cases like these, where there's already two amendments to the patch, perhaps better is a new complete patch, rather than a ping :-).
Yup, I considered that for a moment...
Should've listened to myself :/
Quoted 8 lines
Quoted 1 line
BTW, I don't understand why you ffixed to use .RS/.RE.
Cause that's what we do around code blocks. See man-pages(7), and all of the other pages :-).
The conclusion of the mail thread on this topic was that .RS/RE don't do correct relative indents, IIRC.
Ahhh, I read the diff the other way.
I thought you changed .in -> .RS.
But you did .RS -> .in.
So forget what I said :-)
Thanks,
Alex
Quoted 101 lines
Thanks,
Michael
Quoted 93 lines
See
https://lore.kernel.org/linux-man/[email protected]/T/Thanks,
Alex
Quoted 84 lines
Thanks,
Michael
Quoted 76 lines · Alejandro Colomar (man-pages)
Quoted 73 lines · Alejandro Colomar
Quoted 4 lines
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround exampleQuoted 60 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
Re: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
In reply to Alejandro Colomar (man-pages)Quoted 10 lines · Alejandro Colomar (man-pages)
Quoted 4 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
Maybe a bit more readable:
Complete workaround example
Changed.
Thanks,
Michael
Quoted 63 lines
Quoted 62 lines
(it was too long for the page, but it may be useful here):
......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Re: [PATCH v4] system.3: Document bug and workaround when the command name starts with a hypen
In reply to Alejandro ColomarHi Alex,
Quoted 19 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029Complete workaround
(it was too long for the page, but it may be useful here):......
$ sudo ln -s -T /usr/bin/echo /usr/bin/-echo; $ cc -o system_hyphen -x c - ; #include <stdlib.h>int
main(void){ system(" -echo Hello world!"); exit(EXIT_SUCCESS); }
Quoted 6 lines
$ ./system_hyphen; Hello world!Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>
Thanks for the ping. Patch applied, but see man-pages(7) and my small fix-up in the next commit.
Cheers,
Michael
Quoted 39 lines
---
D'oh!
man3/system.3 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)man3/system.3 +20
-0@@ -255,6 +255,26 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +.\" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +.\" [Glibc bug](https://sourceware.org/bugzilla/show_bug.cgi?id=27143) +.\" [POSIX bug](https://www.austingroupbugs.net/view.php?id=1440) +If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined. +(See the +.B \-c +option to +.BR sh (1).) +To work around this problem, +prepend the command with a space as in the following call: +.PP +.RS 4 +.EX + system(" \-unfortunate\-command\-name"); +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Hi Alex,
Quoted 10 lines · Alejandro Colomar
man-pages bug: 211029
https://bugzilla.kernel.org/show_bug.cgi?id=211029glibc bug: 27143
https://sourceware.org/bugzilla/show_bug.cgi?id=27143When a command name starts with a hyphen (which is a valid one), the shell's '-c' option interprets the command name as antoher option. This can be workarounded by prepending the command name with a space, as Ciprian pointed out in his bug report.
Huh! Well that's weird, of course. So, I think something should be said in the manual page, but perhaps a little less than below. Having a command name that starts with a '-' is a weird corner case, and it's unsurprising (if unfortunate) that it buys you trouble.
Quoted 20 lines
Reported-by Ciprian Dorin Craciun <[email protected]>Cc Florian Weimer <[email protected]>Signed-off-by Alejandro Colomar <[email protected]>---
Hi Ciprian,
If you report a bug to the Austin Group, please CC [email protected],
so that we can add the URL and update the BUGS section if it is ever fixed.man3/system.3 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)man3/system.3 +0
-0
man3/system.3 are not executed. · line 255
Quoted 6 lines
man3/system.3 +3
-0@@ -250,6 +250,39 @@ are not executed. Such risks are especially grave when using .BR system () from a privileged program. +.SH BUGS +./" [BUG 211029](https://bugzilla.kernel.org/show_bug.cgi?id=211029) +./" [glibc 27143](https://sourceware.org/bugzilla/show_bug.cgi?id=27143)
Better add the Austin bug URL mnow.
man3/system.3 are not executed. · line 263
Quoted 8 lines
man3/system.3 +8
-0+If the command name starts with a hyphen, +.BR sh (1) +interprets the command name as an option, +and the behavior is undefined +(See the +.B \-c +option in +.BR sh (1).).
s/.)./.)/
man3/system.3 are not executed. · line 266
Quoted 3 lines
man3/system.3 +3
-0+This behavior is mandated by POSIX. +To work around this problem, +prepend the command with a space as below:
It's a funny workaround :-). But it seems to work in bash, dash, and zsh. Interestingly. (t)csh doesn't even have the problem.
I don't think we need the example below in the manual page (see my comments above), although you could include it in the commit message.
Thanks,
Michael
Quoted 24 lines
man3/system.3 +20
-0+.PP +.RS 4 +.EX +/* system_hyphen.c */ + +#include <stdlib.h> + +int +main(void) +{ + system(" -echo Hello world!"); + exit(EXIT_SUCCESS); +} +.PP +.RB "$" " sudo ln \-s \-T /usr/bin/echo /usr/bin/\-echo;" +.RB "$" " cc \-o system_hyphen system_hyphen.c;" +.RB "$" " ./system_hyphen;" +Hello world! +.EE +.RE .SH SEE ALSO .BR sh (1), .BR execve (2),
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/