0004-For-hidden-operators-pass-a-name-object-to-error-han.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From 34a8c5aa987d4db5234172a62218b168371606b1 Mon Sep 17 00:00:00 2001
  2. From: Chris Liddell <chris.liddell@artifex.com>
  3. Date: Tue, 2 Oct 2018 16:02:58 +0100
  4. Subject: [PATCH 4/5] For hidden operators, pass a name object to error
  5. handler.
  6. In normal operation, Postscript error handlers are passed the object which
  7. triggered the error: this is invariably an operator object.
  8. The issue arises when an error is triggered by an operator which is for internal
  9. use only, and that operator is then passed to the error handler, meaning it
  10. becomes visible to the error handler code.
  11. By converting to a name object, the error message is still valid, but we no
  12. longer expose internal use only operators.
  13. The change in gs_dps1.ps is related to the above: previously an error in
  14. scheck would throw an error against .gcheck, but as .gcheck is now a hidden
  15. operator, it resulted in a name object being passed to the error handler. As
  16. scheck is a 'real' operator, it's better to use the real operator, rather than
  17. the name of an internal, hidden one.
  18. CVE: CVE-2018-17961
  19. Upstream-Status: Backport [git://git.ghostscript.com/ghostpdl.git]
  20. Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
  21. ---
  22. Resource/Init/gs_dps1.ps | 2 +-
  23. psi/interp.c | 33 ++++++++++++++++++++++++---------
  24. 2 files changed, 25 insertions(+), 10 deletions(-)
  25. diff --git a/Resource/Init/gs_dps1.ps b/Resource/Init/gs_dps1.ps
  26. index 1182f53..ec5db61 100644
  27. --- a/Resource/Init/gs_dps1.ps
  28. +++ b/Resource/Init/gs_dps1.ps
  29. @@ -21,7 +21,7 @@ level2dict begin
  30. % ------ Virtual memory ------ %
  31. /currentshared /.currentglobal load def
  32. -/scheck /.gcheck load def
  33. +/scheck {.gcheck} bind odef
  34. %****** FOLLOWING IS WRONG ******
  35. /shareddict currentdict /globaldict .knownget not { 20 dict } if def
  36. diff --git a/psi/interp.c b/psi/interp.c
  37. index cd894f9..b70769d 100644
  38. --- a/psi/interp.c
  39. +++ b/psi/interp.c
  40. @@ -678,6 +678,8 @@ again:
  41. epref = &doref;
  42. /* Push the error object on the operand stack if appropriate. */
  43. if (!GS_ERROR_IS_INTERRUPT(code)) {
  44. + byte buf[260], *bufptr;
  45. + uint rlen;
  46. /* Replace the error object if within an oparray or .errorexec. */
  47. osp++;
  48. if (osp >= ostop) {
  49. @@ -686,23 +688,36 @@ again:
  50. }
  51. *osp = *perror_object;
  52. errorexec_find(i_ctx_p, osp);
  53. - /* If using SAFER, hand a name object to the error handler, rather than the executable
  54. - * object/operator itself.
  55. - */
  56. - if (i_ctx_p->LockFilePermissions) {
  57. +
  58. + if (!r_has_type(osp, t_string) && !r_has_type(osp, t_name)) {
  59. code = obj_cvs(imemory, osp, buf + 2, 256, &rlen, (const byte **)&bufptr);
  60. if (code < 0) {
  61. const char *unknownstr = "--unknown--";
  62. rlen = strlen(unknownstr);
  63. memcpy(buf, unknownstr, rlen);
  64. + bufptr = buf;
  65. }
  66. else {
  67. - buf[0] = buf[1] = buf[rlen + 2] = buf[rlen + 3] = '-';
  68. - rlen += 4;
  69. + ref *tobj;
  70. + bufptr[rlen] = '\0';
  71. + /* Only pass a name object if the operator doesn't exist in systemdict
  72. + * i.e. it's an internal operator we have hidden
  73. + */
  74. + code = dict_find_string(systemdict, (const char *)bufptr, &tobj);
  75. + if (code < 0) {
  76. + buf[0] = buf[1] = buf[rlen + 2] = buf[rlen + 3] = '-';
  77. + rlen += 4;
  78. + bufptr = buf;
  79. + }
  80. + else {
  81. + bufptr = NULL;
  82. + }
  83. + }
  84. + if (bufptr) {
  85. + code = name_ref(imemory, buf, rlen, osp, 1);
  86. + if (code < 0)
  87. + make_null(osp);
  88. }
  89. - code = name_ref(imemory, buf, rlen, osp, 1);
  90. - if (code < 0)
  91. - make_null(osp);
  92. }
  93. }
  94. goto again;
  95. --
  96. 2.7.4