lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250113150253.3097820-8-masahiroy@kernel.org>
Date: Tue, 14 Jan 2025 00:00:45 +0900
From: Masahiro Yamada <masahiroy@...nel.org>
To: linux-kbuild@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
	Masahiro Yamada <masahiroy@...nel.org>
Subject: [PATCH 07/17] genksyms: restrict direct-abstract-declarator to take one parameter-type-list

While there is no more grammatical ambiguity in genksyms, the parser
logic is still inaccurate.

For example, genksyms accepts the following invalid C code:

    void my_func(int ()(int));

This should result in a syntax error because () cannot be reduced to
<direct-abstract-declarator>.

( <abstract-declarator> ) can be reduced, but <abstract-declarator>
must not be empty in the following grammar from K&R [1]:

  <direct-abstract-declarator> ::=  ( <abstract-declarator> )
                                 | {<direct-abstract-declarator>}? [ {<constant-expression>}? ]
                                 | {<direct-abstract-declarator>}? ( {<parameter-type-list>}? )

Furthermore, genksyms accepts the following weird code:

    void my_func(int (*callback)(int)(int)(int));

The parser allows <direct-abstract-declarator> to recursively absorb
multiple ( {<parameter-type-list>}? ), but this behavior is incorrect.

In the example above, (*callback) should be followed by at most one
(int).

[1]: https://cs.wmich.edu/~gupta/teaching/cs4850/sumII06/The%20syntax%20of%20C%20in%20Backus-Naur%20form.htm

Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
---

 scripts/genksyms/parse.y | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/scripts/genksyms/parse.y b/scripts/genksyms/parse.y
index fafce939c32f..03cdd8d53c13 100644
--- a/scripts/genksyms/parse.y
+++ b/scripts/genksyms/parse.y
@@ -381,20 +381,24 @@ abstract_declarator:
 	;
 
 direct_abstract_declarator:
+	direct_abstract_declarator1
+	| direct_abstract_declarator1 open_paren parameter_declaration_clause ')'
+		{ $$ = $4; }
+	| open_paren parameter_declaration_clause ')'
+		{ $$ = $3; }
+	;
+
+direct_abstract_declarator1:
 	  IDENT
 		{ /* For version 2 checksums, we don't want to remember
 		     private parameter names.  */
 		  remove_node($1);
 		  $$ = $1;
 		}
-	| direct_abstract_declarator open_paren parameter_declaration_clause ')'
+	| direct_abstract_declarator1 open_paren error ')'
 		{ $$ = $4; }
-	| direct_abstract_declarator open_paren error ')'
-		{ $$ = $4; }
-	| direct_abstract_declarator BRACKET_PHRASE
+	| direct_abstract_declarator1 BRACKET_PHRASE
 		{ $$ = $2; }
-	| open_paren parameter_declaration_clause ')'
-		{ $$ = $3; }
 	| open_paren abstract_declarator ')'
 		{ $$ = $3; }
 	| open_paren error ')'
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