From owner-svn-src-stable-11@freebsd.org Wed Oct 23 17:28:36 2019 Return-Path: Delivered-To: svn-src-stable-11@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3D2B9158E45; Wed, 23 Oct 2019 17:28:36 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46yy5c0jmQz4Nxh; Wed, 23 Oct 2019 17:28:36 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id ECC5027DA5; Wed, 23 Oct 2019 17:28:35 +0000 (UTC) (envelope-from brooks@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9NHSZF1057156; Wed, 23 Oct 2019 17:28:35 GMT (envelope-from brooks@FreeBSD.org) Received: (from brooks@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9NHSZmr057155; Wed, 23 Oct 2019 17:28:35 GMT (envelope-from brooks@FreeBSD.org) Message-Id: <201910231728.x9NHSZmr057155@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: brooks set sender to brooks@FreeBSD.org using -f From: Brooks Davis Date: Wed, 23 Oct 2019 17:28:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r353939 - stable/11/usr.bin/rpcgen X-SVN-Group: stable-11 X-SVN-Commit-Author: brooks X-SVN-Commit-Paths: stable/11/usr.bin/rpcgen X-SVN-Commit-Revision: 353939 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Oct 2019 17:28:36 -0000 Author: brooks Date: Wed Oct 23 17:28:35 2019 New Revision: 353939 URL: https://svnweb.freebsd.org/changeset/base/353939 Log: MFC r353569: rpcgen: make compiler arglist allocation dynamic Limit argmax to an absurdly large value prevent overflow (no overflow possible on FreeBSD due to ARG_MAX). In CheriBSD we exceed the 19 non-NULL arguments in the static array. Add a simple size doubling allocator and increase the default to 32. GC remnants of support for fixed arguments. Reviewed by: archardson (prior version), James Clarke (prior version) Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D21971 Modified: stable/11/usr.bin/rpcgen/rpc_main.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/rpcgen/rpc_main.c ============================================================================== --- stable/11/usr.bin/rpcgen/rpc_main.c Wed Oct 23 17:20:20 2019 (r353938) +++ stable/11/usr.bin/rpcgen/rpc_main.c Wed Oct 23 17:28:35 2019 (r353939) @@ -93,19 +93,13 @@ static int allnc = nitems(allnv); */ static void addarg(const char *); /* add another argument to the list */ static void insarg(int, const char *); /* insert arg at specified location */ -static void clear_args(void); /* clear argument list */ static void checkfiles(const char *, const char *); /* check if out file already exists */ +static char **arglist; +static int argcount = 0; +static int argmax = 0; - -#define ARGLISTLEN 20 -#define FIXEDARGS 0 - -static char *arglist[ARGLISTLEN]; -static int argcount = FIXEDARGS; - - int nonfatalerrors; /* errors */ int inetdflag = 0; /* Support for inetd is disabled by default, use -I */ int pmflag = 0; /* Support for port monitors is disabled by default */ @@ -141,7 +135,6 @@ main(int argc, const char *argv[]) struct commandline cmd; (void) memset((char *)&cmd, 0, sizeof (struct commandline)); - clear_args(); if (!parseargs(argc, argv, &cmd)) usage(); /* @@ -273,16 +266,6 @@ add_warning(void) f_print(fout, " */\n\n"); } -/* clear list of arguments */ -static void -clear_args(void) -{ - int i; - for (i = FIXEDARGS; i < ARGLISTLEN; i++) - arglist[i] = NULL; - argcount = FIXEDARGS; -} - /* prepend C-preprocessor and flags before arguments */ static void prepend_cpp(void) @@ -921,21 +904,40 @@ do_registers(int argc, const char *argv[]) } /* - * Add another argument to the arg list + * Extend the argument list */ static void -addarg(const char *cp) +moreargs(void) { - if (argcount >= ARGLISTLEN) { - warnx("too many defines"); + char **newarglist; + + argmax = argmax == 0 ? 32 : argmax << 1; + if (argmax > INT_MAX / 4) { + warnx("refusing to allocate too many arguments"); crash(); - /*NOTREACHED*/ } + newarglist = realloc(arglist, argmax * sizeof(*arglist)); + if (newarglist == NULL) { + warnx("unable to allocate arglist"); + crash(); + } + free(arglist); + arglist = newarglist; +} + +/* + * Add another argument to the arg list + */ +static void +addarg(const char *cp) +{ + if (argcount >= argmax) + moreargs(); + if (cp != NULL) arglist[argcount++] = xstrdup(cp); else arglist[argcount++] = NULL; - } /* @@ -946,11 +948,8 @@ insarg(int place, const char *cp) { int i; - if (argcount >= ARGLISTLEN) { - warnx("too many defines"); - crash(); - /*NOTREACHED*/ - } + if (argcount >= argmax) + moreargs(); /* Move up existing arguments */ for (i = argcount - 1; i >= place; i--)