Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/ypserv fix up lossage WRT free()ing invalid pointers.



details:   https://anonhg.NetBSD.org/src/rev/1635cd9e7bfe
branches:  trunk
changeset: 474895:1635cd9e7bfe
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Jul 25 09:01:04 1999 +0000

description:
fix up lossage WRT free()ing invalid pointers.
noted in [bin/8064]

diffstat:

 usr.sbin/ypserv/mknetid/mknetid.c         |  32 +++++++++++++++++-------------
 usr.sbin/ypserv/revnetgroup/revnetgroup.c |  11 +++++----
 usr.sbin/ypserv/stdhosts/stdhosts.c       |  12 ++++++----
 3 files changed, 31 insertions(+), 24 deletions(-)

diffs (199 lines):

diff -r c3cbfbc996e3 -r 1635cd9e7bfe usr.sbin/ypserv/mknetid/mknetid.c
--- a/usr.sbin/ypserv/mknetid/mknetid.c Sun Jul 25 08:55:46 1999 +0000
+++ b/usr.sbin/ypserv/mknetid/mknetid.c Sun Jul 25 09:01:04 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mknetid.c,v 1.9 1998/06/11 14:50:46 kleink Exp $       */
+/*     $NetBSD: mknetid.c,v 1.10 1999/07/25 09:01:04 lukem Exp $       */
 
 /*
  * Copyright (c) 1996 Mats O Jansson <moj%stacken.kth.se@localhost>
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mknetid.c,v 1.9 1998/06/11 14:50:46 kleink Exp $");
+__RCSID("$NetBSD: mknetid.c,v 1.10 1999/07/25 09:01:04 lukem Exp $");
 #endif
 
 /*
@@ -232,21 +232,22 @@
        size_t   line_no;
        int      colon;
        size_t   len;
-       char    *p, *k, *u, *g;
+       char    *line, *p, *k, *u, *g;
 
        if ((pfile = fopen(fname, "r")) == NULL)
                err(1, "%s", fname);
 
        line_no = 0;
        for (;
-           (p = fparseln(pfile, &len, &line_no, NULL, FPARSELN_UNESCALL));
-           free(p)) {
+           (line = fparseln(pfile, &len, &line_no, NULL, FPARSELN_UNESCALL));
+           free(line)) {
                if (len == 0) {
                        warnx("%s line %lu: empty line", fname,
                            (unsigned long)line_no);
                        continue;
                }
 
+               p = line;
                for (k = p, colon = 0; *k != '\0'; k++)
                        if (*k == ':')
                                colon++;
@@ -308,21 +309,22 @@
        size_t   line_no;
        int      colon;
        size_t   len;
-       char    *p, *k, *u, *g;
+       char    *line, *p, *k, *u, *g;
 
        if ((gfile = fopen(fname, "r")) == NULL)
                err(1, "%s", fname);
 
        line_no = 0;
        for (;
-           (p = fparseln(gfile, &len, &line_no, NULL, FPARSELN_UNESCALL));
-           free(p)) {
+           (line = fparseln(gfile, &len, &line_no, NULL, FPARSELN_UNESCALL));
+           free(line)) {
                if (len == 0) {
                        warnx("%s line %lu: empty line", fname,
                            (unsigned long)line_no);
                        continue;
                }
 
+               p = line;
                for (k = p, colon = 0; *k != '\0'; k++)
                        if (*k == ':')
                                colon++;
@@ -402,17 +404,18 @@
 {
        FILE    *hfile;
        size_t   len;
-       char    *p, *k, *u;
+       char    *line, *p, *k, *u;
 
        if ((hfile = fopen(fname, "r")) == NULL)
                err(1, "%s", fname);
 
        for (;
-           (p = fparseln(hfile, &len, NULL, NULL, FPARSELN_UNESCALL));
-           free(p)) {
+           (line = fparseln(hfile, &len, NULL, NULL, FPARSELN_UNESCALL));
+           free(line)) {
                if (len == 0)
                        continue;
 
+               p = line;
                /* Find the key, replace trailing whitespace will <NUL> */
                for (k = p; *p && isspace(*p) == 0; p++)
                        ;
