bin/135159: pkg_delete segfaults on empty @pkgdep lines

Mikolaj Golub to.my.trociny at gmail.com
Fri Jun 5 07:40:03 UTC 2009


The following reply was made to PR bin/135159; it has been noted by GNATS.

From: Mikolaj Golub <to.my.trociny at gmail.com>
To: bug-followup at FreeBSD.org,matthias.andree at 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",
 
 --=-=-=--


More information about the freebsd-bugs mailing list