blob: c0adef6f2fe37670c5541f87e225315215150e5a [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001
2Prevent a segmentation fault which occurs when using incorrect
3structure trying to access name of some named operators, such as
4CPP_NOT, CPP_AND etc. "token->val.node.spelling" cannot be used in
5those cases, as is may not be initialized at all.
6
7
8[YOCTO #11738]
9
10Upstream-Status: Pending
11
12Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
13
14diff --git a/libcpp/lex.c b/libcpp/lex.c
15--- a/libcpp/lex.c
16+++ b/libcpp/lex.c
17@@ -3229,11 +3229,27 @@
18 spell_ident:
19 case SPELL_IDENT:
20 if (forstring)
21- {
22- memcpy (buffer, NODE_NAME (token->val.node.spelling),
23- NODE_LEN (token->val.node.spelling));
24- buffer += NODE_LEN (token->val.node.spelling);
25- }
26+ {
27+ if (token->type == CPP_NAME)
28+ {
29+ memcpy (buffer, NODE_NAME (token->val.node.spelling),
30+ NODE_LEN (token->val.node.spelling));
31+ buffer += NODE_LEN (token->val.node.spelling);
32+ break;
33+ }
34+ /* NAMED_OP, cannot use node.spelling */
35+ if (token->flags & NAMED_OP)
36+ {
37+ const char *str = cpp_named_operator2name (token->type);
38+ if (str)
39+ {
40+ size_t len = strlen(str);
41+ memcpy(buffer, str, len);
42+ buffer += len;
43+ }
44+ break;
45+ }
46+ }
47 else
48 buffer = _cpp_spell_ident_ucns (buffer, token->val.node.node);
49 break;