Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix null pointer dereference on in...



details:   https://anonhg.NetBSD.org/src/rev/2b5204f3e384
branches:  trunk
changeset: 373138:2b5204f3e384
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jan 21 08:04:43 2023 +0000

description:
lint: fix null pointer dereference on invalid argument to __typeof__

diffstat:

 tests/usr.bin/xlint/lint1/gcc_typeof.c |  15 ++++++++++++++-
 usr.bin/xlint/lint1/cgram.y            |   6 +++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diffs (54 lines):

diff -r 9cedae37380c -r 2b5204f3e384 tests/usr.bin/xlint/lint1/gcc_typeof.c
--- a/tests/usr.bin/xlint/lint1/gcc_typeof.c    Sat Jan 21 04:04:30 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/gcc_typeof.c    Sat Jan 21 08:04:43 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gcc_typeof.c,v 1.4 2022/04/10 12:14:10 rillig Exp $    */
+/*     $NetBSD: gcc_typeof.c,v 1.5 2023/01/21 08:04:43 rillig Exp $    */
 # 3 "gcc_typeof.c"
 
 /*
@@ -41,3 +41,16 @@
  */
 int *volatile lock;
 const volatile __typeof__(lock) *lock_pointer = &lock;
+
+/*
+ * Before cgram.y 1.427 from 2023-01-21, lint crashed due to a null pointer
+ * dereference if the __typeof__ operator had an invalid argument.  Seen in
+ * _fc_atomic_ptr_cmpexch from fontconfig, which uses <stdatomic.h> provided
+ * by GCC, which in turn uses __auto_type and __typeof__, and lint doesn't
+ * know about __auto_type.
+ */
+void _fc_atomic_ptr_cmpexch(void)
+{
+       /* expect+1: error: 'expr' undefined [99] */
+       __typeof__ (expr) var = 0;
+}
diff -r 9cedae37380c -r 2b5204f3e384 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jan 21 04:04:30 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jan 21 08:04:43 2023 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.426 2023/01/15 00:05:38 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.427 2023/01/21 08:04:43 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.426 2023/01/15 00:05:38 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.427 2023/01/21 08:04:43 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -850,7 +850,7 @@
                $$ = gettyp($1);
          }
        | T_TYPEOF T_LPAREN expression T_RPAREN {       /* GCC extension */
-               $$ = block_dup_type($3->tn_type);
+               $$ = $3 != NULL ? block_dup_type($3->tn_type) : gettyp(INT);
                $$->t_typeof = true;
          }
        | struct_or_union_specifier {



Home | Main Index | Thread Index | Old Index