Source-Changes-HG archive

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

[src/trunk]: src/libexec/lfs_cleanerd use bounded string ops. check malloc f...



details:   https://anonhg.NetBSD.org/src/rev/fa91ec61cf83
branches:  trunk
changeset: 549381:fa91ec61cf83
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Jul 13 09:44:02 2003 +0000

description:
use bounded string ops.  check malloc failure.  asprintf is easier than
complicated strcat/strcpy combination.

diffstat:

 libexec/lfs_cleanerd/cleanerd.c |  20 +++++++++++++-------
 libexec/lfs_cleanerd/library.c  |  12 +++++++-----
 2 files changed, 20 insertions(+), 12 deletions(-)

diffs (88 lines):

diff -r af1698799929 -r fa91ec61cf83 libexec/lfs_cleanerd/cleanerd.c
--- a/libexec/lfs_cleanerd/cleanerd.c   Sun Jul 13 09:40:20 2003 +0000
+++ b/libexec/lfs_cleanerd/cleanerd.c   Sun Jul 13 09:44:02 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cleanerd.c,v 1.47 2003/04/02 10:39:22 fvdl Exp $       */
+/*     $NetBSD: cleanerd.c,v 1.48 2003/07/13 09:44:02 itojun Exp $     */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)cleanerd.c 8.5 (Berkeley) 6/10/95";
 #else
-__RCSID("$NetBSD: cleanerd.c,v 1.47 2003/04/02 10:39:22 fvdl Exp $");
+__RCSID("$NetBSD: cleanerd.c,v 1.48 2003/07/13 09:44:02 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -295,15 +295,18 @@
                lasttime=0;
                loopcount=0;
            loop:
-               if((childpid=fork())<0) {
+               if ((childpid=fork()) < 0) {
                        syslog(LOG_ERR,"%s: couldn't fork, exiting: %m",
                                fs_name);
                        exit(1);
                }
                if(childpid == 0) {
                        /* Record child's pid */
-                       pidname = malloc(strlen(fs_name) + 16);
-                       sprintf(pidname, "lfs_cleanerd:s:%s", fs_name);
+                       asprintf(&pidname, "lfs_cleanerd:s:%s", fs_name);
+                       if (!pidname) {
+                               syslog(LOG_WARNING,"malloc failed: %m");
+                               exit(1);
+                       }
                        while((cp = strchr(pidname, '/')) != NULL)
                                *cp = '|';
                        pidfile(pidname);
@@ -313,8 +316,11 @@
                        }
                } else {
                        /* Record parent's pid */
-                       pidname = malloc(strlen(fs_name) + 16);
-                       sprintf(pidname, "lfs_cleanerd:m:%s", fs_name);
+                       asprintf(&pidname, "lfs_cleanerd:m:%s", fs_name);
+                       if (!pidname) {
+                               syslog(LOG_WARNING,"malloc failed: %m");
+                               exit(1);
+                       }
                        while((cp = strchr(pidname, '/')) != NULL)
                                *cp = '|';
                        pidfile(pidname);
diff -r af1698799929 -r fa91ec61cf83 libexec/lfs_cleanerd/library.c
--- a/libexec/lfs_cleanerd/library.c    Sun Jul 13 09:40:20 2003 +0000
+++ b/libexec/lfs_cleanerd/library.c    Sun Jul 13 09:44:02 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: library.c,v 1.35 2003/04/02 10:39:22 fvdl Exp $        */
+/*     $NetBSD: library.c,v 1.36 2003/07/13 09:44:02 itojun Exp $      */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)library.c  8.3 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: library.c,v 1.35 2003/04/02 10:39:22 fvdl Exp $");
+__RCSID("$NetBSD: library.c,v 1.36 2003/07/13 09:44:02 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -276,10 +276,12 @@
        int count;
 
        ifp = NULL;
-       ifile_name = malloc(strlen(fsp->fi_statfsp->f_mntonname) +
-           strlen(IFILE_NAME)+2);
-       strcat(strcat(strcpy(ifile_name, fsp->fi_statfsp->f_mntonname), "/"),
+       asprintf(&ifile_name, "%s/%s", fsp->fi_statfsp->f_mntonname,
            IFILE_NAME);
+       if (!ifile_name) {
+               syslog(LOG_ERR, "get_ifile: malloc failed: %m");
+               exit(1);
+       }
 
        if(ifile_fd == -1) {
                /* XXX KS - Do we ever *write* to the ifile? */



Home | Main Index | Thread Index | Old Index