aboutsummaryrefslogtreecommitdiff
path: root/posix
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-03-25 15:21:09 +0000
committerUlrich Drepper <drepper@redhat.com>1998-03-25 15:21:09 +0000
commit68b506045507245594280b53e1ccdd425bc0a6a5 (patch)
tree3522b722dd47ae4016b2e43b3349e1e45a288439 /posix
parent0669867278c8e633bf5c3e52ded6ea3a2e0034f9 (diff)
downloadglibc-68b506045507245594280b53e1ccdd425bc0a6a5.zip
glibc-68b506045507245594280b53e1ccdd425bc0a6a5.tar.gz
glibc-68b506045507245594280b53e1ccdd425bc0a6a5.tar.bz2
Update.
1998-03-25 Ulrich Drepper <drepper@cygnus.com> * glibcbug.in: Create files safely when mktemp is not available. * sysdeps/unix/sysv/linux/adjtime.c: Make weak alias appear again. Patch by a sun <asun@saul1.u.washington.edu>. 1998-03-25 Thorsten Kukuk <kukuk@vt.uni-paderborn.de> * libc.map: Rename getname to getnetname. 1998-03-25 13:35 Ulrich Drepper <drepper@cygnus.com> * manual/maint.texi: Use supported platform in examples. * manual/install.texi: Document some installation tips. 1998-03-25 10:56 Ulrich Drepper <drepper@cygnus.com> * posix/wordexp.c: Fix some memory leaks and makes $* more efficient. Fix a bug so that it returns an error if a numeric parameter is unset and WRDE_UNDEF is set. Patch by Andreas Schwab and Tim Waugh. * posix/wordexp-test.c: Add new new test. 1998-03-25 Ulrich Drepper <drepper@cygnus.com> * posix/regex.c (regex_compile): Last patch wasn't entirely correct. Patch by Alain Magloire <alainm@rcsm.ece.mcgill.ca>. 1998-03-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * manual/filesys.texi (Scanning Directory Content): Fix typo. 1998-03-25 09:24 Bernd Schmidt <crux@Pool.Informatik.RWTH-Aachen.DE> * sysdeps/i386/bits/string.h: Fix all assembler statements so that clobbered registers don't appear as operands.
Diffstat (limited to 'posix')
-rw-r--r--posix/regex.c4
-rw-r--r--posix/wordexp-test.c1
-rw-r--r--posix/wordexp.c99
3 files changed, 63 insertions, 41 deletions
diff --git a/posix/regex.c b/posix/regex.c
index 8c259d9..0778bb8 100644
--- a/posix/regex.c
+++ b/posix/regex.c
@@ -2171,14 +2171,14 @@ regex_compile (pattern, size, syntax, bufp)
for (;;)
{
PATFETCH (c);
- if (c == ':' || c == ']' || !isalpha (c) || p == pend
+ if ((c == ':' && *p == ']') || p == pend
|| c1 == CHAR_CLASS_MAX_LENGTH)
break;
str[c1++] = c;
}
str[c1] = '\0';
- /* If isn't a word bracketed by `[:' and:`]':
+ /* If isn't a word bracketed by `[:' and `:]':
undo the ending character, the letters, and leave
the leading `:' and `[' (but set bits for them). */
if (c == ':' && *p == ']')
diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c
index d9ecadc..9ee1ab7 100644
--- a/posix/wordexp-test.c
+++ b/posix/wordexp-test.c
@@ -138,6 +138,7 @@ struct test_case_struct
{ WRDE_BADCHAR, NULL, "close-brace}", 0, 0, { NULL, } },
{ WRDE_CMDSUB, NULL, "$(ls)", WRDE_NOCMD, 0, { NULL, } },
{ WRDE_BADVAL, NULL, "$var", WRDE_UNDEF, 0, { NULL, } },
+ { WRDE_BADVAL, NULL, "$9", WRDE_UNDEF, 0, { NULL, } },
{ WRDE_SYNTAX, NULL, "$[50+20))", 0, 0, { NULL, } },
{ WRDE_SYNTAX, NULL, "${%%noparam}", 0, 0, { NULL, } },
{ WRDE_SYNTAX, NULL, "${missing-brace", 0, 0, { NULL, } },
diff --git a/posix/wordexp.c b/posix/wordexp.c
index 64d5b3c..265ddd8 100644
--- a/posix/wordexp.c
+++ b/posix/wordexp.c
@@ -1147,7 +1147,7 @@ parse_param (char **word, size_t *word_length, size_t *max_length,
switch (words[*offset])
{
case '}':
- /* Evalute. */
+ /* Evaluate. */
goto envsubst;
case '#':
@@ -1295,36 +1295,23 @@ envsubst:
/* Is it `$*' or `$@' (unquoted) ? */
else if (*env == '*' || (*env == '@' && !quoted))
{
- size_t plist_len = 1;
+ size_t plist_len = 0;
int p;
+ char *end;
/* Build up value parameter by parameter (copy them) */
for (p = 1; __libc_argv[p]; ++p)
+ plist_len += strlen (__libc_argv[p]) + 1; /* for space */
+ value = malloc (plist_len);
+ if (value == NULL)
+ goto no_space;
+ end = value;
+ *end = 0;
+ for (p = 1; __libc_argv[p]; ++p)
{
- char *old_pointer = value;
- size_t argv_len = strlen (__libc_argv[p]);
- size_t old_plist_len = plist_len;
-
- if (value)
- value[plist_len - 1] = 0;
-
- plist_len += 1 + argv_len;
-
- /* First realloc will act as malloc because value is
- * initialised to NULL. */
- value = realloc (value, plist_len); /* ### re-work this */
- if (value == NULL)
- {
- free (old_pointer);
- return WRDE_NOSPACE;
- }
-
- memcpy (&value[old_plist_len - 1], __libc_argv[p], argv_len + 1);
- if (__libc_argv[p + 1])
- {
- value[plist_len - 1] = '\0';
- value[plist_len - 2] = ' ';
- }
+ if (p > 1)
+ *end++ = ' ';
+ end = __stpcpy (end, __libc_argv[p]);
}
free_value = 1;
@@ -1336,11 +1323,7 @@ envsubst:
/* Each parameter is a separate word ("$@") */
if (__libc_argc == 2)
- {
- value = __strdup (__libc_argv[1]);
- if (value == NULL)
- goto no_space;
- }
+ value = __libc_argv[1];
else if (__libc_argc > 2)
{
int p;
@@ -1361,8 +1344,6 @@ envsubst:
/* Start a new word with the last parameter. */
*word = w_newword (word_length, max_length);
value = __strdup (__libc_argv[p]);
- if (value == NULL)
- goto no_space;
}
else
{
@@ -1373,11 +1354,16 @@ envsubst:
}
}
else
+ value = getenv (env);
+
+ if (value == NULL && (flags & WRDE_UNDEF))
{
- value = getenv (env);
- if (value == NULL && (flags & WRDE_UNDEF))
- /* Variable not defined. */
- return WRDE_BADVAL;
+ /* Variable not defined. */
+ if (pattern)
+ free (pattern);
+ if (env)
+ free (env);
+ return WRDE_BADVAL;
}
if (action != ACT_NONE)
@@ -1408,7 +1394,19 @@ envsubst:
if (fnmatch (pattern, value, 0) != FNM_NOMATCH)
{
*p = c;
- value = p;
+ if (free_value)
+ {
+ char *newval = __strdup (p);
+ if (newval == NULL)
+ {
+ free (value);
+ goto no_space;
+ }
+ free (value);
+ value = newval;
+ }
+ else
+ value = p;
break;
}
*p = c;
@@ -1424,7 +1422,19 @@ envsubst:
if (fnmatch (pattern, value, 0) != FNM_NOMATCH)
{
*p = c;
- value = p;
+ if (free_value)
+ {
+ char *newval = __strdup (p);
+ if (newval == NULL)
+ {
+ free (value);
+ goto no_space;
+ }
+ free (value);
+ value = newval;
+ }
+ else
+ value = p;
break;
}
*p = c;
@@ -1519,6 +1529,8 @@ envsubst:
free (env);
free (pattern);
+ if (free_value)
+ free (value);
return error;
case ACT_NULL_SUBST:
@@ -1531,6 +1543,8 @@ envsubst:
/* Substitute NULL */
free (env);
free (pattern);
+ if (free_value)
+ free (value);
return 0;
}
@@ -1540,6 +1554,9 @@ envsubst:
wordexp_t we;
int i;
+ if (free_value)
+ free (value);
+
if (quoted)
{
/* No field-splitting is allowed, so imagine
@@ -1622,6 +1639,8 @@ envsubst:
/* Substitute NULL */
free (env);
free (pattern);
+ if (free_value)
+ free (value);
return 0;
case ACT_NULL_ASSIGN:
@@ -1634,6 +1653,8 @@ envsubst:
/* Substitute NULL */
free (env);
free (pattern);
+ if (free_value)
+ free (value);
return 0;
}