Author: pfg
Date: Mon Dec 12 03:46:40 2016
New Revision: 309873
URL: https://svnweb.freebsd.org/changeset/base/309873

Log:
  ed(1): Prevent possible overflows during allocation.
  
  Make sure the parameters used for malloc(3) can hold size_t sizes.
  This should help ed(1) handle bigger data in the future.
  
  MFC after:    2 weeks

Modified:
  head/bin/ed/ed.h
  head/bin/ed/glbl.c
  head/bin/ed/main.c

Modified: head/bin/ed/ed.h
==============================================================================
--- head/bin/ed/ed.h    Mon Dec 12 02:24:54 2016        (r309872)
+++ head/bin/ed/ed.h    Mon Dec 12 03:46:40 2016        (r309873)
@@ -115,7 +115,7 @@ if (--mutex == 0) { \
 /* REALLOC: assure at least a minimum size for buffer b */
 #define REALLOC(b,n,i,err) \
 if ((i) > (n)) { \
-       int ti = (n); \
+       size_t ti = (n); \
        char *ts; \
        SPL1(); \
        if ((b) != NULL) { \
@@ -141,7 +141,7 @@ if ((i) > (n)) { \
 /* REALLOC: assure at least a minimum size for buffer b */
 #define REALLOC(b,n,i,err) \
 if ((i) > (n)) { \
-       int ti = (n); \
+       size_t ti = (n); \
        char *ts; \
        SPL1(); \
        if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \

Modified: head/bin/ed/glbl.c
==============================================================================
--- head/bin/ed/glbl.c  Mon Dec 12 02:24:54 2016        (r309872)
+++ head/bin/ed/glbl.c  Mon Dec 12 03:46:40 2016        (r309873)
@@ -146,7 +146,7 @@ int
 set_active_node(line_t *lp)
 {
        if (active_last + 1 > active_size) {
-               int ti = active_size;
+               size_t ti = active_size;
                line_t **ts;
                SPL1();
 #if defined(sun) || defined(NO_REALLOC_NULL)

Modified: head/bin/ed/main.c
==============================================================================
--- head/bin/ed/main.c  Mon Dec 12 02:24:54 2016        (r309872)
+++ head/bin/ed/main.c  Mon Dec 12 03:46:40 2016        (r309873)
@@ -1356,7 +1356,7 @@ handle_hup(int signo)
        char *hup = NULL;               /* hup filename */
        char *s;
        char ed_hup[] = "ed.hup";
-       int n;
+       size_t n;
 
        if (!sigactive)
                quit(1);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to