Infrastructure change to come in a separate commit.
https://mail-index.netbsd.org/tech-crypto/2017/05/06/msg000719.html
Patch for CVE-2018-049.
Prevent shell execution with r command.
Check bounds before dereferencing in encryption routines.
Document -S to disable ! commands.
Sync with NetBSD-8
closes #268
Change-Id: I1c2849e0097b0cc9f89beef5ee24ccd9d73b4ee2
-# $NetBSD: Makefile,v 1.36 2009/07/26 01:58:20 dholland Exp $
+# $NetBSD: Makefile,v 1.37 2017/05/21 15:28:36 riastradh Exp $
.include <bsd.own.mk>
PROG= ed
CPPFLAGS+=-DBACKWARDS
.include <bsd.own.mk>
PROG= ed
CPPFLAGS+=-DBACKWARDS
-
-.if (${MKCRYPTO} != "no")
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
SRCS= buf.c cbc.c glbl.c io.c main.c re.c sub.c undo.c
-/* $NetBSD: cbc.c,v 1.23 2014/03/23 05:06:42 dholland Exp $ */
+/* $NetBSD: cbc.c,v 1.24 2016/02/01 17:34:00 christos Exp $ */
/* cbc.c: This file contains the encryption routines for the ed line editor */
/*-
/* cbc.c: This file contains the encryption routines for the ed line editor */
/*-
#if 0
static char *rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
#else
#if 0
static char *rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
#else
-__RCSID("$NetBSD: cbc.c,v 1.23 2014/03/23 05:06:42 dholland Exp $");
+__RCSID("$NetBSD: cbc.c,v 1.24 2016/02/01 17:34:00 christos Exp $");
#endif
#endif /* not lint */
#endif
#endif /* not lint */
/*
* now translate it, bombing on any illegal hex digit
*/
/*
* now translate it, bombing on any illegal hex digit
*/
- for (i = 0; inbuf[i] && i < 16; i++)
+ for (i = 0; i < 16 && inbuf[i]; i++)
if ((nbuf[i] = hex_to_binary((int) inbuf[i], 16)) == -1)
des_error("bad hex digit in key");
while (i < 16)
if ((nbuf[i] = hex_to_binary((int) inbuf[i], 16)) == -1)
des_error("bad hex digit in key");
while (i < 16)
/*
* now translate it, bombing on any illegal binary digit
*/
/*
* now translate it, bombing on any illegal binary digit
*/
- for (i = 0; inbuf[i] && i < 16; i++)
+ for (i = 0; i < 16 && inbuf[i]; i++)
if ((nbuf[i] = hex_to_binary((int) inbuf[i], 2)) == -1)
des_error("bad binary digit in key");
while (i < 64)
if ((nbuf[i] = hex_to_binary((int) inbuf[i], 2)) == -1)
des_error("bad binary digit in key");
while (i < 64)
-.\" $NetBSD: ed.1,v 1.30 2010/05/14 02:09:58 joerg Exp $
+.\" $NetBSD: ed.1,v 1.30.40.1 2018/04/08 06:04:08 snj Exp $
.\" $OpenBSD: ed.1,v 1.42 2003/07/27 13:25:43 jmc Exp $
.\"
.\" Copyright (c) 1993 Andrew Moore, Talke Studio.
.\" $OpenBSD: ed.1,v 1.42 2003/07/27 13:25:43 jmc Exp $
.\"
.\" Copyright (c) 1993 Andrew Moore, Talke Studio.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Op Fl p Ar string
.Op Ar file
.Sh DESCRIPTION
.Op Fl p Ar string
.Op Ar file
.Sh DESCRIPTION
.It Fl E
Enables the use of extended regular expressions instead of the basic
regular expressions that are normally used.
.It Fl E
Enables the use of extended regular expressions instead of the basic
regular expressions that are normally used.
+.It Fl S
+Disables using of the
+.Dq !
+command (execuring a subshell).
+Intended to be used by batch jobs like
+.Xr patch 1 .
.It Fl p Ar string
Specifies a command prompt.
This may be toggled on and off with the
.It Fl p Ar string
Specifies a command prompt.
This may be toggled on and off with the
.Xr sed 1 ,
.Xr sh 1 ,
.Xr vi 1 ,
.Xr sed 1 ,
.Xr sh 1 ,
.Xr vi 1 ,
.Xr regex 3
.Pp
USD:09-10
.Xr regex 3
.Pp
USD:09-10
-/* $NetBSD: main.c,v 1.27 2014/03/31 12:55:46 christos Exp $ */
+/* $NetBSD: main.c,v 1.28.8.2 2018/06/22 10:08:22 martin Exp $ */
/* main.c: This file contains the main control and user-interface routines
for the ed line editor. */
/* main.c: This file contains the main control and user-interface routines
for the ed line editor. */
#if 0
static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
#else
#if 0
static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
#else
-__RCSID("$NetBSD: main.c,v 1.27 2014/03/31 12:55:46 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.28.8.2 2018/06/22 10:08:22 martin Exp $");
#endif
#endif /* not lint */
#endif
#endif /* not lint */
int red = 0; /* if set, restrict shell/directory access */
int ere = 0; /* if set, use extended regexes */
int scripted = 0; /* if set, suppress diagnostics */
int red = 0; /* if set, restrict shell/directory access */
int ere = 0; /* if set, use extended regexes */
int scripted = 0; /* if set, suppress diagnostics */
+int secure = 0; /* is set, ! is not allowed */
int sigflags = 0; /* if set, signals received while mutex set */
int sigactive = 0; /* if set, signal handlers are enabled */
int sigflags = 0; /* if set, signals received while mutex set */
int sigactive = 0; /* if set, signal handlers are enabled */
const char *dps = "*"; /* default command-line prompt */
const char *dps = "*"; /* default command-line prompt */
-static const char usage[] = "Usage: %s [-] [-sxE] [-p string] [name]\n";
+static const char usage[] = "Usage: %s [-] [-ESsx] [-p string] [name]\n";
/* ed: line editor */
int
/* ed: line editor */
int
red = (n = strlen(argv[0])) > 2 && argv[0][n - 3] == 'r';
top:
red = (n = strlen(argv[0])) > 2 && argv[0][n - 3] == 'r';
top:
- while ((c = getopt(argc, argv, "p:sxE")) != -1)
+ while ((c = getopt(argc, argv, "p:sxES")) != -1)
switch(c) {
case 'p': /* set prompt */
prompt = optarg;
switch(c) {
case 'p': /* set prompt */
prompt = optarg;
case 'E':
ere = REG_EXTENDED;
break;
case 'E':
ere = REG_EXTENDED;
break;
+ case 'S': /* ! is not allowed */
+ secure = 1;
+ break;
default:
fprintf(stderr, usage, getprogname());
exit(1);
default:
fprintf(stderr, usage, getprogname());
exit(1);
}
isglobal = 0;
if ((status = extract_addr_range()) >= 0 &&
}
isglobal = 0;
if ((status = extract_addr_range()) >= 0 &&
- (status = exec_command()) >= 0)
- if (!status || (status &&
- (status = display_lines(current_addr, current_addr,
- status)) >= 0))
+ (status = exec_command()) >= 0) {
+ if (status == 0)
+ continue;
+ status = display_lines(current_addr, current_addr,
+ status);
+ if (status >= 0)
switch (status) {
case EOF:
quit(0);
switch (status) {
case EOF:
quit(0);
if (addr_cnt > 0) {
seterrmsg("unexpected address");
return ERR;
if (addr_cnt > 0) {
seterrmsg("unexpected address");
return ERR;
- } else if ((sflags = get_shell_command()) < 0)
+ }
+ if ((sflags = get_shell_command()) < 0)
return ERR;
GET_COMMAND_SUFFIX();
if (sflags) printf("%s\n", shcmd + 1);
return ERR;
GET_COMMAND_SUFFIX();
if (sflags) printf("%s\n", shcmd + 1);
seterrmsg("shell access restricted");
return ERR;
} else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)
seterrmsg("shell access restricted");
return ERR;
} else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)