Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 1 | From aaa896a57b0004a74c1d474e74b21f41147a65cb Mon Sep 17 00:00:00 2001 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | From: Juro Bystricky <juro.bystricky@intel.com> |
| 3 | Date: Mon, 19 Mar 2018 22:31:20 -0700 |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 4 | Subject: [PATCH 34/36] fix segmentation fault in precompiled header generation |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 5 | |
| 6 | Prevent a segmentation fault which occurs when using incorrect |
| 7 | structure trying to access name of some named operators, such as |
| 8 | CPP_NOT, CPP_AND etc. "token->val.node.spelling" cannot be used in |
| 9 | those cases, as is may not be initialized at all. |
| 10 | |
| 11 | [YOCTO #11738] |
| 12 | |
| 13 | Upstream-Status: Pending |
| 14 | |
| 15 | Signed-off-by: Juro Bystricky <juro.bystricky@intel.com> |
| 16 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 17 | --- |
| 18 | libcpp/lex.c | 26 +++++++++++++++++++++----- |
| 19 | 1 file changed, 21 insertions(+), 5 deletions(-) |
| 20 | |
| 21 | diff --git a/libcpp/lex.c b/libcpp/lex.c |
| 22 | index eedfcbb3146..15040a1b1f0 100644 |
| 23 | --- a/libcpp/lex.c |
| 24 | +++ b/libcpp/lex.c |
| 25 | @@ -3280,11 +3280,27 @@ cpp_spell_token (cpp_reader *pfile, const cpp_token *token, |
| 26 | spell_ident: |
| 27 | case SPELL_IDENT: |
| 28 | if (forstring) |
| 29 | - { |
| 30 | - memcpy (buffer, NODE_NAME (token->val.node.spelling), |
| 31 | - NODE_LEN (token->val.node.spelling)); |
| 32 | - buffer += NODE_LEN (token->val.node.spelling); |
| 33 | - } |
| 34 | + { |
| 35 | + if (token->type == CPP_NAME) |
| 36 | + { |
| 37 | + memcpy (buffer, NODE_NAME (token->val.node.spelling), |
| 38 | + NODE_LEN (token->val.node.spelling)); |
| 39 | + buffer += NODE_LEN (token->val.node.spelling); |
| 40 | + break; |
| 41 | + } |
| 42 | + /* NAMED_OP, cannot use node.spelling */ |
| 43 | + if (token->flags & NAMED_OP) |
| 44 | + { |
| 45 | + const char *str = cpp_named_operator2name (token->type); |
| 46 | + if (str) |
| 47 | + { |
| 48 | + size_t len = strlen(str); |
| 49 | + memcpy(buffer, str, len); |
| 50 | + buffer += len; |
| 51 | + } |
| 52 | + break; |
| 53 | + } |
| 54 | + } |
| 55 | else |
| 56 | buffer = _cpp_spell_ident_ucns (buffer, token->val.node.node); |
| 57 | break; |
| 58 | -- |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 59 | 2.22.1 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 60 | |