From nobody Fri Jul 14 01:37:23 2023 X-Original-To: dev-commits-src-all@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 4R2DcN0lyZz4mmpD; Fri, 14 Jul 2023 01:37:24 +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 4R2DcN0HX3z4l06; Fri, 14 Jul 2023 01:37:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689298644; 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=5MEyeQyyojPL8YcFWSGmbg6wCyyS+B32T5Mx0gOcON8=; b=NzCEiyM60r5L84rL9xNJDtJAgOA1kZG/VqzbHiZJKut/slnD3tfog7kHKQvcBwCsL0g3Pr SbUwCz+IORKKOb9HNbPJJ6hOd1nW6dqZbBRefqtrFvq91fhtb8Z3y48tZ9b81z8Hxr2QNB F5RtXD0Uwq639TMvXO7MOkxm+WZlD1mx0ViPHj0kFuYvoeN9cfJ2oGllI5RY6cWJ//59Md de4n0mksHjl2IyTUXmFy3snW5gqNhu436QDbMrzORHMNzVAnQD2LHxojqOLBwn/grC8USF 01/l4wqUjLOHvmveHFXjq/t3eUPzXZseGsY+DxF7aim7rf7/ZC3oLOfhWAMacA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689298644; 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=5MEyeQyyojPL8YcFWSGmbg6wCyyS+B32T5Mx0gOcON8=; b=L2TiDo3ynMPfnjt70laUtI98SmM4IsjoPqY+CNksEmVw+oIZMafvBkxHwoHhnNp75zVbZc l6RidqJE08Og3qkK+fcbXoF6dlrdQW41xioy7vYKUn5786cK3h5QA8X9a+pHuLXr1Sx5M3 Pc4k3kIdTjqPvHgl2GLHiWjZjeDrIU/4Kym5JxjfTEosffzW7fhnTl/PPUTQlVFA+/S8X1 1Td+EamO2laXiyb5DGzu8XzzgVdOptKkJI4+pidHJpdyQp8JOJUFwHfL35ysTf8DFHU3Vv k/MxBn4vN7rvn6Vpdo5Ey3HJnWZaAuN93FKwHPEuy6632x27XDaPUimDeYQ49Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689298644; a=rsa-sha256; cv=none; b=S07x/tPLZ+0mjRkNTSVas1kD/rMiq0CU9yW/BnqEvszn44T/inr870f0cjoaEUKESNtYXK goFp9eMmFtgk2HiUuNRXqU2yeqeSg3PM+FLv/3ehq8yj2WTzdSG/81+GJgCvuHAB9y5c9I 7OAHRtBMAiVaUiWSEwEk570pqEeSr8g8z/lPWB42uGIFAPule2mU6vf7hZ6JqnjQbooq8p xwl+Qej66Rb65jBP+fjzq7AfiUPaEXGoUwRFR2aKl3JpoUo8fgFpZDmZnkLtvFyKNwjaph y/kJ6ZNOQBatBHTfSFbuOcfpnnxJOJlOZCBk33V2dCa0D8tqCu/Jnw0gQhOirw== 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 4R2DcM6Nyrz1DYv; Fri, 14 Jul 2023 01:37:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 36E1bNa3019326; Fri, 14 Jul 2023 01:37:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 36E1bNJX019325; Fri, 14 Jul 2023 01:37:23 GMT (envelope-from git) Date: Fri, 14 Jul 2023 01:37:23 GMT Message-Id: <202307140137.36E1bNJX019325@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 587458b7d67a - main - rpcgen: Perform shell-style word expansion on RPCGEN_CPP List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 587458b7d67a697c53fc2e31fb3407d1084fe773 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=587458b7d67a697c53fc2e31fb3407d1084fe773 commit 587458b7d67a697c53fc2e31fb3407d1084fe773 Author: Jessica Clarke AuthorDate: 2023-07-14 01:35:25 +0000 Commit: Jessica Clarke CommitDate: 2023-07-14 01:35:25 +0000 rpcgen: Perform shell-style word expansion on RPCGEN_CPP Up until recently, CPP has been a list of space-separated words, with no quotes, backslashes or other characters with special meaning to a shell. However, as of 8fad2cda93c7, (escaped) quotes appear in CPP, and the rudimentary parser in rpcgen is insufficient, since it will leave the escaped quotes as escaped rather than performing one level of expansion as would be done by a shell (whether in a script or a Makefile). Rather than hack around this in all the places RPCGEN_CPP gets set, implement proper expansion inside rpcgen. Note that this only deals with a subset of shell syntax, since we don't handle any of: | & ; < > ( ) $ ` * ? [ # ˜ = % having special meaning (with the exception of how a backslash behaves inside double quotes, where \$ means a literal $ inside double quotes but \a means a literal \a), instead using their literal value, but those are all reasonable restrictions, and can be worked around by avoiding their use; what's important is that we get the quoting and splitting right. This fixes -Winvalid-pp-token spew during build${libcompat}. Reviewed by: brooks Fixes: 8fad2cda93c7 ("bsd.compat.mk: Provide new CPP and sub-make variables") Differential Revision: https://reviews.freebsd.org/D41013 --- usr.bin/rpcgen/rpc_main.c | 111 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 8 deletions(-) diff --git a/usr.bin/rpcgen/rpc_main.c b/usr.bin/rpcgen/rpc_main.c index ba9eda676b39..6576d6cfb919 100644 --- a/usr.bin/rpcgen/rpc_main.c +++ b/usr.bin/rpcgen/rpc_main.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include @@ -270,20 +271,114 @@ add_warning(void) static void prepend_cpp(void) { - int idx = 0; - const char *var; - char *dupvar, *s, *t; + int idx = 0, quoted; + const char *var, *s; + char *dupvar, *t, *word; if (CPP != NULL) insarg(idx++, CPP); else if ((var = getenv("RPCGEN_CPP")) == NULL) insarg(idx++, "/usr/bin/cpp"); else { - /* Parse command line in a rudimentary way */ - dupvar = xstrdup(var); - for (s = dupvar; (t = strsep(&s, " \t")) != NULL; ) { - if (t[0]) - insarg(idx++, t); + /* + * Parse command line like a shell (but only handle whitespace, + * quotes and backslash). + */ + dupvar = malloc(strlen(var) + 1); + quoted = 0; + word = NULL; + for (s = var, t = dupvar; *s; ++s) { + switch (quoted) { + /* Unquoted */ + case 0: + switch (*s) { + case ' ': + case '\t': + case '\n': + if (word != NULL) { + *t++ = '\0'; + insarg(idx++, word); + word = NULL; + } + break; + case '\'': + if (word == NULL) + word = t; + quoted = 1; + break; + case '"': + if (word == NULL) + word = t; + quoted = 2; + break; + case '\\': + switch (*(s + 1)) { + case '\0': + break; + case '\n': + ++s; + continue; + default: + ++s; + break; + } + /* FALLTHROUGH */ + default: + if (word == NULL) + word = t; + *t++ = *s; + break; + } + break; + + /* Single-quoted */ + case 1: + switch (*s) { + case '\'': + quoted = 0; + break; + default: + *t++ = *s; + break; + } + break; + + /* Double-quoted */ + case 2: + switch (*s) { + case '"': + quoted = 0; + break; + case '\\': + switch (*(s + 1)) { + case '\0': + break; + case '$': + case '`': + case '"': + case '\\': + ++s; + break; + case '\n': + ++s; + continue; + default: + break; + } + /* FALLTHROUGH */ + default: + *t++ = *s; + break; + } + break; + } + } + if (quoted) + errx(1, "RPCGEN_CPP: unterminated %c", + quoted == 1 ? '\'' : '"'); + if (word != NULL) { + *t++ = '\0'; + insarg(idx++, word); } free(dupvar); }