linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] system.3: Document bug when the command name starts with a hypen
@ 2021-01-04 15:13 Alejandro Colomar
  2021-01-04 15:54 ` Ciprian Dorin Craciun
  2021-01-05 13:23 ` [RFC] system.3: Document bug " Michael Kerrisk (man-pages)
  0 siblings, 2 replies; 17+ messages in thread
From: Alejandro Colomar @ 2021-01-04 15:13 UTC (permalink / raw)
  To: mtk.manpages
  Cc: Alejandro Colomar, linux-man, Ciprian Dorin Craciun, Florian Weimer

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.

Reported-by: Ciprian Dorin Craciun <ciprian.craciun@gmail.com>
Cc: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---

Hi Ciprian,

If you report a bug to the Austin Group,
please CC linux-man@vger.kernel.org,
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(+)

diff --git a/man3/system.3 b/man3/system.3
index aef40417a..5a9318dec 100644
--- a/man3/system.3
+++ b/man3/system.3
@@ -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),
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-01-18 16:18 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04 15:13 [RFC] system.3: Document bug when the command name starts with a hypen Alejandro Colomar
2021-01-04 15:54 ` Ciprian Dorin Craciun
2021-01-04 18:04   ` [PATCH] system.3: Document bug and workaround " Alejandro Colomar
2021-01-04 18:32     ` Alejandro Colomar (man-pages)
2021-01-04 20:02       ` Alejandro Colomar (man-pages)
2021-01-08 14:15     ` [PATCH v2] " Alejandro Colomar
2021-01-08 14:20     ` [PATCH v3] " Alejandro Colomar
2021-01-08 14:22     ` [PATCH v4] " Alejandro Colomar
2021-01-08 14:28       ` Alejandro Colomar (man-pages)
2021-01-18 15:28         ` Ping: " Alejandro Colomar (man-pages)
2021-01-18 15:37           ` Michael Kerrisk (man-pages)
2021-01-18 15:45             ` Alejandro Colomar (man-pages)
2021-01-18 15:58               ` Michael Kerrisk (man-pages)
2021-01-18 16:11                 ` Alejandro Colomar (man-pages)
2021-01-18 15:36         ` Michael Kerrisk (man-pages)
2021-01-18 15:35       ` Michael Kerrisk (man-pages)
2021-01-05 13:23 ` [RFC] system.3: Document bug " Michael Kerrisk (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).