[RFC] system.3: Document bug when the command name starts with a hypen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Cc: Florian Weimer <fweimer@xxxxxxxxxx>
Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---

Hi Ciprian,

If you report a bug to the Austin Group,
please CC linux-man@xxxxxxxxxxxxxxx,
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




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux