Module Name: src
Committed By: riz
Date: Tue Jun 29 18:01:11 UTC 2010
Modified Files:
src/usr.bin/sort [netbsd-5]: fsort.c msort.c sort.c sort.h
Log Message:
Pull up following revision(s) (requested by dholland in ticket #1420):
usr.bin/sort/sort.h: revision 1.31
usr.bin/sort/sort.c: revision 1.58
usr.bin/sort/fsort.c: revision 1.47
usr.bin/sort/msort.c: revision 1.30
Don't touch past the end of allocated region. It results segmentation
violation.
To generate a diff of this commit:
cvs rdiff -u -r1.32.6.1 -r1.32.6.2 src/usr.bin/sort/fsort.c
cvs rdiff -u -r1.18.6.1 -r1.18.6.2 src/usr.bin/sort/msort.c
cvs rdiff -u -r1.46.4.1 -r1.46.4.2 src/usr.bin/sort/sort.c
cvs rdiff -u -r1.19.6.1 -r1.19.6.2 src/usr.bin/sort/sort.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/sort/fsort.c
diff -u src/usr.bin/sort/fsort.c:1.32.6.1 src/usr.bin/sort/fsort.c:1.32.6.2
--- src/usr.bin/sort/fsort.c:1.32.6.1 Wed Oct 14 20:41:53 2009
+++ src/usr.bin/sort/fsort.c Tue Jun 29 18:01:11 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: fsort.c,v 1.32.6.1 2009/10/14 20:41:53 sborrill Exp $ */
+/* $NetBSD: fsort.c,v 1.32.6.2 2010/06/29 18:01:11 riz Exp $ */
/*-
* Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
#include "fsort.h"
#ifndef lint
-__RCSID("$NetBSD: fsort.c,v 1.32.6.1 2009/10/14 20:41:53 sborrill Exp $");
+__RCSID("$NetBSD: fsort.c,v 1.32.6.2 2010/06/29 18:01:11 riz Exp $");
__SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
@@ -98,7 +98,7 @@
int file_no;
int max_recs = DEBUG('m') ? 16 : MAXNUM;
- buffer = malloc(bufsize);
+ buffer = allocrec(NULL, bufsize);
bufend = (u_char *)buffer + bufsize;
/* Allocate double length keymap for radix_sort */
keylist = malloc(2 * max_recs * sizeof(*keylist));
@@ -157,7 +157,7 @@
/* c == BUFFEND, and we can process more data */
/* Allocate a larger buffer for this lot of data */
bufsize *= 2;
- nbuffer = realloc(buffer, bufsize);
+ nbuffer = allocrec(buffer, bufsize);
if (!nbuffer) {
err(2, "failed to realloc buffer to %zu bytes",
bufsize);
Index: src/usr.bin/sort/msort.c
diff -u src/usr.bin/sort/msort.c:1.18.6.1 src/usr.bin/sort/msort.c:1.18.6.2
--- src/usr.bin/sort/msort.c:1.18.6.1 Wed Oct 14 20:41:53 2009
+++ src/usr.bin/sort/msort.c Tue Jun 29 18:01:11 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: msort.c,v 1.18.6.1 2009/10/14 20:41:53 sborrill Exp $ */
+/* $NetBSD: msort.c,v 1.18.6.2 2010/06/29 18:01:11 riz Exp $ */
/*-
* Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
#include "fsort.h"
#ifndef lint
-__RCSID("$NetBSD: msort.c,v 1.18.6.1 2009/10/14 20:41:53 sborrill Exp $");
+__RCSID("$NetBSD: msort.c,v 1.18.6.2 2010/06/29 18:01:11 riz Exp $");
__SCCSID("@(#)msort.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
@@ -209,7 +209,7 @@
for (nfiles = i = 0; i < fstack_count; i++) {
cfile = &fstack[i];
if (cfile->rec == NULL) {
- cfile->rec = emalloc(DEFLLEN);
+ cfile->rec = allocrec(NULL, DEFLLEN);
cfile->end = (u_char *)cfile->rec + DEFLLEN;
}
rewind(cfile->fp);
@@ -222,7 +222,7 @@
if (c == BUFFEND) {
/* Double buffer size */
sz = (cfile->end - (u_char *)cfile->rec) * 2;
- cfile->rec = erealloc(cfile->rec, sz);
+ cfile->rec = allocrec(cfile->rec, sz);
cfile->end = (u_char *)cfile->rec + sz;
continue;
}
@@ -248,7 +248,7 @@
* output file - maintaining one record from each file in the sorted
* list.
*/
- new_rec = emalloc(DEFLLEN);
+ new_rec = allocrec(NULL, DEFLLEN);
new_end = (u_char *)new_rec + DEFLLEN;
for (;;) {
cfile = flist[0];
@@ -266,7 +266,7 @@
if (c == BUFFEND) {
/* Buffer not large enough - double in size */
sz = (new_end - (u_char *)new_rec) * 2;
- new_rec = erealloc(new_rec, sz);
+ new_rec = allocrec(new_rec, sz);
new_end = (u_char *)new_rec +sz;
continue;
}
Index: src/usr.bin/sort/sort.c
diff -u src/usr.bin/sort/sort.c:1.46.4.1 src/usr.bin/sort/sort.c:1.46.4.2
--- src/usr.bin/sort/sort.c:1.46.4.1 Wed Oct 14 20:41:53 2009
+++ src/usr.bin/sort/sort.c Tue Jun 29 18:01:11 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sort.c,v 1.46.4.1 2009/10/14 20:41:53 sborrill Exp $ */
+/* $NetBSD: sort.c,v 1.46.4.2 2010/06/29 18:01:11 riz Exp $ */
/*-
* Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
#endif /* not lint */
#ifndef lint
-__RCSID("$NetBSD: sort.c,v 1.46.4.1 2009/10/14 20:41:53 sborrill Exp $");
+__RCSID("$NetBSD: sort.c,v 1.46.4.2 2010/06/29 18:01:11 riz Exp $");
__SCCSID("@(#)sort.c 8.1 (Berkeley) 6/6/93");
#endif /* not lint */
@@ -405,3 +405,10 @@
" [-t char] [file ...]\n");
exit(2);
}
+
+RECHEADER *
+allocrec(RECHEADER *rec, size_t size)
+{
+
+ return (erealloc(rec, size + sizeof(long) - 1));
+}
Index: src/usr.bin/sort/sort.h
diff -u src/usr.bin/sort/sort.h:1.19.6.1 src/usr.bin/sort/sort.h:1.19.6.2
--- src/usr.bin/sort/sort.h:1.19.6.1 Wed Oct 14 20:41:53 2009
+++ src/usr.bin/sort/sort.h Tue Jun 29 18:01:11 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: sort.h,v 1.19.6.1 2009/10/14 20:41:53 sborrill Exp $ */
+/* $NetBSD: sort.h,v 1.19.6.2 2010/06/29 18:01:11 riz Exp $ */
/*-
* Copyright (c) 2000-2003 The NetBSD Foundation, Inc.
@@ -174,6 +174,7 @@
#define DEBUG(ch) (debug_flags & (1 << ((ch) & 31)))
extern unsigned int debug_flags;
+RECHEADER *allocrec(RECHEADER *, size_t);
void append(RECHEADER **, int, FILE *, void (*)(const RECHEADER *, FILE *));
void concat(FILE *, FILE *);
length_t enterkey(RECHEADER *, const u_char *, u_char *, size_t, struct field *);