0031-fix-segmentation-fault-in-precompiled-header-generat.patch 1.9 KB

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