[hackers] [sbase] uniq: always store previous line length || Eivind Uggedal
commit d4f7ecd334cb666d2b58d80b40fe95d9b89f6716
Author: Eivind Uggedal <eivind_AT_uggedal.com>
AuthorDate: Fri Mar 11 15:06:18 2016 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Fri Mar 11 15:38:36 2016 +0000
uniq: always store previous line length
A bug was introduced in the NUL support refactor leading to
the length of the previous line only being saved if the
previous line was shorter than the current line. If triggered
this lead to copying too much data into the previous line buffer.
Behavior before:
printf '1234\na\n' | ./uniq
1234
a
4
Behavior after:
printf '1234\na\n' | ./uniq
1234
a
diff --git a/uniq.c b/uniq.c
index 4f35d05..f1ad6a7 100644
--- a/uniq.c
+++ b/uniq.c
_AT_@ -62,9 +62,9 @@ uniqline(FILE *ofp, struct line *l)
if (l) {
if (!prevl.data || l->len >= prevl.len) {
- prevl.len = l->len;
- prevl.data = erealloc(prevl.data, prevl.len);
+ prevl.data = erealloc(prevl.data, l->len);
}
+ prevl.len = l->len;
memcpy(prevl.data, l->data, prevl.len);
prevoff = loff;
}
Received on Fri Mar 11 2016 - 16:38:45 CET
This archive was generated by hypermail 2.3.0
: Fri Mar 11 2016 - 16:48:13 CET