@@ -435,18 +438,19 @@
 {
        FILE    *mfile;
        size_t   len;
-       char    *p, *k, *u;
+       char    *line, *p, *k, *u;
 
        mfile = fopen(fname, "r");
        if (mfile == NULL)
                return;
 
        for (;
-           (p = fparseln(mfile, &len, NULL, NULL, FPARSELN_UNESCALL));
-           free(p)) {
+           (line = fparseln(mfile, &len, NULL, NULL, FPARSELN_UNESCALL));
+           free(line)) {
                if (len == 0)
                        continue;
 
+               p = line;
                /* Find the key, replace trailing whitespace will <NUL> */
                for (k = p; *p && !isspace(*p); p++)
                        ;
diff -r c3cbfbc996e3 -r 1635cd9e7bfe usr.sbin/ypserv/revnetgroup/revnetgroup.c
--- a/usr.sbin/ypserv/revnetgroup/revnetgroup.c Sun Jul 25 08:55:46 1999 +0000
+++ b/usr.sbin/ypserv/revnetgroup/revnetgroup.c Sun Jul 25 09:01:04 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: revnetgroup.c,v 1.6 1998/06/08 06:53:49 lukem Exp $ */
+/*     $NetBSD: revnetgroup.c,v 1.7 1999/07/25 09:01:05 lukem Exp $ */
 
 /*
  * Copyright (c) 1995
@@ -41,7 +41,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: revnetgroup.c,v 1.6 1998/06/08 06:53:49 lukem Exp $");
+__RCSID("$NetBSD: revnetgroup.c,v 1.7 1999/07/25 09:01:05 lukem Exp $");
 #endif
 
 #include <ctype.h>
@@ -90,7 +90,7 @@
        struct group_entry *gcur;
        struct member_entry *mcur;
        FILE    *fp;
-       char    *p, *host, *user, *domain;
+       char    *line, *p, *host, *user, *domain;
        int      ch, i;
        size_t   len;
        char    *key;
@@ -137,10 +137,11 @@
 
        /* Stuff all the netgroup names and members into a hash table. */
        for (;
-           (p = fparseln(fp, &len, NULL, NULL, FPARSELN_UNESCALL));
-           free(p)) {
+           (line = fparseln(fp, &len, NULL, NULL, FPARSELN_UNESCALL));
+           free(line)) {
                if (len == 0)
                        continue;
+               p = line;
 
                for (key = p; *p && isspace(*p) == 0; p++)
                        ;
diff -r c3cbfbc996e3 -r 1635cd9e7bfe usr.sbin/ypserv/stdhosts/stdhosts.c
--- a/usr.sbin/ypserv/stdhosts/stdhosts.c       Sun Jul 25 08:55:46 1999 +0000
+++ b/usr.sbin/ypserv/stdhosts/stdhosts.c       Sun Jul 25 09:01:04 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stdhosts.c,v 1.10 1999/01/17 07:01:26 lukem Exp $       */
+/*     $NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $       */
 
 /*
  * Copyright (c) 1994 Mats O Jansson <moj%stacken.kth.se@localhost>
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: stdhosts.c,v 1.10 1999/01/17 07:01:26 lukem Exp $");
+__RCSID("$NetBSD: stdhosts.c,v 1.11 1999/07/25 09:01:05 lukem Exp $");
 #endif
 
 #include <sys/types.h>
@@ -64,7 +64,7 @@
        FILE    *data_file;
        size_t   line_no;
        size_t   len;
-       char    *k, *v, *addr_string, *fname;
+       char    *line, *k, *v, *addr_string, *fname;
 
        addr_string = NULL;             /* XXX gcc -Wuninitialized */
 
@@ -83,11 +83,13 @@
 
        line_no = 0;
        for (;
-           (v = fparseln(data_file, &len, &line_no, NULL, FPARSELN_UNESCALL));
-           free(v)) {
+           (line = fparseln(data_file, &len, &line_no, NULL,
+               FPARSELN_UNESCALL));
+           free(line)) {
                if (len == 0)
                        continue;
 
+               v = line;
                for (k = v; *v && !isspace(*v); v++)
                        ;
                while (*v && isspace(*v))



Home | Main Index | Thread Index | Old Index