commit bash-20190308 snapshot

This commit is contained in:
Chet Ramey
2019-03-11 08:57:46 -04:00
parent f6388ab913
commit 203f479c03
12 changed files with 237 additions and 41 deletions
+11 -2
View File
@@ -1194,7 +1194,7 @@ glob_filename (pathname, flags)
if (d[directory_len - 1] == '/')
d[directory_len - 1] = '\0';
directories = glob_filename (d, dflags);
directories = glob_filename (d, dflags|GX_RECURSE);
if (free_dirname)
{
@@ -1351,11 +1351,20 @@ only_filename:
free (directory_name);
return (NULL);
}
if (directory_len > 0 && hasglob == 2) /* need to dequote */
/* If we have a directory name with quoted characters, and we are
being called recursively to glob the directory portion of a pathname,
we need to dequote the directory name before returning it so the
caller can read the directory */
if (directory_len > 0 && hasglob == 2 && (flags & GX_RECURSE) != 0)
{
dequote_pathname (directory_name);
directory_len = strlen (directory_name);
}
/* We could check whether or not the dequoted directory_name is a
directory and return it here, returning the original directory_name
if not, but we don't do that yet. I'm not sure it matters. */
/* Handle GX_MARKDIRS here. */
result[0] = (char *) malloc (directory_len + 1);
if (result[0] == NULL)
+1
View File
@@ -30,6 +30,7 @@
#define GX_NULLDIR 0x100 /* internal -- no directory preceding pattern */
#define GX_ADDCURDIR 0x200 /* internal -- add passed directory name */
#define GX_GLOBSTAR 0x400 /* turn on special handling of ** */
#define GX_RECURSE 0x800 /* internal -- glob_filename called recursively */
extern int glob_pattern_p __P((const char *));
extern char **glob_vector __P((char *, char *, int));
+2 -2
View File
@@ -213,10 +213,10 @@ sh_eaccess (path, mode)
# else /* HAVE_EACCESS */ /* FreeBSD */
ret = eaccess (path, mode); /* XXX -- not always correct for X_OK */
# endif /* HAVE_EACCESS */
# if defined (__FreeBSD__) || defined (SOLARIS)
# if defined (__FreeBSD__) || defined (SOLARIS) || defined (_AIX)
if (ret == 0 && current_user.euid == 0 && mode == X_OK)
return (sh_stataccess (path, mode));
# endif /* __FreeBSD__ || SOLARIS */
# endif /* __FreeBSD__ || SOLARIS || _AIX */
return ret;
#elif defined (EFF_ONLY_OK) /* SVR4(?), SVR4.2 */
return access (path, mode|EFF_ONLY_OK);
+59 -14
View File
@@ -1,6 +1,6 @@
/* shquote - functions to quote and dequote strings */
/* Copyright (C) 1999-2015 Free Software Foundation, Inc.
/* Copyright (C) 1999-2019 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -136,8 +136,15 @@ sh_double_quote (string)
const char *string;
{
register unsigned char c;
int mb_cur_max;
char *result, *r;
const char *s;
size_t slen;
const char *s, *send;
DECLARE_MBSTATE;
slen = strlen (string);
send = string + slen;
mb_cur_max = MB_CUR_MAX;
result = (char *)xmalloc (3 + (2 * strlen (string)));
r = result;
@@ -148,12 +155,19 @@ sh_double_quote (string)
/* Backslash-newline disappears within double quotes, so don't add one. */
if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n')
*r++ = '\\';
#if 0
/* Assume that the string will not be further expanded. */
else if (c == CTLESC || c == CTLNUL)
*r++ = CTLESC; /* could be '\\'? */
#if defined (HANDLE_MULTIBYTE)
if ((locale_utf8locale && (c & 0x80)) ||
(locale_utf8locale == 0 && mb_cur_max > 1 && is_basic (c) == 0))
{
COPY_CHAR_P (r, s, send);
s--; /* compensate for auto-increment in loop above */
continue;
}
#endif
/* Assume that the string will not be further expanded, so no need to
add CTLESC to protect CTLESC or CTLNUL. */
*r++ = c;
}
@@ -171,16 +185,29 @@ sh_mkdoublequoted (s, slen, flags)
int slen, flags;
{
char *r, *ret;
int rlen;
const char *send;
int rlen, mb_cur_max;
DECLARE_MBSTATE;
send = s + slen;
mb_cur_max = flags ? MB_CUR_MAX : 1;
rlen = (flags == 0) ? slen + 3 : (2 * slen) + 1;
ret = r = (char *)xmalloc (rlen);
*r++ = '"';
while (*s)
{
if (flags && *s == '"')
*r++ = '\\';
#if defined (HANDLE_MULTIBYTE)
if (flags && ((locale_utf8locale && (*s & 0x80)) ||
(locale_utf8locale == 0 && mb_cur_max > 1 && is_basic (*s) == 0)))
{
COPY_CHAR_P (r, s, send);
continue;
}
#endif
*r++ = *s++;
}
*r++ = '"';
@@ -259,7 +286,8 @@ sh_backslash_quote (string, table, flags)
*r++ = c;
continue;
}
if (mb_cur_max > 1 && is_basic (c) == 0)
if ((locale_utf8locale && (c & 0x80)) ||
(locale_utf8locale == 0 && mb_cur_max > 1 && is_basic (c) == 0))
{
COPY_CHAR_P (r, s, send);
s--; /* compensate for auto-increment in loop above */
@@ -291,18 +319,35 @@ sh_backslash_quote_for_double_quotes (string)
char *string;
{
unsigned char c;
char *result, *r, *s;
result = (char *)xmalloc (2 * strlen (string) + 1);
char *result, *r, *s, *send;
size_t slen;
int mb_cur_max;
DECLARE_MBSTATE;
slen = strlen (string);
send = string + slen;
mb_cur_max = MB_CUR_MAX;
result = (char *)xmalloc (2 * slen + 1);
for (r = result, s = string; s && (c = *s); s++)
{
if (sh_syntaxtab[c] & CBSDQUOTE)
/* Backslash-newline disappears within double quotes, so don't add one. */
if ((sh_syntaxtab[c] & CBSDQUOTE) && c != '\n')
*r++ = '\\';
/* I should probably add flags for these to sh_syntaxtab[] */
/* I should probably use the CSPECL flag for these in sh_syntaxtab[] */
else if (c == CTLESC || c == CTLNUL)
*r++ = CTLESC; /* could be '\\'? */
#if defined (HANDLE_MULTIBYTE)
if ((locale_utf8locale && (c & 0x80)) ||
(locale_utf8locale == 0 && mb_cur_max > 1 && is_basic (c) == 0))
{
COPY_CHAR_P (r, s, send);
s--; /* compensate for auto-increment in loop above */
continue;
}
#endif
*r++ = c;
}