Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config config(1): Avoid buffer overrun (modular build)



details:   https://anonhg.NetBSD.org/src/rev/be5795ac43da
branches:  trunk
changeset: 803871:be5795ac43da
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Sat Nov 15 12:18:55 2014 +0000

description:
config(1): Avoid buffer overrun (modular build)

diffstat:

 usr.bin/config/mkmakefile.c |  13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r 5321cc5db027 -r be5795ac43da usr.bin/config/mkmakefile.c
--- a/usr.bin/config/mkmakefile.c       Sat Nov 15 08:21:38 2014 +0000
+++ b/usr.bin/config/mkmakefile.c       Sat Nov 15 12:18:55 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkmakefile.c,v 1.27 2014/11/15 08:21:38 uebayasi Exp $ */
+/*     $NetBSD: mkmakefile.c,v 1.28 2014/11/15 12:18:55 uebayasi Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: mkmakefile.c,v 1.27 2014/11/15 08:21:38 uebayasi Exp $");
+__RCSID("$NetBSD: mkmakefile.c,v 1.28 2014/11/15 12:18:55 uebayasi Exp $");
 
 #include <sys/param.h>
 #include <ctype.h>
@@ -374,10 +374,10 @@
 {
        int i;
 
-       attrbuf = ecalloc((size_t)nattrs, sizeof(attrbuf));
+       attrbuf = emalloc((size_t)nattrs * sizeof(attrbuf));
 
        ht_enumerate(attrtab, emitallkobjsweighcb, NULL);
-       ht_enumerate(attrtab, emitallkobjscb, fp);
+       ht_enumerate(attrtab, emitallkobjscb, NULL);
        qsort(attrbuf, (size_t)attridx, sizeof(struct attr *), attrcmp);
 
        fputs("OBJS=", fp);
@@ -398,6 +398,11 @@
        if (TAILQ_EMPTY(&a->a_files))
                return 0;
        attrbuf[attridx++] = a;
+       /* XXX nattrs tracking is not exact yet */
+       if (attridx == nattrs) {
+               nattrs *= 2;
+               attrbuf = erealloc(attrbuf, (size_t)nattrs * sizeof(attrbuf));
+       }
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index