From owner-freebsd-bugs@FreeBSD.ORG Fri Jun 5 07:40:03 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5E121106566B for ; Fri, 5 Jun 2009 07:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 4BE178FC1A for ; Fri, 5 Jun 2009 07:40:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n557e3cB012749 for ; Fri, 5 Jun 2009 07:40:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n557e3I1012748; Fri, 5 Jun 2009 07:40:03 GMT (envelope-from gnats) Date: Fri, 5 Jun 2009 07:40:03 GMT Message-Id: <200906050740.n557e3I1012748@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Mikolaj Golub Cc: Subject: Re: bin/135159: pkg_delete segfaults on empty @pkgdep lines X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Mikolaj Golub List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2009 07:40:03 -0000 The following reply was made to PR bin/135159; it has been noted by GNATS. From: Mikolaj Golub To: bug-followup@FreeBSD.org,matthias.andree@gmx.de Cc: Subject: Re: bin/135159: pkg_delete segfaults on empty @pkgdep lines Date: Fri, 05 Jun 2009 10:39:18 +0300 --=-=-= I see the fix in CURRENT for this problem: Tue May 19 14:26:41 2009 UTC (2 weeks, 2 days ago) by flz Branches: MAIN CVS tags: HEAD Diff to: previous 1.55: preferred, colored Changes since revision 1.55: +4 -0 lines SVN rev 192382 on 2009-05-19 14:26:41Z by flz Skip @pkgdep if there's no argument. Submitted by: pav MFC after: 1 week But actually I don't like very much the solution. It fixes only this particular case with @pkgdep but leaves the same potential problems with other commands. We could fix this as it is proposed in the patch attached. I have added argument checking for the commands I was sure that they needed it but some other commands might need the check too. -- Mikolaj Golub --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=pkg_install.patch Index: lib/lib.h =================================================================== --- lib/lib.h (revision 193485) +++ lib/lib.h (working copy) @@ -39,6 +39,7 @@ /* Macros */ #define SUCCESS (0) #define FAIL (-1) +#define FAIL_ARGMISS (-2) #ifndef TRUE #define TRUE (1) Index: lib/plist.c =================================================================== --- lib/plist.c (revision 193485) +++ lib/plist.c (working copy) @@ -208,14 +208,23 @@ *arg = (char *)sp; if (!strcmp(cmd, "cwd")) return PLIST_CWD; - else if (!strcmp(cmd, "srcdir")) - return PLIST_SRC; - else if (!strcmp(cmd, "cd")) + else if (!strcmp(cmd, "srcdir")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_SRC; + } else if (!strcmp(cmd, "cd")) return PLIST_CWD; - else if (!strcmp(cmd, "exec")) - return PLIST_CMD; - else if (!strcmp(cmd, "unexec")) - return PLIST_UNEXEC; + else if (!strcmp(cmd, "exec")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_CMD; + } else if (!strcmp(cmd, "unexec")) + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_UNEXEC; else if (!strcmp(cmd, "mode")) return PLIST_CHMOD; else if (!strcmp(cmd, "owner")) @@ -237,21 +246,42 @@ return PLIST_IGNORE; else if (!strcmp(cmd, "ignore_inst")) return PLIST_IGNORE_INST; - else if (!strcmp(cmd, "name")) - return PLIST_NAME; - else if (!strcmp(cmd, "display")) - return PLIST_DISPLAY; - else if (!strcmp(cmd, "pkgdep")) - return PLIST_PKGDEP; - else if (!strcmp(cmd, "conflicts")) - return PLIST_CONFLICTS; - else if (!strcmp(cmd, "mtree")) - return PLIST_MTREE; - else if (!strcmp(cmd, "dirrm")) - return PLIST_DIR_RM; - else if (!strcmp(cmd, "option")) - return PLIST_OPTION; - else + else if (!strcmp(cmd, "name")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_NAME; + } else if (!strcmp(cmd, "display")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_DISPLAY; + } else if (!strcmp(cmd, "pkgdep")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_PKGDEP; + } else if (!strcmp(cmd, "conflicts")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_CONFLICTS; + } else if (!strcmp(cmd, "mtree")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_MTREE; + } else if (!strcmp(cmd, "dirrm")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_DIR_RM; + } else if (!strcmp(cmd, "option")) { + if (**arg == '\0') + return FAIL_ARGMISS; + else + return PLIST_OPTION; + } else return FAIL; } @@ -283,12 +313,14 @@ __func__, pline); goto bottom; } + if (cmd == FAIL_ARGMISS) { + warnx("%s: command '%s': required argument is missed, ignoring", + __func__, pline); + cmd = FAIL; + goto bottom; + } if (*cp == '\0') { cp = NULL; - if (cmd == PLIST_PKGDEP) { - warnx("corrupted record (pkgdep line without argument), ignoring"); - cmd = FAIL; - } goto bottom; } if (cmd == PLIST_COMMENT && sscanf(cp, "PKG_FORMAT_REVISION:%d.%d\n", --=-=-=--