aboutsummaryrefslogtreecommitdiff
path: root/bin/sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/TOUR2
-rw-r--r--bin/sh/b.c106
-rw-r--r--bin/sh/error.c46
-rw-r--r--bin/sh/eval.c5
-rw-r--r--bin/sh/expand.c4
-rw-r--r--bin/sh/mknodes.c15
-rw-r--r--bin/sh/mt78
-rw-r--r--bin/sh/parser.c12
-rw-r--r--bin/sh/sh.14
9 files changed, 50 insertions, 222 deletions
diff --git a/bin/sh/TOUR b/bin/sh/TOUR
index 7cc0f226a379..aa593346f337 100644
--- a/bin/sh/TOUR
+++ b/bin/sh/TOUR
@@ -325,7 +325,7 @@ put structures allocated. "Output" represents the standard out-
put, "errout" the standard error, and "memout" contains output
which is to be stored in memory. This last is used when a buil-
tin command appears in backquotes, to allow its output to be col-
-lected without doing any I/O through the UNIX operating system.
+lected without doing any I/O through the operating system.
The variables out1 and out2 normally point to output and errout,
respectively, but they are set to point to memout when appropri-
ate inside backquotes.
diff --git a/bin/sh/b.c b/bin/sh/b.c
deleted file mode 100644
index 9b7f568ecdff..000000000000
--- a/bin/sh/b.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * This file was generated by the mkbuiltins program.
- */
-
-#ifndef lint
-static char rcsid[] = "b.c,v 1.2 1993/08/02 17:15:45 mycroft Exp";
-#endif /* not lint */
-
-#include "shell.h"
-#include "builtins.h"
-
-int bltincmd();
-int bgcmd();
-int breakcmd();
-int cdcmd();
-int dotcmd();
-int echocmd();
-int evalcmd();
-int execcmd();
-int exitcmd();
-int exportcmd();
-int fgcmd();
-int getoptscmd();
-int hashcmd();
-int jobidcmd();
-int jobscmd();
-int lccmd();
-int localcmd();
-int pwdcmd();
-int readcmd();
-int returncmd();
-int setcmd();
-int setvarcmd();
-int shiftcmd();
-int trapcmd();
-int truecmd();
-int umaskcmd();
-int unsetcmd();
-int waitcmd();
-
-int (*const builtinfunc[])() = {
- bltincmd,
- bgcmd,
- breakcmd,
- cdcmd,
- dotcmd,
- echocmd,
- evalcmd,
- execcmd,
- exitcmd,
- exportcmd,
- fgcmd,
- getoptscmd,
- hashcmd,
- jobidcmd,
- jobscmd,
- lccmd,
- localcmd,
- pwdcmd,
- readcmd,
- returncmd,
- setcmd,
- setvarcmd,
- shiftcmd,
- trapcmd,
- truecmd,
- umaskcmd,
- unsetcmd,
- waitcmd,
-};
-
-const struct builtincmd builtincmd[] = {
- "command", 0,
- "bg", 1,
- "break", 2,
- "continue", 2,
- "cd", 3,
- "chdir", 3,
- ".", 4,
- "echo", 5,
- "eval", 6,
- "exec", 7,
- "exit", 8,
- "export", 9,
- "readonly", 9,
- "fg", 10,
- "getopts", 11,
- "hash", 12,
- "jobid", 13,
- "jobs", 14,
- "lc", 15,
- "local", 16,
- "pwd", 17,
- "read", 18,
- "return", 19,
- "set", 20,
- "setvar", 21,
- "shift", 22,
- "trap", 23,
- ":", 24,
- "true", 24,
- "umask", 25,
- "unset", 26,
- "wait", 27,
- NULL, 0
-};
diff --git a/bin/sh/error.c b/bin/sh/error.c
index 430de28465a8..6b1c010db085 100644
--- a/bin/sh/error.c
+++ b/bin/sh/error.c
@@ -178,55 +178,55 @@ struct errname {
#define ALL (E_OPEN|E_CREAT|E_EXEC)
STATIC const struct errname errormsg[] = {
- EINTR, ALL, "interrupted",
- EACCES, ALL, "permission denied",
+ EINTR, ALL, "interrupted",
+ EACCES, ALL, "permission denied",
EIO, ALL, "I/O error",
- ENOENT, E_OPEN, "no such file",
+ ENOENT, E_OPEN, "no such file",
ENOENT, E_CREAT, "directory nonexistent",
- ENOENT, E_EXEC, "not found",
+ ENOENT, E_EXEC, "not found",
ENOTDIR, E_OPEN, "no such file",
ENOTDIR, E_CREAT, "directory nonexistent",
ENOTDIR, E_EXEC, "not found",
- EISDIR, ALL, "is a directory",
-/* EMFILE, ALL, "too many open files", */
- ENFILE, ALL, "file table overflow",
- ENOSPC, ALL, "file system full",
+ EISDIR, ALL, "is a directory",
+/* EMFILE, ALL, "too many open files", */
+ ENFILE, ALL, "file table overflow",
+ ENOSPC, ALL, "file system full",
#ifdef EDQUOT
- EDQUOT, ALL, "disk quota exceeded",
+ EDQUOT, ALL, "disk quota exceeded",
#endif
#ifdef ENOSR
- ENOSR, ALL, "no streams resources",
+ ENOSR, ALL, "no streams resources",
#endif
- ENXIO, ALL, "no such device or address",
- EROFS, ALL, "read-only file system",
- ETXTBSY, ALL, "text busy",
+ ENXIO, ALL, "no such device or address",
+ EROFS, ALL, "read-only file system",
+ ETXTBSY, ALL, "text busy",
#ifdef SYSV
- EAGAIN, E_EXEC, "not enough memory",
+ EAGAIN, E_EXEC, "not enough memory",
#endif
- ENOMEM, ALL, "not enough memory",
+ ENOMEM, ALL, "not enough memory",
#ifdef ENOLINK
- ENOLINK, ALL, "remote access failed",
+ ENOLINK, ALL, "remote access failed",
#endif
#ifdef EMULTIHOP
- EMULTIHOP, ALL, "remote access failed",
+ EMULTIHOP, ALL, "remote access failed",
#endif
#ifdef ECOMM
- ECOMM, ALL, "remote access failed",
+ ECOMM, ALL, "remote access failed",
#endif
#ifdef ESTALE
- ESTALE, ALL, "remote access failed",
+ ESTALE, ALL, "remote access failed",
#endif
#ifdef ETIMEDOUT
- ETIMEDOUT, ALL, "remote access failed",
+ ETIMEDOUT, ALL, "remote access failed",
#endif
#ifdef ELOOP
- ELOOP, ALL, "symbolic link loop",
+ ELOOP, ALL, "symbolic link loop",
#endif
- E2BIG, E_EXEC, "argument list too long",
+ E2BIG, E_EXEC, "argument list too long",
#ifdef ELIBACC
ELIBACC, E_EXEC, "shared library missing",
#endif
- 0, 0, NULL
+ 0, 0, NULL
};
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 718876e95b50..d6bd1296291d 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -521,7 +521,10 @@ evalbackcmd(n, result)
result->buf = NULL;
result->nleft = 0;
result->jp = NULL;
- if (n->type == NCMD) {
+ /* No command inside the backqotes, so do nothing. */
+ if (n == NULL)
+ ;
+ else if (n->type == NCMD) {
evalcommand(n, EV_BACKCMD, result);
} else {
if (pipe(pip) < 0)
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 1d5864d233bf..95d2e504cd70 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -664,8 +664,10 @@ expandmeta(str)
savelastp = exparg.lastp;
INTOFF;
if (expdir == NULL)
- expdir = ckmalloc(1024); /* I hope this is big enough */
+ expdir = ckmalloc(8192); /* I hope this is big enough */
expmeta(expdir, str->text);
+ if(strlen(expdir) >= 8192)
+ error("malloc overflow in sh:expand.c in ckmalloc(8192)\n");
ckfree(expdir);
expdir = NULL;
INTON;
diff --git a/bin/sh/mknodes.c b/bin/sh/mknodes.c
index 53c8508ee1ec..083138b0147c 100644
--- a/bin/sh/mknodes.c
+++ b/bin/sh/mknodes.c
@@ -99,13 +99,16 @@ char *savestr();
#define equal(s1, s2) (strcmp(s1, s2) == 0)
-main(argc, argv)
- char **argv;
- {
- if (argc != 3)
+main(int argc, char **argv)
+{
+ if (argc != 3) {
error("usage: mknodes file\n");
- if ((infp = fopen(argv[1], "r")) == NULL)
+ return(1);
+ }
+ if ((infp = fopen(argv[1], "r")) == NULL) {
error("Can't open %s", argv[1]);
+ return(1);
+ }
while (readline()) {
if (line[0] == ' ' || line[0] == '\t')
parsefield();
@@ -113,7 +116,7 @@ main(argc, argv)
parsenode();
}
output(argv[2]);
- return 0;
+ return(0);
}
diff --git a/bin/sh/mt b/bin/sh/mt
deleted file mode 100644
index f07a32e28d7c..000000000000
--- a/bin/sh/mt
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/sh -
-#
-# Copyright (c) 1991 The Regents of the University of California.
-# All rights reserved.
-#
-# This code is derived from software contributed to Berkeley by
-# Kenneth Almquist.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-# 3. All advertising materials mentioning features or use of this software
-# must display the following acknowledgement:
-# This product includes software developed by the University of
-# California, Berkeley and its contributors.
-# 4. Neither the name of the University nor the names of its contributors
-# may be used to endorse or promote products derived from this software
-# without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-# SUCH DAMAGE.
-#
-# @(#)mktokens 5.1 (Berkeley) 3/7/91
-#
-# /b/source/CVS/src/bin/sh/mt,v 1.3 1993/03/23 00:28:48 cgd Exp
-
-# The following is a list of tokens. The second column is nonzero if the
-# token marks the end of a list. The third column is the name to print in
-# error messages.
-
-cat > /tmp/ka$$ <<\!
-TEOF 1 end of file
-TNL 0 newline
-TSEMI 0 ";"
-TBACKGND 0 "&"
-TAND 0 "&&"
-TOR 0 "||"
-TPIPE 0 "|"
-TLP 0 "("
-TRP 1 ")"
-TENDCASE 1 ";;"
-TENDBQUOTE 1 "`"
-TREDIR 0 redirection
-TWORD 0 word
-TIF 0 "if"
-TTHEN 1 "then"
-TELSE 1 "else"
-TELIF 1 "elif"
-TFI 1 "fi"
-TWHILE 0 "while"
-TUNTIL 0 "until"
-TFOR 0 "for"
-TDO 1 "do"
-TDONE 1 "done"
-TBEGIN 0 "{"
-TEND 1 "}"
-TCASE 0 "case"
-TESAC 1 "esac"
-!
-nl=`wc -l /tmp/ka$$`
-exec
-awk "-F " '{print $1 "#define " NR-1}' /tmp/ka$$
-
-rm /tmp/ka$$
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index dc0e046ea171..1ab8751d0c7e 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -352,10 +352,11 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
n2->narg.backquote = NULL;
n2->narg.next = NULL;
n1->nfor.args = n2;
- /* A newline or semicolon is optional here. Anything
- else gets pushed back so we can read it again. */
- if (lasttoken != TNL && lasttoken != TSEMI)
- tokpushback++;
+ /* Many shells accept an optional semicolon here, but
+ POSIX says we should not, so we don't. An optional
+ newline is OK here, but that is handled by the
+ checkkwd = 2 assignment below. */
+ tokpushback++;
}
checkkwd = 2;
if ((t = readtoken()) == TDO)
@@ -429,7 +430,10 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
checkkwd = 1;
break;
/* Handle an empty command like other simple commands. */
+ case TSEMI:
case TNL:
+ /* Handle EOF like other simple commands, too. */
+ case TEOF:
case TWORD:
tokpushback++;
return simplecmd(rpp, redir);
diff --git a/bin/sh/sh.1 b/bin/sh/sh.1
index 415aa0e42fc3..e5498959ecc9 100644
--- a/bin/sh/sh.1
+++ b/bin/sh/sh.1
@@ -372,7 +372,7 @@ will be as if a new shell had been invoked to handle the shell procedure,
except that the location of commands located in the parent shell will
be remembered by the child. If the program is a file beginning with
``#!'', the remainder of the first line specifies an interpreter for
-the program. The shell (or the operating system, under Berkeley UNIX)
+the program. The operating system
will run the interpreter in this case. The arguments to the interpreter
will consist of any arguments given on the first line of the program,
followed by the name of the program, followed by the arguments passed
@@ -486,7 +486,7 @@ fields separated by a separator character, is used.
When performing splitting, the shell scans the replacement text looking
for a character (when IFS does not begin with a space) or a sequence of
characters (when IFS does begin with a space), deletes the character or
-sequence of characters, and spits the word into two strings at that
+sequence of characters, and splits the word into two strings at that
point. When IFS begins with a space, the shell deletes either of the
strings if they are null. As a special case, if the word containing
the replacement text is the null string, the word is deleted.