summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc/0031-fix-segmentation-fault-in-precompiled-header-generat.patch
blob: 0b93a055c2226d098ea8d39d0ea5c4278c9dc8d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From d3b25e66c7f9c86b5da0fd3e9e6236e0b59dc934 Mon Sep 17 00:00:00 2001
From: Juro Bystricky <juro.bystricky@intel.com>
Date: Mon, 19 Mar 2018 22:31:20 -0700
Subject: [PATCH] fix segmentation fault in precompiled header generation

Prevent a segmentation fault which occurs when using incorrect
structure trying to access name of some named operators, such as
CPP_NOT, CPP_AND etc. "token->val.node.spelling" cannot be used in
those cases, as is may not be initialized at all.

[YOCTO #11738]

Upstream-Status: Pending

Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 libcpp/lex.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/libcpp/lex.c b/libcpp/lex.c
index 665297af776..0ac5d67ddf0 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -3311,11 +3311,27 @@ cpp_spell_token (cpp_reader *pfile, const cpp_token *token,
     spell_ident:
     case SPELL_IDENT:
       if (forstring)
-	{
-	  memcpy (buffer, NODE_NAME (token->val.node.spelling),
-		  NODE_LEN (token->val.node.spelling));
-	  buffer += NODE_LEN (token->val.node.spelling);
-	}
+        {
+          if (token->type == CPP_NAME)
+            {
+              memcpy (buffer, NODE_NAME (token->val.node.spelling),
+                    NODE_LEN (token->val.node.spelling));
+              buffer += NODE_LEN (token->val.node.spelling);
+              break;
+            }
+          /* NAMED_OP, cannot use node.spelling */
+          if (token->flags & NAMED_OP)
+            {
+              const char *str = cpp_named_operator2name (token->type);
+              if (str)
+                {
+                  size_t len = strlen(str);
+                  memcpy(buffer, str, len);
+                  buffer += len;
+                }
+              break;
+            }
+        }
       else
 	buffer = _cpp_spell_ident_ucns (buffer, token->val.node.node);
       break;