pkgsrc-Changes-HG archive

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

[pkgsrc/pkg_install-renovation]: pkgsrc/pkgtools/pkg_install/files/lib pkg_in...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/610137a4df65
branches:  pkg_install-renovation
changeset: 541603:610137a4df65
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Tue Sep 16 19:03:54 2008 +0000

description:
pkg_install-20080916:
Quote arguments of @exec and @unexec correctly.

diffstat:

 pkgtools/pkg_install/files/lib/file.c    |  111 ++++++++++++++++++------------
 pkgtools/pkg_install/files/lib/version.h |    4 +-
 2 files changed, 69 insertions(+), 46 deletions(-)

diffs (158 lines):

diff -r ef115c280541 -r 610137a4df65 pkgtools/pkg_install/files/lib/file.c
--- a/pkgtools/pkg_install/files/lib/file.c     Mon Sep 08 23:07:16 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/file.c     Tue Sep 16 19:03:54 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: file.c,v 1.23.8.2 2008/08/21 16:04:39 joerg Exp $      */
+/*     $NetBSD: file.c,v 1.23.8.3 2008/09/16 19:03:54 joerg Exp $      */
 
 #if HAVE_CONFIG_H
 #include "config.h"
@@ -17,7 +17,7 @@
 #if 0
 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
 #else
-__RCSID("$NetBSD: file.c,v 1.23.8.2 2008/08/21 16:04:39 joerg Exp $");
+__RCSID("$NetBSD: file.c,v 1.23.8.3 2008/09/16 19:03:54 joerg Exp $");
 #endif
 #endif
 
@@ -300,57 +300,80 @@
 int
 format_cmd(char *buf, size_t size, const char *fmt, const char *dir, const char *name)
 {
-       char    scratch[MaxPathSize * 2];
-       char   *bufp;
+       size_t  remaining, quoted;
+       char   *bufp, *tmp;
        char   *cp;
 
-       for (bufp = buf; (int) (bufp - buf) < size && *fmt;) {
-               if (*fmt == '%') {
-                       if (*++fmt != 'D' && name == NULL) {
-                               warnx("no last file available for '%s' command", buf);
+       for (bufp = buf, remaining = size; remaining > 1 && *fmt;) {
+               if (*fmt != '%') {
+                       *bufp++ = *fmt++;
+                       --remaining;
+                       continue;
+               }
+
+               if (*++fmt != 'D' && name == NULL) {
+                       warnx("no last file available for '%s' command", buf);
+                       return -1;
+               }
+               switch (*fmt) {
+               case 'F':
+                       quoted = shquote(name, bufp, remaining);
+                       if (quoted >= remaining) {
+                               warnx("overflow during quoting");
+                               return -1;
+                       }
+                       bufp += quoted;
+                       remaining -= quoted;
+                       break;
+
+               case 'D':
+                       quoted = shquote(dir, bufp, remaining);
+                       if (quoted >= remaining) {
+                               warnx("overflow during quoting");
                                return -1;
                        }
-                       switch (*fmt) {
-                       case 'F':
-                               strlcpy(bufp, name, size - (int) (bufp - buf));
-                               bufp += strlen(bufp);
-                               break;
+                       bufp += quoted;
+                       remaining -= quoted;
+                       break;
 
-                       case 'D':
-                               strlcpy(bufp, dir, size - (int) (bufp - buf));
-                               bufp += strlen(bufp);
-                               break;
-
-                       case 'B':
-                               (void) snprintf(scratch, sizeof(scratch), "%s/%s", dir, name);
-                               if ((cp = strrchr(scratch, '/')) == (char *) NULL) {
-                                       cp = scratch;
-                               }
-                               *cp = '\0';
-                               strlcpy(bufp, scratch, size - (int) (bufp - buf));
-                               bufp += strlen(bufp);
-                               break;
+               case 'B':
+                       tmp = xasprintf("%s/%s", dir, name);
+                       cp = strrchr(tmp, '/');
+                       *cp = '\0';
+                       quoted = shquote(tmp, bufp, remaining);
+                       free(tmp);
+                       if (quoted >= remaining) {
+                               warnx("overflow during quoting");
+                               return -1;
+                       }
+                       bufp += quoted;
+                       remaining -= quoted;
+                       break;
 
-                       case 'f':
-                               (void) snprintf(scratch, sizeof(scratch), "%s/%s", dir, name);
-                               if ((cp = strrchr(scratch, '/')) == (char *) NULL) {
-                                       cp = scratch;
-                               } else {
-                                       cp++;
-                               }
-                               strlcpy(bufp, cp, size - (int) (bufp - buf));
-                               bufp += strlen(bufp);
-                               break;
+               case 'f':
+                       tmp = xasprintf("%s/%s", dir, name);
+                       cp = strrchr(tmp, '/') + 1;
+                       quoted = shquote(cp, bufp, remaining);
+                       free(tmp);
+                       if (quoted >= remaining) {
+                               warnx("overflow during quoting");
+                               return -1;
+                       }
+                       bufp += quoted;
+                       remaining -= quoted;
+                       break;
 
-                       default:
-                               *bufp++ = '%';
-                               *bufp++ = *fmt;
-                               break;
+               default:
+                       if (remaining == 1) {
+                               warnx("overflow during quoting");
+                               return -1;
                        }
-                       ++fmt;
-               } else {
-                       *bufp++ = *fmt++;
+                       *bufp++ = '%';
+                       *bufp++ = *fmt;
+                       remaining -= 2;
+                       break;
                }
+               ++fmt;
        }
        *bufp = '\0';
        return 0;
diff -r ef115c280541 -r 610137a4df65 pkgtools/pkg_install/files/lib/version.h
--- a/pkgtools/pkg_install/files/lib/version.h  Mon Sep 08 23:07:16 2008 +0000
+++ b/pkgtools/pkg_install/files/lib/version.h  Tue Sep 16 19:03:54 2008 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: version.h,v 1.102.2.15 2008/08/25 19:15:11 joerg Exp $ */
+/*     $NetBSD: version.h,v 1.102.2.16 2008/09/16 19:03:54 joerg Exp $ */
 
 /*
  * Copyright (c) 2001 Thomas Klausner.  All rights reserved.
@@ -27,6 +27,6 @@
 #ifndef _INST_LIB_VERSION_H_
 #define _INST_LIB_VERSION_H_
 
-#define PKGTOOLS_VERSION "20080825"
+#define PKGTOOLS_VERSION "20080916"
 
 #endif /* _INST_LIB_VERSION_H_ */



Home | Main Index | Thread Index | Old Index