From ff64806ae51c2813f0c6334c0c52082b027c255c Mon Sep 17 00:00:00 2001 From: Anastasia Belova Date: Tue, 28 Jan 2025 15:08:54 +0300 Subject: [PATCH] Fix possible dereference of NULL In some places in compile.c (for example in compile_builtin_arg) ERROR_ARGS macro is used while node = NULL. This macro uses nd_line which dereferences node. Add check for NULL to prevent such errors. --- node.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.h b/node.h index dff7613936..bfc7493e50 100644 --- a/node.h +++ b/node.h @@ -74,7 +74,7 @@ RUBY_SYMBOL_EXPORT_END #define NODE_LSHIFT (NODE_TYPESHIFT+7) #define NODE_LMASK (((SIGNED_VALUE)1<<(sizeof(VALUE)*CHAR_BIT-NODE_LSHIFT))-1) -#define nd_line(n) (int)(((SIGNED_VALUE)(n)->flags)>>NODE_LSHIFT) +#define nd_line(n) (int)((n) ? ((SIGNED_VALUE)(n)->flags)>>NODE_LSHIFT : -1) #define nd_set_line(n,l) \ (n)->flags=(((n)->flags&~((VALUE)(-1)<