2
0

200-CVE-2019-6706.patch 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. From 89aee84cbc9224f638f3b7951b306d2ee8ecb71e Mon Sep 17 00:00:00 2001
  2. From: Roberto Ierusalimschy <[email protected]>
  3. Date: Wed, 27 Mar 2019 14:30:12 -0300
  4. Subject: [PATCH] Fixed bug in 'lua_upvaluejoin'
  5. Bug-fix: joining an upvalue with itself could cause a use-after-free
  6. crash.
  7. ---
  8. src/lapi.c | 12 +++++------
  9. 1 file changed, 41 insertions(+), 39 deletions(-)
  10. --- a/src/lapi.c
  11. +++ b/src/lapi.c
  12. @@ -1254,13 +1254,12 @@ LUA_API const char *lua_setupvalue (lua_
  13. }
  14. -static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) {
  15. +static UpVal **getupvalref (lua_State *L, int fidx, int n) {
  16. LClosure *f;
  17. StkId fi = index2addr(L, fidx);
  18. api_check(L, ttisLclosure(fi), "Lua function expected");
  19. f = clLvalue(fi);
  20. api_check(L, (1 <= n && n <= f->p->sizeupvalues), "invalid upvalue index");
  21. - if (pf) *pf = f;
  22. return &f->upvals[n - 1]; /* get its upvalue pointer */
  23. }
  24. @@ -1269,7 +1268,7 @@ LUA_API void *lua_upvalueid (lua_State *
  25. StkId fi = index2addr(L, fidx);
  26. switch (ttype(fi)) {
  27. case LUA_TLCL: { /* lua closure */
  28. - return *getupvalref(L, fidx, n, NULL);
  29. + return *getupvalref(L, fidx, n);
  30. }
  31. case LUA_TCCL: { /* C closure */
  32. CClosure *f = clCvalue(fi);
  33. @@ -1286,9 +1285,10 @@ LUA_API void *lua_upvalueid (lua_State *
  34. LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1,
  35. int fidx2, int n2) {
  36. - LClosure *f1;
  37. - UpVal **up1 = getupvalref(L, fidx1, n1, &f1);
  38. - UpVal **up2 = getupvalref(L, fidx2, n2, NULL);
  39. + UpVal **up1 = getupvalref(L, fidx1, n1);
  40. + UpVal **up2 = getupvalref(L, fidx2, n2);
  41. + if (*up1 == *up2)
  42. + return;
  43. luaC_upvdeccount(L, *up1);
  44. *up1 = *up2;
  45. (*up1)->refcount++;