libproxy-0.4.15-mozjs-use-after-free.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. From 738785214546ec5bb772886019529b2a6519deaf Mon Sep 17 00:00:00 2001
  2. From: Simon McVittie <smcv@debian.org>
  3. Date: Fri, 1 May 2020 19:04:22 +0100
  4. Subject: [PATCH] mozjs: Avoid use-after-free
  5. If we don't assign the temporary std::string returned by
  6. url_.to_string() to a variable, then it immediately goes out of scope
  7. and is freed, resulting in the result of c_str() pointing into freed
  8. memory. This works about as well as you would expect.
  9. Signed-off-by: Simon McVittie <smcv@debian.org>
  10. ---
  11. libproxy/modules/pacrunner_mozjs.cpp | 11 ++++-------
  12. 1 file changed, 4 insertions(+), 7 deletions(-)
  13. diff --git a/libproxy/modules/pacrunner_mozjs.cpp b/libproxy/modules/pacrunner_mozjs.cpp
  14. index ade6d0a..aac6531 100644
  15. --- a/libproxy/modules/pacrunner_mozjs.cpp
  16. +++ b/libproxy/modules/pacrunner_mozjs.cpp
  17. @@ -175,14 +175,11 @@ class mozjs_pacrunner : public pacrunner {
  18. string run(const url& url_) throw (bad_alloc) {
  19. // Build arguments to the FindProxyForURL() function
  20. - const char *tmpurl = url_.to_string().c_str();
  21. - const char *tmphost = url_.get_host().c_str();
  22. - if (!tmpurl || !tmphost) {
  23. - throw bad_alloc();
  24. - }
  25. + string tmpurl(url_.to_string());
  26. + string tmphost(url_.get_host());
  27. JS::AutoValueArray<2> args(this->jsctx);
  28. - args[0].setString(JS_NewStringCopyZ(this->jsctx, tmpurl));
  29. - args[1].setString(JS_NewStringCopyZ(this->jsctx, tmphost));
  30. + args[0].setString(JS_NewStringCopyZ(this->jsctx, tmpurl.c_str()));
  31. + args[1].setString(JS_NewStringCopyZ(this->jsctx, tmphost.c_str()));
  32. // Find the proxy (call FindProxyForURL())
  33. JS::RootedValue rval(this->jsctx);