From nobody Thu Feb 16 20:37:36 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHmwJ2HJ5z3rVg3; Thu, 16 Feb 2023 20:37:36 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHmwJ1jcnz3vxL; Thu, 16 Feb 2023 20:37:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676579856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1rossOgng60yxtutRLUfCRL88HVrw6+PZjXnslexh3E=; b=J7r/iJdxtvtH0SxUrhLJ6lTjke/iLjVGdoy7KQGnjgqOvSNHct1L3iGQXsP5iuIu1KLp0U oo/L2D2Dr//EZPy8Am4iIiB9SBNnw2gg58mKG20zFGkm09SPp45SPsEYoOYl51TPq2bxtb cN/qrGpX1fe2gqGjMYq1GWBs6VU6JpYqmhS20O32nuUDzZYaVbaTYxR01S2c9VzHKBtpz9 m71lqoue2DcUaTsSHDW3aIknRpNClGepeeJ3f0agpj+WkjRm9tkNuh4g1zHtxhuDLxkNmR y8FC12jKYCzp1cMtEtbo/6qCPvQVIdCvfGCP59rb4Xa+K//nf98RWSJ3GHZIYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676579856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1rossOgng60yxtutRLUfCRL88HVrw6+PZjXnslexh3E=; b=aD9e1Xex8QSqfJcRf0Pm3nQAdvlhEPH58sGpOVaf05B+xSj19vB4FrZiSFgRMAVhlWOy4O iTmvVVnfOWKR82MGzFKTJQQdKxQ+v7qzEkebo8pvQtU29bYsSqW2q23GoMnhP5in5nFN+i 9f5h1HyVF0/7LcbExqivnwYLnpM4w8R7N3gULEd3yMA7+mLQEvaFBidJhVMMJuZFwEUO1R TzlEiITHYziJNz+yS75738k0xvbw/SlkCMgz1PBnehAklawQv3DvKAoy2Fg8vkQYWEKEAm DtqcjDgD/eM3d6r8kWuWiMiUG5W4h14UDp0Rm3rEjdY5DdMlOqj2givrVl1q9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676579856; a=rsa-sha256; cv=none; b=ToBRbw4p2vymI+Tn/0LLhROsnI/RZKrNQgRG9+R4pic32OkeZ1srrF3lRb7VSen82s9SV4 w6p7tJjb34C1GbPXw//+gFEpPpz0lK4SX7qcK5uWrRMO3IrYYR/4LsjuzDlIOetROKNB3v a4bzJS8ykM6eJaBOQ5q/ZKsNsUCdOcru/vgIibrS6PUjuoUn01anzWrD+gdoTeO8HzNkcF nNs7FzsqzbPZTXEG5mnTQVNr6692Zw/E990Qdgo/sOvJW3yYzCLECTU7k8xiA2o3rLG9c6 4YSYx6xX5hA01fTHuOPzAQJXre7QzHbyWUTpK08zxxV5fvyc415tdtIeE2FVcQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PHmwJ0mWqzHHB; Thu, 16 Feb 2023 20:37:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31GKbaPM002527; Thu, 16 Feb 2023 20:37:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31GKba12002526; Thu, 16 Feb 2023 20:37:36 GMT (envelope-from git) Date: Thu, 16 Feb 2023 20:37:36 GMT Message-Id: <202302162037.31GKba12002526@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: da8884202940 - main - config: error out on malformed env/hint lines List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: da8884202940498096a8c37d91d2fbbf471c6e7b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=da8884202940498096a8c37d91d2fbbf471c6e7b commit da8884202940498096a8c37d91d2fbbf471c6e7b Author: Kyle Evans AuthorDate: 2023-02-16 20:36:17 +0000 Commit: Kyle Evans CommitDate: 2023-02-16 20:37:05 +0000 config: error out on malformed env/hint lines We need these to be assignments, error out if they're not. While we're here, tag errout as __printflike so that the compiler will sanity check the format string + args. CID: 1505293 Reviewed by: emaste, imp Differential Revision: https://reviews.freebsd.org/D38642 --- usr.sbin/config/mkmakefile.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/usr.sbin/config/mkmakefile.cc b/usr.sbin/config/mkmakefile.cc index 969d32cf1389..2aaed82ce3ee 100644 --- a/usr.sbin/config/mkmakefile.cc +++ b/usr.sbin/config/mkmakefile.cc @@ -69,10 +69,11 @@ static void read_files(void); static void sanitize_envline(char *result, const char *src); static bool preprocess(char *line, char *result); static void process_into_file(char *line, FILE *ofp); -static void process_into_map(char *line, env_map &emap); +static int process_into_map(char *line, env_map &emap); static void dump_map(env_map &emap, FILE *ofp); -static void errout(const char *fmt, ...) +static void __printflike(1, 2) +errout(const char *fmt, ...) { va_list ap; @@ -269,16 +270,20 @@ process_into_file(char *line, FILE *ofp) fprintf(ofp, "\"%s\\0\"\n", result); } -static void +static int process_into_map(char *line, env_map &emap) { char result[BUFSIZ], *s; if (preprocess(line, result)) { s = strchr(result, '='); + if (s == NULL) + return (EINVAL); *s = '\0'; emap[result] = s + 1; } + + return (0); } static void @@ -320,8 +325,11 @@ makehints(void) ifp = fopen(hint->hint_name, "r"); if (ifp == NULL) err(1, "%s", hint->hint_name); - while (fgets(line, BUFSIZ, ifp) != NULL) - process_into_map(line, emap); + while (fgets(line, BUFSIZ, ifp) != NULL) { + if (process_into_map(line, emap) != 0) + errout("%s: malformed line: %s\n", + hint->hint_name, line); + } dump_map(emap, ofp); fclose(ifp); } @@ -360,8 +368,11 @@ makeenv(void) ifp = fopen(envvar->env_str, "r"); if (ifp == NULL) err(1, "%s", envvar->env_str); - while (fgets(line, BUFSIZ, ifp) != NULL) - process_into_map(line, emap); + while (fgets(line, BUFSIZ, ifp) != NULL) { + if (process_into_map(line, emap) != 0) + errout("%s: malformed line: %s\n", + envvar->env_str, line); + } dump_map(emap, ofp); fclose(ifp); } else