summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2022-01-12 15:13:37 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2022-01-12 15:13:37 +0000
commit873587f2fedb832add8160044bcfe5d011a0746d (patch)
treecdb1f4cf594cd26481ac9cb9a546e43184bd6040 /usr.bin
parent2d1cc5d3c3367d92a72842cf97486c47329af799 (diff)
Make lputs use psl instead of expecting it to be null-terminated.
This allows us to enable the commandl1 and commandl2 regress tests. Original analysis from seL4 <at> disroot <dot> org OK millert@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sed/process.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index cc31fcb57a3..932e333fde4 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process.c,v 1.34 2018/11/14 10:59:33 martijn Exp $ */
+/* $OpenBSD: process.c,v 1.35 2022/01/12 15:13:36 martijn Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -60,7 +60,7 @@ static SPACE HS, PS, SS;
static inline int applies(struct s_command *);
static void flush_appends(void);
-static void lputs(char *);
+static void lputs(char *, size_t);
static inline int regexec_e(regex_t *, const char *, int, int, size_t,
size_t);
static void regsub(SPACE *, char *, char *);
@@ -158,7 +158,7 @@ redirect:
(void)fprintf(outfile, "%s", cp->t);
break;
case 'l':
- lputs(ps);
+ lputs(ps, psl);
break;
case 'n':
if (!nflag && !pd)
@@ -478,14 +478,14 @@ flush_appends(void)
}
static void
-lputs(char *s)
+lputs(char *s, size_t len)
{
int count;
extern int termwidth;
const char *escapes;
char *p;
- for (count = 0; *s; ++s) {
+ for (count = 0; len > 0; len--, s++) {
if (count >= termwidth) {
(void)fprintf(outfile, "\\\n");
count = 0;
@@ -501,7 +501,7 @@ lputs(char *s)
} else {
escapes = "\\\a\b\f\r\t\v";
(void)fputc('\\', outfile);
- if ((p = strchr(escapes, *s))) {
+ if ((p = strchr(escapes, *s)) && *s != '\0') {
(void)fputc("\\abfrtv"[p - escapes], outfile);
count += 2;
} else {