summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2011-01-01 12:11:37 +0000
committerkettenis <kettenis@openbsd.org>2011-01-01 12:11:37 +0000
commitad9c7e049865a7aaa240c828bb249b0b0a0a527f (patch)
tree6932f46575c72ad6aaff41ad12bf92cad84250fd
parentPut "else if" split between two lines together, then move whitespace. (diff)
downloadwireguard-openbsd-ad9c7e049865a7aaa240c828bb249b0b0a0a527f.tar.xz
wireguard-openbsd-ad9c7e049865a7aaa240c828bb249b0b0a0a527f.zip
Stop enterfield() from writing beyond the end of the buffer.
Fixes PR 6294. ok tedu@
-rw-r--r--usr.bin/sort/fields.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/usr.bin/sort/fields.c b/usr.bin/sort/fields.c
index 4217904bcde..667eb2f40c3 100644
--- a/usr.bin/sort/fields.c
+++ b/usr.bin/sort/fields.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fields.c,v 1.14 2009/10/27 23:59:43 deraadt Exp $ */
+/* $OpenBSD: fields.c,v 1.15 2011/01/01 12:11:37 kettenis Exp $ */
/*-
* Copyright (c) 1993
@@ -164,14 +164,14 @@ enterfield(u_char *tablepos, u_char *endkey, struct field *cur_fld, int gflags)
for (; start < end; start++)
if (mask[*start]) {
if (*start <= 1) {
- if (tablepos+2 >= endkey)
+ if (tablepos + 2 >= endkey)
return (NULL);
*tablepos++ = lweight[1];
*tablepos++ = lweight[*start ? 2 : 1];
} else {
- *tablepos++ = lweight[*start];
- if (tablepos == endkey)
+ if (tablepos + 1 >= endkey)
return (NULL);
+ *tablepos++ = lweight[*start];
}
}
*tablepos++ = lweight[0];