CVE-2017-7960.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. input: check end of input before reading a byte
  2. When reading bytes we weren't check that the index wasn't
  3. out of bound and this could produce an invalid read which
  4. could deal to a security bug.
  5. Upstream-Status: Backport[https://gitlab.gnome.org/GNOME/libcroco/
  6. commit/898e3a8c8c0314d2e6b106809a8e3e93cf9d4394]
  7. CVE: CVE-2017-7960
  8. Signed-off-by: Changqing Li <changqing.li@windriver.com>
  9. diff --git a/src/cr-input.c b/src/cr-input.c
  10. index 49000b1f5f07fe057135f1b8fc69bdcf9613e300..3b63a88ee3b1c56778e58172d147d958951bf099 100644
  11. --- a/src/cr-input.c
  12. +++ b/src/cr-input.c
  13. @@ -256,7 +256,7 @@ cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc)
  14. *we should free buf here because it's own by CRInput.
  15. *(see the last parameter of cr_input_new_from_buf().
  16. */
  17. - buf = NULL ;
  18. + buf = NULL;
  19. }
  20. cleanup:
  21. @@ -404,6 +404,8 @@ cr_input_get_nb_bytes_left (CRInput const * a_this)
  22. enum CRStatus
  23. cr_input_read_byte (CRInput * a_this, guchar * a_byte)
  24. {
  25. + gulong nb_bytes_left = 0;
  26. +
  27. g_return_val_if_fail (a_this && PRIVATE (a_this)
  28. && a_byte, CR_BAD_PARAM_ERROR);
  29. @@ -413,6 +415,12 @@ cr_input_read_byte (CRInput * a_this, guchar * a_byte)
  30. if (PRIVATE (a_this)->end_of_input == TRUE)
  31. return CR_END_OF_INPUT_ERROR;
  32. + nb_bytes_left = cr_input_get_nb_bytes_left (a_this);
  33. +
  34. + if (nb_bytes_left < 1) {
  35. + return CR_END_OF_INPUT_ERROR;
  36. + }
  37. +
  38. *a_byte = PRIVATE (a_this)->in_buf[PRIVATE (a_this)->next_byte_index];
  39. if (PRIVATE (a_this)->nb_bytes -
  40. @@ -477,7 +485,6 @@ cr_input_read_char (CRInput * a_this, guint32 * a_char)
  41. if (*a_char == '\n') {
  42. PRIVATE (a_this)->end_of_line = TRUE;
  43. }
  44. -
  45. }
  46. return status;