summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
committersjg <sjg@FreeBSD.org>2015-05-27 01:19:58 +0000
commit65145fa4c81da358fcbc3b650156dab705dfa34e (patch)
tree55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /usr.bin/sed
parent60ff4eb0dff94a04d75d0d52a3957aaaf5f8c693 (diff)
parente6b664c390af88d4a87208bc042ce503da664c3b (diff)
downloadFreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.zip
FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.tar.gz
Merge sync of head
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/compile.c5
-rw-r--r--usr.bin/sed/main.c8
-rw-r--r--usr.bin/sed/process.c10
-rw-r--r--usr.bin/sed/tests/multi_test.sh4
-rw-r--r--usr.bin/sed/tests/regress.multitest.out/2.232
5 files changed, 19 insertions, 10 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index e146668..c7fbe21 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -558,7 +558,7 @@ compile_flags(char *p, struct s_subst *s)
{
int gn; /* True if we have seen g or n */
unsigned long nval;
- char wfile[_POSIX2_LINE_MAX + 1], *q;
+ char wfile[_POSIX2_LINE_MAX + 1], *q, *eq;
s->n = 1; /* Default */
s->p = 0;
@@ -611,9 +611,12 @@ compile_flags(char *p, struct s_subst *s)
#endif
EATSPACE();
q = wfile;
+ eq = wfile + sizeof(wfile) - 1;
while (*p) {
if (*p == '\n')
break;
+ if (q >= eq)
+ err(1, "wfile too long");
*q++ = *p++;
}
*q = '\0';
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 76e186f..36a3299 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -400,15 +400,17 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
sizeof(oldfname));
len = strlcat(oldfname, inplace,
sizeof(oldfname));
- if (len > sizeof(oldfname))
+ if (len > (ssize_t)sizeof(oldfname))
errx(1, "%s: name too long", fname);
}
len = snprintf(tmpfname, sizeof(tmpfname),
"%s/.!%ld!%s", dirname(fname), (long)getpid(),
basename(fname));
- if (len >= sizeof(tmpfname))
+ if (len >= (ssize_t)sizeof(tmpfname))
errx(1, "%s: name too long", fname);
unlink(tmpfname);
+ if (outfile != NULL && outfile != stdout)
+ fclose(outfile);
if ((outfile = fopen(tmpfname, "w")) == NULL)
err(1, "%s", fname);
fchown(fileno(outfile), sb.st_uid, sb.st_gid);
@@ -488,7 +490,7 @@ add_file(char *s)
}
static int
-next_files_have_lines()
+next_files_have_lines(void)
{
struct s_flist *file;
FILE *file_fd;
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index 9cd2c2e..daabfd8 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -67,11 +67,11 @@ static SPACE HS, PS, SS, YS;
#define hs HS.space
#define hsl HS.len
-static __inline int applies(struct s_command *);
+static inline int applies(struct s_command *);
static void do_tr(struct s_tr *);
static void flush_appends(void);
static void lputs(char *, size_t);
-static __inline int regexec_e(regex_t *, const char *, int, int, size_t);
+static int regexec_e(regex_t *, const char *, int, int, size_t);
static void regsub(SPACE *, char *, char *);
static int substitute(struct s_command *);
@@ -288,7 +288,7 @@ new: if (!nflag && !pd)
* Return TRUE if the command applies to the current line. Sets the start
* line for process ranges. Interprets the non-select (``!'') flag.
*/
-static __inline int
+static inline int
applies(struct s_command *cp)
{
int r;
@@ -324,7 +324,7 @@ applies(struct s_command *cp)
} else
r = 1;
}
- } else if (MATCH(cp->a1)) {
+ } else if (cp->a1 && MATCH(cp->a1)) {
/*
* If the second address is a number less than or
* equal to the line number first selected, only
@@ -656,7 +656,7 @@ lputs(char *s, size_t len)
errx(1, "%s: %s", outfname, strerror(errno ? errno : EIO));
}
-static __inline int
+static int
regexec_e(regex_t *preg, const char *string, int eflags, int nomatch,
size_t slen)
{
diff --git a/usr.bin/sed/tests/multi_test.sh b/usr.bin/sed/tests/multi_test.sh
index d821832..66207a6 100644
--- a/usr.bin/sed/tests/multi_test.sh
+++ b/usr.bin/sed/tests/multi_test.sh
@@ -51,7 +51,7 @@ main()
awk 'END { for (i = 1; i < 15; i++) print "l1_" i}' </dev/null >lines1
awk 'END { for (i = 1; i < 10; i++) print "l2_" i}' </dev/null >lines2
- echo "1..129"
+ echo "1..130"
exec 4>&1 5>&2
tests
@@ -181,6 +181,8 @@ hello' /dev/null
mark '2.20' ; $SED -n '/l1_7/,3p' lines1 lines2
mark '2.21' ; $SED -n '13,+4p' lines1 lines2
mark '2.22' ; $SED -n '/l1_6/,+2p' lines1 lines2
+ # For PR bin/192108
+ mark '2.23'; $SED -n '12,+1p' lines1
}
test_group()
diff --git a/usr.bin/sed/tests/regress.multitest.out/2.23 b/usr.bin/sed/tests/regress.multitest.out/2.23
new file mode 100644
index 0000000..543c057
--- /dev/null
+++ b/usr.bin/sed/tests/regress.multitest.out/2.23
@@ -0,0 +1,2 @@
+l1_12
+l1_13
OpenPOWER on IntegriCloud