CVE-2016-6255.patch 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. From be0a01bdb83395d9f3a5ea09c1308a4f1a972cbd Mon Sep 17 00:00:00 2001
  2. From: Matthew Garrett <mjg59@srcf.ucam.org>
  3. Date: Tue, 23 Feb 2016 13:53:20 -0800
  4. Subject: [PATCH] Don't allow unhandled POSTs to write to the filesystem by
  5. default
  6. If there's no registered handler for a POST request, the default behaviour
  7. is to write it to the filesystem. Several million deployed devices appear
  8. to have this behaviour, making it possible to (at least) store arbitrary
  9. data on them. Add a configure option that enables this behaviour, and change
  10. the default to just drop POSTs that aren't directly handled.
  11. ---
  12. configure.ac | 4 ++++
  13. upnp/inc/upnpconfig.h.in | 5 +++++
  14. upnp/src/genlib/net/http/webserver.c | 4 ++++
  15. 3 files changed, 13 insertions(+)
  16. diff --git a/configure.ac b/configure.ac
  17. index dd88734..ea2bc09 100644
  18. --- a/configure.ac
  19. +++ b/configure.ac
  20. @@ -482,6 +482,10 @@ if test "x$enable_scriptsupport" = xyes ; then
  21. AC_DEFINE(IXML_HAVE_SCRIPTSUPPORT, 1, [see upnpconfig.h])
  22. fi
  23. +RT_BOOL_ARG_ENABLE([postwrite], [no], [write to the filesystem on otherwise unhandled POST requests])
  24. +if test "x$enable_postwrite" = xyes ; then
  25. + AC_DEFINE(UPNP_ENABLE_POST_WRITE, 1, [see upnpconfig.h])
  26. +fi
  27. RT_BOOL_ARG_ENABLE([samples], [yes], [compilation of upnp/sample/ code])
  28. diff --git a/upnp/inc/upnpconfig.h.in b/upnp/inc/upnpconfig.h.in
  29. index 46ddc6e..5df8c5a 100644
  30. --- a/upnp/inc/upnpconfig.h.in
  31. +++ b/upnp/inc/upnpconfig.h.in
  32. @@ -135,5 +135,10 @@
  33. * (i.e. configure --enable-open_ssl) */
  34. #undef UPNP_ENABLE_OPEN_SSL
  35. +/** Defined to 1 if the library has been compiled to support filesystem writes on POST
  36. + * (i.e. configure --enable-postwrite) */
  37. +#undef UPNP_ENABLE_POST_WRITE
  38. +
  39. +
  40. #endif /* UPNP_CONFIG_H */
  41. diff --git a/upnp/src/genlib/net/http/webserver.c b/upnp/src/genlib/net/http/webserver.c
  42. index 8991c16..8b2ecf2 100644
  43. --- a/upnp/src/genlib/net/http/webserver.c
  44. +++ b/upnp/src/genlib/net/http/webserver.c
  45. @@ -1369,9 +1369,13 @@ static int http_RecvPostMessage(
  46. if (Fp == NULL)
  47. return HTTP_INTERNAL_SERVER_ERROR;
  48. } else {
  49. +#ifdef UPNP_ENABLE_POST_WRITE
  50. Fp = fopen(filename, "wb");
  51. if (Fp == NULL)
  52. return HTTP_UNAUTHORIZED;
  53. +#else
  54. + return HTTP_NOT_FOUND;
  55. +#endif
  56. }
  57. parser->position = POS_ENTITY;
  58. do {