mirror of
https://github.com/sheumann/hush.git
synced 2025-01-10 16:29:44 +00:00
Remember to delete un-expandable variables, and do a better job of expanding
shell-specific things in case the wordexp implementation is broken (ie. the stubbed out wordexp in uClibc). -Erik
This commit is contained in:
parent
ca6045955d
commit
32f8c170b0
34
lash.c
34
lash.c
@ -959,15 +959,29 @@ static int expand_arguments(char *command)
|
|||||||
else
|
else
|
||||||
var = itoa(last_bg_pid);
|
var = itoa(last_bg_pid);
|
||||||
break;
|
break;
|
||||||
#if 0
|
/* Everything else like $$, $#, $[0-9], etc should all be
|
||||||
/* Everything else like $$, $#, $[0-9], etcshould all be
|
* expanded by wordexp(), so we can in theory skip that stuff
|
||||||
* expanded by wordexp(), so we can skip that stuff here */
|
* here, but just to be on the safe side (i.e. since uClibc
|
||||||
|
* wordexp doesn't do this stuff yet), lets leave it in for
|
||||||
|
* now. */
|
||||||
case '$':
|
case '$':
|
||||||
|
var = itoa(getpid());
|
||||||
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
|
var = itoa(argc-1);
|
||||||
|
break;
|
||||||
case '0':case '1':case '2':case '3':case '4':
|
case '0':case '1':case '2':case '3':case '4':
|
||||||
case '5':case '6':case '7':case '8':case '9':
|
case '5':case '6':case '7':case '8':case '9':
|
||||||
|
{
|
||||||
|
int index=*(dst + 1)-48;
|
||||||
|
if (index >= argc) {
|
||||||
|
var='\0';
|
||||||
|
} else {
|
||||||
|
var = argv[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (var) {
|
if (var) {
|
||||||
@ -982,9 +996,17 @@ static int expand_arguments(char *command)
|
|||||||
memmove(dst+subst_len, next_dst+1, subst_len);
|
memmove(dst+subst_len, next_dst+1, subst_len);
|
||||||
/* Now copy in the new stuff */
|
/* Now copy in the new stuff */
|
||||||
strncpy(dst, var, subst_len);
|
strncpy(dst, var, subst_len);
|
||||||
|
src = dst;
|
||||||
|
src++;
|
||||||
|
} else {
|
||||||
|
/* Seems we got an un-expandable variable. So delete it. */
|
||||||
|
char *next_dst;
|
||||||
|
if ((next_dst=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?")) != NULL) {
|
||||||
|
/* Move stuff to the end of the string to accommodate filling
|
||||||
|
* the created gap with the new stuff */
|
||||||
|
memmove(dst, next_dst, next_dst-dst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src = dst;
|
|
||||||
src++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
34
sh.c
34
sh.c
@ -959,15 +959,29 @@ static int expand_arguments(char *command)
|
|||||||
else
|
else
|
||||||
var = itoa(last_bg_pid);
|
var = itoa(last_bg_pid);
|
||||||
break;
|
break;
|
||||||
#if 0
|
/* Everything else like $$, $#, $[0-9], etc should all be
|
||||||
/* Everything else like $$, $#, $[0-9], etcshould all be
|
* expanded by wordexp(), so we can in theory skip that stuff
|
||||||
* expanded by wordexp(), so we can skip that stuff here */
|
* here, but just to be on the safe side (i.e. since uClibc
|
||||||
|
* wordexp doesn't do this stuff yet), lets leave it in for
|
||||||
|
* now. */
|
||||||
case '$':
|
case '$':
|
||||||
|
var = itoa(getpid());
|
||||||
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
|
var = itoa(argc-1);
|
||||||
|
break;
|
||||||
case '0':case '1':case '2':case '3':case '4':
|
case '0':case '1':case '2':case '3':case '4':
|
||||||
case '5':case '6':case '7':case '8':case '9':
|
case '5':case '6':case '7':case '8':case '9':
|
||||||
|
{
|
||||||
|
int index=*(dst + 1)-48;
|
||||||
|
if (index >= argc) {
|
||||||
|
var='\0';
|
||||||
|
} else {
|
||||||
|
var = argv[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (var) {
|
if (var) {
|
||||||
@ -982,9 +996,17 @@ static int expand_arguments(char *command)
|
|||||||
memmove(dst+subst_len, next_dst+1, subst_len);
|
memmove(dst+subst_len, next_dst+1, subst_len);
|
||||||
/* Now copy in the new stuff */
|
/* Now copy in the new stuff */
|
||||||
strncpy(dst, var, subst_len);
|
strncpy(dst, var, subst_len);
|
||||||
|
src = dst;
|
||||||
|
src++;
|
||||||
|
} else {
|
||||||
|
/* Seems we got an un-expandable variable. So delete it. */
|
||||||
|
char *next_dst;
|
||||||
|
if ((next_dst=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?")) != NULL) {
|
||||||
|
/* Move stuff to the end of the string to accommodate filling
|
||||||
|
* the created gap with the new stuff */
|
||||||
|
memmove(dst, next_dst, next_dst-dst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src = dst;
|
|
||||||
src++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
34
shell/lash.c
34
shell/lash.c
@ -959,15 +959,29 @@ static int expand_arguments(char *command)
|
|||||||
else
|
else
|
||||||
var = itoa(last_bg_pid);
|
var = itoa(last_bg_pid);
|
||||||
break;
|
break;
|
||||||
#if 0
|
/* Everything else like $$, $#, $[0-9], etc should all be
|
||||||
/* Everything else like $$, $#, $[0-9], etcshould all be
|
* expanded by wordexp(), so we can in theory skip that stuff
|
||||||
* expanded by wordexp(), so we can skip that stuff here */
|
* here, but just to be on the safe side (i.e. since uClibc
|
||||||
|
* wordexp doesn't do this stuff yet), lets leave it in for
|
||||||
|
* now. */
|
||||||
case '$':
|
case '$':
|
||||||
|
var = itoa(getpid());
|
||||||
|
break;
|
||||||
case '#':
|
case '#':
|
||||||
|
var = itoa(argc-1);
|
||||||
|
break;
|
||||||
case '0':case '1':case '2':case '3':case '4':
|
case '0':case '1':case '2':case '3':case '4':
|
||||||
case '5':case '6':case '7':case '8':case '9':
|
case '5':case '6':case '7':case '8':case '9':
|
||||||
|
{
|
||||||
|
int index=*(dst + 1)-48;
|
||||||
|
if (index >= argc) {
|
||||||
|
var='\0';
|
||||||
|
} else {
|
||||||
|
var = argv[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (var) {
|
if (var) {
|
||||||
@ -982,9 +996,17 @@ static int expand_arguments(char *command)
|
|||||||
memmove(dst+subst_len, next_dst+1, subst_len);
|
memmove(dst+subst_len, next_dst+1, subst_len);
|
||||||
/* Now copy in the new stuff */
|
/* Now copy in the new stuff */
|
||||||
strncpy(dst, var, subst_len);
|
strncpy(dst, var, subst_len);
|
||||||
|
src = dst;
|
||||||
|
src++;
|
||||||
|
} else {
|
||||||
|
/* Seems we got an un-expandable variable. So delete it. */
|
||||||
|
char *next_dst;
|
||||||
|
if ((next_dst=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?")) != NULL) {
|
||||||
|
/* Move stuff to the end of the string to accommodate filling
|
||||||
|
* the created gap with the new stuff */
|
||||||
|
memmove(dst, next_dst, next_dst-dst);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src = dst;
|
|
||||||
src++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user