Source-Changes-HG archive

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

[src/trunk]: src/sys/kern copyinargs: Replace a hand-written string copy loop...



details:   https://anonhg.NetBSD.org/src/rev/1cd44219c328
branches:  trunk
changeset: 328696:1cd44219c328
user:      uebayasi <uebayasi%NetBSD.org@localhost>
date:      Mon Apr 14 05:39:19 2014 +0000

description:
copyinargs: Replace a hand-written string copy loop with strlcpy(3).  Carefully
reuse return value of strlcpy(3) to iterate.

diffstat:

 sys/kern/kern_exec.c |  25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diffs (61 lines):

diff -r 6e64b300c00b -r 1cd44219c328 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Mon Apr 14 01:56:18 2014 +0000
+++ b/sys/kern/kern_exec.c      Mon Apr 14 05:39:19 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.393 2014/04/13 12:11:01 uebayasi Exp $ */
+/*     $NetBSD: kern_exec.c,v 1.394 2014/04/14 05:39:19 uebayasi Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.393 2014/04/13 12:11:01 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.394 2014/04/14 05:39:19 uebayasi Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1408,8 +1408,6 @@
 
        dp = *dpp;
 
-       /* XXX -- THE FOLLOWING SECTION NEEDS MAJOR CLEANUP */
-
        data->ed_argc = 0;
 
        /* copy the fake args list, if there's one, freeing it as we go */
@@ -1417,14 +1415,17 @@
                struct exec_fakearg     *tmpfap = epp->ep_fa;
 
                while (tmpfap->fa_arg != NULL) {
-                       const char *cp;
+                       const size_t maxlen = ARG_MAX - (dp - data->ed_argp);
+                       size_t len;
 
-                       /* XXX boudary check */
-                       cp = tmpfap->fa_arg;
-                       while (*cp)
-                               *dp++ = *cp++;
-                       *dp++ = '\0';
-                       ktrexecarg(tmpfap->fa_arg, cp - tmpfap->fa_arg);
+                       len = strlcpy(dp, tmpfap->fa_arg, maxlen);
+                       /* Count NUL into len. */
+                       if (len < maxlen)
+                               len++;
+                       else
+                               len = maxlen;
+                       ktrexecarg(tmpfap->fa_arg, len - 1);
+                       dp += len;
 
                        kmem_free(tmpfap->fa_arg, tmpfap->fa_len);
                        tmpfap++;
@@ -1487,7 +1488,7 @@
 
        i = 0;
        while (1) {
-               const size_t maxlen = data->ed_argp + ARG_MAX - dp;
+               const size_t maxlen = ARG_MAX - (dp - data->ed_argp);
                size_t len;
 
                if ((error = (*fetch_element)(strs, i, &sp)) != 0) {



Home | Main Index | Thread Index | Old Index