Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/patch Keep things portable (requested by joerg) by n...
details: https://anonhg.NetBSD.org/src/rev/16c929fd79dc
branches: trunk
changeset: 319998:16c929fd79dc
user: christos <christos%NetBSD.org@localhost>
date: Mon Jun 18 18:33:31 2018 +0000
description:
Keep things portable (requested by joerg) by not depending on reallocarr
and instead doing the overflow check ourselves.
diffstat:
usr.bin/patch/inp.c | 10 ++++++----
usr.bin/patch/pch.c | 10 +++++-----
usr.bin/patch/util.c | 14 ++++++++++++--
usr.bin/patch/util.h | 3 ++-
4 files changed, 25 insertions(+), 12 deletions(-)
diffs (139 lines):
diff -r c727a9295870 -r 16c929fd79dc usr.bin/patch/inp.c
--- a/usr.bin/patch/inp.c Mon Jun 18 17:07:07 2018 +0000
+++ b/usr.bin/patch/inp.c Mon Jun 18 18:33:31 2018 +0000
@@ -1,7 +1,7 @@
/*
* $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $
* $DragonFly: src/usr.bin/patch/inp.c,v 1.6 2007/09/29 23:11:10 swildner Exp $
- * $NetBSD: inp.c,v 1.25 2018/06/16 00:40:14 christos Exp $
+ * $NetBSD: inp.c,v 1.26 2018/06/18 18:33:31 christos Exp $
*/
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: inp.c,v 1.25 2018/06/16 00:40:14 christos Exp $");
+__RCSID("$NetBSD: inp.c,v 1.26 2018/06/18 18:33:31 christos Exp $");
#include <sys/types.h>
#include <sys/file.h>
@@ -118,11 +118,12 @@
static bool
reallocate_lines(size_t *lines_allocated)
{
+ char **p;
size_t new_size;
new_size = *lines_allocated * 3 / 2;
- int res = reallocarr(&i_ptr, new_size + 2, sizeof(char *));
- if (res != 0) { /* shucks, it was a near thing */
+ p = pch_realloc(i_ptr, new_size + 2, sizeof(char *));
+ if (p == NULL) { /* shucks, it was a near thing */
munmap(i_womp, i_size);
i_womp = NULL;
free(i_ptr);
@@ -131,6 +132,7 @@
return false;
}
*lines_allocated = new_size;
+ i_ptr = p;
return true;
}
diff -r c727a9295870 -r 16c929fd79dc usr.bin/patch/pch.c
--- a/usr.bin/patch/pch.c Mon Jun 18 17:07:07 2018 +0000
+++ b/usr.bin/patch/pch.c Mon Jun 18 18:33:31 2018 +0000
@@ -1,7 +1,7 @@
/*
* $OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $
* $DragonFly: src/usr.bin/patch/pch.c,v 1.6 2008/08/10 23:35:40 joerg Exp $
- * $NetBSD: pch.c,v 1.29 2018/04/05 18:50:10 christos Exp $
+ * $NetBSD: pch.c,v 1.30 2018/06/18 18:33:31 christos Exp $
*/
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pch.c,v 1.29 2018/04/05 18:50:10 christos Exp $");
+__RCSID("$NetBSD: pch.c,v 1.30 2018/06/18 18:33:31 christos Exp $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -156,15 +156,15 @@
if (p_line == NULL || p_len == NULL || p_char == NULL)
fatal("Internal memory allocation error\n");
- new_p_line = realloc(p_line, new_hunkmax * sizeof(char *));
+ new_p_line = pch_realloc(p_line, new_hunkmax, sizeof(char *));
if (new_p_line == NULL)
free(p_line);
- new_p_len = realloc(p_len, new_hunkmax * sizeof(short));
+ new_p_len = pch_realloc(p_len, new_hunkmax, sizeof(short));
if (new_p_len == NULL)
free(p_len);
- new_p_char = realloc(p_char, new_hunkmax * sizeof(char));
+ new_p_char = pch_realloc(p_char, new_hunkmax, sizeof(char));
if (new_p_char == NULL)
free(p_char);
diff -r c727a9295870 -r 16c929fd79dc usr.bin/patch/util.c
--- a/usr.bin/patch/util.c Mon Jun 18 17:07:07 2018 +0000
+++ b/usr.bin/patch/util.c Mon Jun 18 18:33:31 2018 +0000
@@ -1,7 +1,7 @@
/*
* $OpenBSD: util.c,v 1.32 2006/03/11 19:41:30 otto Exp $
* $DragonFly: src/usr.bin/patch/util.c,v 1.9 2007/09/29 23:11:10 swildner Exp $
- * $NetBSD: util.c,v 1.27 2015/11/07 18:11:21 joerg Exp $
+ * $NetBSD: util.c,v 1.28 2018/06/18 18:33:31 christos Exp $
*/
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: util.c,v 1.27 2015/11/07 18:11:21 joerg Exp $");
+__RCSID("$NetBSD: util.c,v 1.28 2018/06/18 18:33:31 christos Exp $");
#include <sys/param.h>
#include <sys/stat.h>
@@ -435,3 +435,13 @@
unlink(TMPPATNAME);
exit(status);
}
+
+void *
+pch_realloc(void *ptr, size_t number, size_t size)
+{
+ if (number > SIZE_MAX / size) {
+ errno = EOVERFLOW;
+ return NULL;
+ }
+ return realloc(ptr, number * size);
+}
diff -r c727a9295870 -r 16c929fd79dc usr.bin/patch/util.h
--- a/usr.bin/patch/util.h Mon Jun 18 17:07:07 2018 +0000
+++ b/usr.bin/patch/util.h Mon Jun 18 18:33:31 2018 +0000
@@ -1,7 +1,7 @@
/*
* $OpenBSD: util.h,v 1.15 2005/06/20 07:14:06 otto Exp $
* $DragonFly: src/usr.bin/patch/util.h,v 1.2 2007/09/29 23:11:10 swildner Exp $
- * $NetBSD: util.h,v 1.12 2011/09/06 18:25:14 joerg Exp $
+ * $NetBSD: util.h,v 1.13 2018/06/18 18:33:31 christos Exp $
*/
/*
@@ -45,6 +45,7 @@
void makedirs(const char *, bool);
void version(void) __dead;
void my_exit(int) __dead;
+void *pch_realloc(void *, size_t, size_t);
/* in mkpath.c */
extern int mkpath(char *);
Home |
Main Index |
Thread Index |
Old Index