From: Bruno Haible Date: Mon, 31 Mar 2003 20:19:41 +0000 (+0000) Subject: Fix handling of empty string. X-Git-Tag: v0.12~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8ecc4cab5d0c640935d291b7268826a6d483a2a;p=thirdparty%2Fgettext.git Fix handling of empty string. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 15f1a97e6..c577ae40c 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-03-31 Bruno Haible + + * sh-quote.c (shell_quote_length, shell_quote_copy): Handle empty + argument string correctly. + 2003-03-30 Bruno Haible * progname.c (ISSLASH, HAS_DEVICE, IS_PATH_WITH_DIR, diff --git a/gettext-tools/lib/sh-quote.c b/gettext-tools/lib/sh-quote.c index 41c82c3bb..4052aba1d 100644 --- a/gettext-tools/lib/sh-quote.c +++ b/gettext-tools/lib/sh-quote.c @@ -1,5 +1,5 @@ /* Shell quoting. - Copyright (C) 2001-2002 Free Software Foundation, Inc. + Copyright (C) 2001-2003 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -29,13 +29,20 @@ #include "xmalloc.h" +/* Must quote the program name and arguments since Unix shells interpret + characters like " ", "'", "<", ">", "$" etc. in a special way. This + kind of quoting should work unless the string contains "\n" and we call + csh. But we are lucky: only /bin/sh will be used. */ + #define SHELL_SPECIAL_CHARS "\t\n !\"#$&'()*;<=>?[\\]`{|}~" /* Returns the number of bytes needed for the quoted string. */ size_t shell_quote_length (const char *string) { - if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL) + if (string[0] == '\0') + return 2; + else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL) return strlen (string); else { @@ -67,7 +74,12 @@ shell_quote_length (const char *string) char * shell_quote_copy (char *p, const char *string) { - if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL) + if (string[0] == '\0') + { + memcpy (p, "''", 2); + return p + 2; + } + else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL) { memcpy (p, string, strlen (string)); return p + strlen (string);