bugs 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. --[=[
  2. ** lua.stx / llex.c
  3. Tue Dec 2 10:45:48 EDT 1997
  4. >> BUG: "lastline" was not reset on function entry, so debug information
  5. >> started only in the 2nd line of a function.
  6. =================================================================
  7. --- Version 3.1 alpha
  8. ** lua.c
  9. Thu Jan 15 14:34:58 EDT 1998
  10. >> must include "stdlib.h" (for "exit()").
  11. ** lbuiltin.c / lobject.h
  12. Thu Jan 15 14:34:58 EDT 1998
  13. >> MAX_WORD may be bigger than MAX_INT
  14. (by lhf)
  15. ** llex.c
  16. Mon Jan 19 18:17:18 EDT 1998
  17. >> wrong line number (+1) in error report when file starts with "#..."
  18. ** lstrlib.c
  19. Tue Jan 27 15:27:49 EDT 1998
  20. >> formats like "%020d" were considered too big (3 digits); moreover,
  21. >> some sistems limit printf to at most 500 chars, so we can limit sizes
  22. >> to 2 digits (99).
  23. ** lapi.c
  24. Tue Jan 27 17:12:36 EDT 1998
  25. >> "lua_getstring" may create a new string, so should check GC
  26. ** lstring.c / ltable.c
  27. Wed Jan 28 14:48:12 EDT 1998
  28. >> tables can become full of "empty" slots, and keep growing without limits.
  29. ** lstrlib.c
  30. Mon Mar 9 15:26:09 EST 1998
  31. >> gsub('a', '(b?)%1*' ...) loops (because the capture is empty).
  32. ** lstrlib.c
  33. Mon May 18 19:20:00 EST 1998
  34. >> arguments for "format" 'x', 'X', 'o' and 'u' must be unsigned int.
  35. =================================================================
  36. --- Version 3.1
  37. ** liolib.c / lauxlib.c
  38. Mon Sep 7 15:57:02 EST 1998
  39. >> function "luaL_argerror" prints wrong argument number (from a user's point
  40. of view) when functions have upvalues.
  41. ** lstrlib.c
  42. Tue Nov 10 17:29:36 EDT 1998
  43. >> gsub/strfind do not check whether captures are properly finished.
  44. (by roberto/tomas)
  45. ** lbuiltin.c
  46. Fri Dec 18 11:22:55 EDT 1998
  47. >> "tonumber" goes crazy with negative numbers in other bases (not 10),
  48. because "strtol" returns long, not unsigned long.
  49. (by Visual C++)
  50. ** lstrlib.c
  51. Mon Jan 4 10:41:40 EDT 1999
  52. >> "format" does not check size of format item (such as "%00000...00000d").
  53. ** lapi.c
  54. Wed Feb 3 14:40:21 EDT 1999
  55. >> getlocal cannot return the local itself, since lua_isstring and
  56. lua_isnumber can modify it.
  57. ** lstrlib.c
  58. Thu Feb 4 17:08:50 EDT 1999
  59. >> format "%s" may break limit of "sprintf" on some machines.
  60. (by Marcelo Sales)
  61. ** lzio.c
  62. Thu Mar 4 11:49:37 EST 1999
  63. >> file stream cannot call fread after EOF.
  64. (by lhf)
  65. =================================================================
  66. --- Version 3.2 (beta)
  67. ** lstrlib.c
  68. Fri Apr 30 11:10:20 EST 1999
  69. >> '$' at end of pattern was matching regular '$', too.
  70. (by anna; since 2.5)
  71. ** lbuiltin.c
  72. Fri May 21 17:15:11 EST 1999
  73. >> foreach, foreachi, foreachvar points to function in stack when stack
  74. can be reallocated.
  75. (by tomas; since 3.2 beta)
  76. ** lparser.c
  77. Wed Jun 16 10:32:46 EST 1999
  78. >> cannot assign to unlimited variables, because it causes overflow in
  79. the number of returns of a function.
  80. (since 3.1)
  81. =================================================================
  82. --- Version 3.2
  83. ** lmathlib.c
  84. Wed Aug 18 11:28:38 EST 1999
  85. >> random(0) and random(x,0) are wrong (0 is read as no argument!).
  86. (by Dave Bollinger; since 3.1)
  87. ** lparser.c
  88. Thu Sep 2 10:07:20 EST 1999
  89. >> in the (old) expression << ls->fs->f->consts[checkname(ls)] >>, checkname
  90. could realloc f->consts.
  91. (by Supratik Champati; since 3.2 beta)
  92. ** lobject.c / lbuiltin.c
  93. Wed Sep 8 17:41:54 EST 1999
  94. >> tonumber'e1' and tonumber(' ', x), for x!=10, gave 0 instead of nil.
  95. (since 3.1)
  96. ** lstrlib.c
  97. Thu Nov 11 14:36:30 EDT 1999
  98. >> `strfind' does not handle \0 in plain search.
  99. (by Jon Kleiser; since 3.1)
  100. ** lparser.c
  101. Wed Dec 29 16:05:43 EDT 1999
  102. >> return gives wrong line in debug information
  103. (by lhf; since 3.2 [at least])
  104. ** ldo.c
  105. Thu Dec 30 16:39:33 EDT 1999
  106. >> cannot reopen stdin (for binary mode)
  107. (by lhf & roberto; since 3.1)
  108. ** lapi.c
  109. Thu Mar 2 09:41:53 EST 2000
  110. >> lua_settable should check stack space (it could call a T.M.)
  111. (by lhf & celes; since 3.2; it was already fixed by fixed stack)
  112. ** lparser.c
  113. Mon Apr 3 09:59:06 EST 2000
  114. >> '%' should be in expfollow
  115. (by Edgar Toernig; since 3.1; it was already fixed)
  116. ** lbuiltin.c
  117. Mon Apr 3 10:05:05 EST 2000
  118. >> tostring() without arguments gives seg. fault.
  119. (by Edgar Toernig; since 3.0)
  120. =================================================================
  121. --- Version 4.0 alpha
  122. Tested with full test suites (as locked in Mon Apr 24 14:23:11 EST 2000)
  123. in the following platforms:
  124. * Linux - gcc, g++
  125. * AIX - gcc
  126. * Solaris - gcc, cc
  127. * IRIX - cc, cc-purify
  128. * Windows - Visual C++ (.c e .cpp, warning level=4)
  129. ** lstrlib.c
  130. Tue May 2 15:27:58 EST 2000
  131. >> `strfind' gets wrong subject length when there is an offset
  132. (by Jon Kleiser; since 4.0a)
  133. ** lparser.c
  134. Fri May 12 15:11:12 EST 2000
  135. >> first element in a list constructor is not adjusted to one value
  136. >> (e.g. «a = {gsub('a','a','')}»)
  137. (by Tomas; since 4.0a)
  138. ** lparser.c
  139. Wed May 24 14:50:16 EST 2000
  140. >> record-constructor starting with an upvalue name gets an error
  141. >> (e.g. «local a; function f() x = {a=1} end»)
  142. (by Edgar Toernig; since 3.1)
  143. ** lparser.c
  144. Tue Aug 29 15:56:05 EST 2000
  145. >> error message for `for' uses `while'
  146. (since 4.0a; already corrected)
  147. ** lgc.c
  148. Tue Aug 29 15:57:41 EST 2000
  149. >> gc tag method for nil could call line hook
  150. (by ry; since ?)
  151. =================================================================
  152. --- Version 4.0 Beta
  153. ** liolib.c
  154. Fri Sep 22 15:12:37 EST 2000
  155. >> `read("*w")' should return nil at EOF
  156. (by roberto; since 4.0b)
  157. ** lvm.c
  158. Mon Sep 25 11:47:48 EST 2000
  159. >> lua_gettable does not get key from stack top
  160. (by Philip Yi; since 4.0b)
  161. ** lgc.c
  162. Mon Sep 25 11:50:48 EST 2000
  163. >> GC may crash when checking locked C closures
  164. (by Philip Yi; since 4.0b)
  165. ** lapi.c
  166. Wed Sep 27 09:50:19 EST 2000
  167. >> lua_tag should return LUA_NOTAG for non-valid indices
  168. (by Paul Hankin; since 4.0b)
  169. ** llex.h / llex.c / lparser.c
  170. Wed Sep 27 13:39:45 EST 2000
  171. >> parser overwrites semantic information when looking ahead
  172. >> (e.g. «a = {print'foo'}»)
  173. (by Edgar Toernig; since 4.0b, deriving from previous bug)
  174. ** liolib.c
  175. Thu Oct 26 10:50:46 EDT 2000
  176. >> in function `read_file', realloc() doesn't free the buffer if it can't
  177. >> allocate new memory
  178. (by Mauro Vezzosi; since 4.0b)
  179. =================================================================
  180. --- Version 4.0
  181. ** lparser.c
  182. Wed Nov 29 09:51:44 EDT 2000
  183. >> parser does not accept a `;' after a `return'
  184. (by lhf; since 4.0b)
  185. ** liolib.c
  186. Fri Dec 22 15:30:42 EDT 2000
  187. >> when `read' fails it must return nil (and not no value)
  188. (by cassino; since at least 3.1)
  189. ** lstring.c/lapi.c
  190. Thu Feb 1 11:55:45 EDT 2001
  191. >> lua_pushuserdata(L, NULL) is buggy
  192. (by Edgar Toernig; since 4.0)
  193. ** ldo.c
  194. Fri Feb 2 14:06:40 EDT 2001
  195. >> «while 1 dostring[[print('hello\n')]] end» never reclaims memory
  196. (by Andrew Paton; since 4.0b)
  197. ** lbaselib.c
  198. Tue Feb 6 11:57:13 EDT 2001
  199. >> ESC (which starts precompiled code) in C is \33, not \27
  200. (by Edgar Toernig and lhf; since 4.0b)
  201. ** lparser.c
  202. Tue Jul 10 16:59:18 EST 2001
  203. >> error message for `%a' gave wrong line number
  204. (by Leonardo Constantino; since 4.0)
  205. ** lbaselib.c
  206. Fri Dec 21 15:21:05 EDT 2001
  207. >> seg. fault when rawget/rawset get extra arguments
  208. (by Eric Mauger; since 4.0b)
  209. ** lvm.c
  210. Wed Jun 19 13:28:20 EST 2002
  211. >> line hook gets wrong `ar'
  212. (by Daniel C. Sinclair; since 4.0.b)
  213. ** ldo.c
  214. Wed Jun 19 13:31:49 EST 2002
  215. >> `protectedparser' may run GC, and then collect `filename'
  216. >> (in function `parse_file')
  217. (by Alex Bilyk; since 4.0)
  218. =================================================================
  219. --- Version 5.0 alpha
  220. ** lgc.c
  221. Fri Aug 30 13:49:14 EST 2002
  222. >> GC metamethod stored in a weak metatable being collected together with
  223. >> userdata may not be cleared properly
  224. (by Roberto; since 5.0a)
  225. ** lapi.c
  226. Thu Nov 21 11:00:00 EST 2002
  227. >> ULONG_MAX>>10 may not fit into an int
  228. (by Jeff Petkau; since 4.0)
  229. ** lparser.c
  230. Fri Dec 6 17:06:40 UTC 2002
  231. >> scope of generic for variables is not sound
  232. (by Gavin Wraith; since 5.0a)
  233. =================================================================
  234. --- Version 5.0 beta
  235. ** lbaselib.c
  236. Fri Dec 20 09:53:19 UTC 2002
  237. >> `resume' was checking the wrong value for stack overflow
  238. (by Maik Zimmermann; since 5.0b)
  239. ** ldo.c
  240. Thu Jan 23 11:29:06 UTC 2003
  241. >> error during garbage collection in luaD_protectedparser is not being
  242. >> protected
  243. (by Benoit Germain; since 5.0a)
  244. ** ldo.c (and others)
  245. Fri Feb 28 14:20:33 EST 2003
  246. >> GC metamethod calls could mess C/Lua stack syncronization
  247. (by Roberto; since 5.0b)
  248. ** lzio.h/zlio.c
  249. Thu Mar 20 11:40:12 EST 2003
  250. >> zio mixes a 255 as first char in a buffer with EOZ
  251. (by lhf; since 5.0a)
  252. --]=]
  253. -----------------------------------------------------------------
  254. -- Lua 5.0 (final)
  255. Bug{
  256. what = [[lua_closethread exists only in the manual]],
  257. report = [[by Nguyen Binh, 28/04/2003]],
  258. patch = [[no patch; the manual is wrong]],
  259. }
  260. Bug{
  261. what = [[attempt to resume a running coroutine crashes Lua]],
  262. example = [[
  263. function co_func (current_co)
  264. coroutine.resume(co)
  265. end
  266. co = coroutine.create(co_func)
  267. coroutine.resume(co)
  268. coroutine.resume(co) --> seg. fault
  269. ]],
  270. report = [[by Alex Bilyk, 09/05/2003]],
  271. patch = [[
  272. * ldo.c:
  273. 325,326c325
  274. < if (nargs >= L->top - L->base)
  275. < luaG_runerror(L, "cannot resume dead coroutine");
  276. ---
  277. > lua_assert(nargs < L->top - L->base);
  278. 329c328,329
  279. < else if (ci->state & CI_YIELD) { /* inside a yield? */
  280. ---
  281. > else { /* inside a yield */
  282. > lua_assert(ci->state & CI_YIELD);
  283. 344,345d343
  284. < else
  285. < luaG_runerror(L, "cannot resume non-suspended coroutine");
  286. 351a350,358
  287. > static int resume_error (lua_State *L, const char *msg) {
  288. > L->top = L->ci->base;
  289. > setsvalue2s(L->top, luaS_new(L, msg));
  290. > incr_top(L);
  291. > lua_unlock(L);
  292. > return LUA_ERRRUN;
  293. > }
  294. >
  295. >
  296. 355a363,368
  297. > if (L->ci == L->base_ci) {
  298. > if (nargs >= L->top - L->base)
  299. > return resume_error(L, "cannot resume dead coroutine");
  300. > }
  301. > else if (!(L->ci->state & CI_YIELD)) /* not inside a yield? */
  302. > return resume_error(L, "cannot resume non-suspended coroutine");
  303. ]],
  304. }
  305. Bug{
  306. what = [[file:close cannot be called without a file. (results in seg fault)]],
  307. example = [[
  308. > io.stdin.close() -- correct call shold be io.stdin:close()
  309. ]],
  310. report = [[by Tuomo Valkonen, 27/05/2003]],
  311. patch = [[
  312. * liolib.c:
  313. 161c161
  314. < if (lua_isnone(L, 1)) {
  315. ---
  316. > if (lua_isnone(L, 1) && lua_type(L, lua_upvalueindex(1)) == LUA_TTABLE) {
  317. ]], --}}
  318. }
  319. Bug{
  320. what = [[C functions also may have stacks larger than current top]],
  321. example = [[
  322. Must recompile lua with a change in lua.c and with lua_assert defined:
  323. * lua.c:
  324. 381a382
  325. > lua_checkstack(l, 1000);
  326. ]],
  327. report = [[Alex Bilyk, 09/06/2003]],
  328. patch = [[
  329. * lgc.c:
  330. 247c247
  331. < if (!(ci->state & CI_C) && lim < ci->top)
  332. ---
  333. > if (lim < ci->top)
  334. ]],
  335. }
  336. Bug{
  337. what = [[`pc' address is invalidated when a coroutine is suspended]],
  338. example = [[
  339. function g(x)
  340. coroutine.yield(x)
  341. end
  342. function f (i)
  343. debug.sethook(print, "l")
  344. for j=1,1000 do
  345. g(i+j)
  346. end
  347. end
  348. co = coroutine.wrap(f)
  349. co(10)
  350. pcall(co)
  351. pcall(co)
  352. ]],
  353. report = [[Nick Trout, 07/07/2003]],
  354. patch = [[
  355. * lvm.c:
  356. 402,403c402,403
  357. < L->ci->u.l.pc = &pc;
  358. < if (L->hookmask & LUA_MASKCALL)
  359. ---
  360. > if (L->hookmask & LUA_MASKCALL) {
  361. > L->ci->u.l.pc = &pc;
  362. 404a405
  363. > }
  364. 405a407
  365. > L->ci->u.l.pc = &pc;
  366. 676,678c678
  367. < lua_assert(ci->u.l.pc == &pc &&
  368. < ttisfunction(ci->base - 1) &&
  369. < (ci->state & CI_SAVEDPC));
  370. ---
  371. > lua_assert(ttisfunction(ci->base - 1) && (ci->state & CI_SAVEDPC));
  372. ]]
  373. }
  374. Bug{
  375. what = [[userdata to be collected still counts into new GC threshold,
  376. increasing memory consumption]],
  377. report = [[Roberto, 25/07/2003]],
  378. example = [[
  379. a = newproxy(true)
  380. getmetatable(a).__gc = function () end
  381. for i=1,10000000 do
  382. newproxy(a)
  383. if math.mod(i, 10000) == 0 then print(gcinfo()) end
  384. end
  385. ]],
  386. patch = [[
  387. * lgc.h:
  388. 18c18
  389. < void luaC_separateudata (lua_State *L);
  390. ---
  391. > size_t luaC_separateudata (lua_State *L);
  392. * lgc.c:
  393. 113c113,114
  394. < void luaC_separateudata (lua_State *L) {
  395. ---
  396. > size_t luaC_separateudata (lua_State *L) {
  397. > size_t deadmem = 0;
  398. 127a129
  399. > deadmem += sizeudata(gcotou(curr)->uv.len);
  400. 136a139
  401. > return deadmem;
  402. 390c393
  403. < static void checkSizes (lua_State *L) {
  404. ---
  405. > static void checkSizes (lua_State *L, size_t deadmem) {
  406. 400c403
  407. < G(L)->GCthreshold = 2*G(L)->nblocks; /* new threshold */
  408. ---
  409. > G(L)->GCthreshold = 2*G(L)->nblocks - deadmem; /* new threshold */
  410. 454c457,458
  411. < static void mark (lua_State *L) {
  412. ---
  413. > static size_t mark (lua_State *L) {
  414. > size_t deadmem;
  415. 467c471
  416. < luaC_separateudata(L); /* separate userdata to be preserved */
  417. ---
  418. > deadmem = luaC_separateudata(L); /* separate userdata to be preserved */
  419. 475a480
  420. > return deadmem;
  421. 480c485
  422. < mark(L);
  423. ---
  424. > size_t deadmem = mark(L);
  425. 482c487
  426. < checkSizes(L);
  427. ---
  428. > checkSizes(L, deadmem);
  429. ]]
  430. }
  431. Bug{
  432. what=[[IBM AS400 (OS400) has sizeof(void *)==16, and a `%p' may generate
  433. up to 60 characters in a `printf'. That causes a buffer overflow in
  434. `tostring'.]],
  435. report = [[David Burgess, 25/08/2003]],
  436. example = [[print{}; (in an AS400 machine)]],
  437. patch = [[
  438. * liolib.c:
  439. 178c178
  440. < char buff[32];
  441. ---
  442. > char buff[128];
  443. * lbaselib.c:
  444. 327c327
  445. < char buff[64];
  446. ---
  447. > char buff[128];
  448. ]]
  449. }
  450. Bug{
  451. what = [[syntax `local function' does not increment stack size]],
  452. report = [[Rici Lake, 26/09/2003]],
  453. example = [[
  454. -- must run this with precompiled code
  455. local a,b,c
  456. local function d () end
  457. ]],
  458. patch = [[
  459. * lparser.c:
  460. 1143a1144
  461. > FuncState *fs = ls->fs;
  462. 1145c1146,1147
  463. < init_exp(&v, VLOCAL, ls->fs->freereg++);
  464. ---
  465. > init_exp(&v, VLOCAL, fs->freereg);
  466. > luaK_reserveregs(fs, 1);
  467. 1148c1150,1152
  468. < luaK_storevar(ls->fs, &v, &b);
  469. ---
  470. > luaK_storevar(fs, &v, &b);
  471. > /* debug information will only see the variable after this point! */
  472. > getlocvar(fs, fs->nactvar - 1).startpc = fs->pc;
  473. ]],
  474. }
  475. Bug{
  476. what = [[count hook may be called without being set]],
  477. report = [[Andreas Stenius, 06/10/2003]],
  478. example = [[
  479. set your hooks with
  480. lua_sethook(L, my_hook, LUA_MASKLINE | LUA_MASKRET, 1);
  481. (It is weird to use a count > 0 without setting the count hook,
  482. but it is not wrong.)
  483. ]],
  484. patch = [[
  485. * lvm.c:
  486. 69c69
  487. < if (mask > LUA_MASKLINE) { /* instruction-hook set? */
  488. ---
  489. > if (mask & LUA_MASKCOUNT) { /* instruction-hook set? */
  490. ]],
  491. }
  492. Bug{
  493. what = [[`dofile' eats one return value when called without arguments]],
  494. report = [[Frederico Abraham, 15/01/2004]],
  495. example = [[
  496. a,b = dofile() --< here you enter `return 1,2,3 <eof>'
  497. print(a,b) --> 2 3 (should be 1 and 2)
  498. ]],
  499. patch = [[
  500. * lbaselib.c:
  501. 313a314
  502. > int n = lua_gettop(L);
  503. 317c318
  504. < return lua_gettop(L) - 1;
  505. ---
  506. > return lua_gettop(L) - n;
  507. ]],
  508. }
  509. -----------------------------------------------------------------
  510. -- Lua 5.0.2
  511. Bug{
  512. what = [[string concatenation may cause arithmetic overflow, leading
  513. to a buffer overflow]],
  514. report = [[Rici Lake, 20/05/2004]],
  515. example = [[
  516. longs = string.rep("\0", 2^25)
  517. function catter(i)
  518. return assert(loadstring(
  519. string.format("return function(a) return a%s end",
  520. string.rep("..a", i-1))))()
  521. end
  522. rep129 = catter(129)
  523. rep129(longs)
  524. ]],
  525. patch = [[
  526. * lvm.c:
  527. @@ -321,15 +321,15 @@
  528. luaG_concaterror(L, top-2, top-1);
  529. } else if (tsvalue(top-1)->tsv.len > 0) { /* if len=0, do nothing */
  530. /* at least two string values; get as many as possible */
  531. - lu_mem tl = cast(lu_mem, tsvalue(top-1)->tsv.len) +
  532. - cast(lu_mem, tsvalue(top-2)->tsv.len);
  533. + size_t tl = tsvalue(top-1)->tsv.len;
  534. char *buffer;
  535. int i;
  536. - while (n < total && tostring(L, top-n-1)) { /* collect total length */
  537. - tl += tsvalue(top-n-1)->tsv.len;
  538. - n++;
  539. + /* collect total length */
  540. + for (n = 1; n < total && tostring(L, top-n-1); n++) {
  541. + size_t l = tsvalue(top-n-1)->tsv.len;
  542. + if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
  543. + tl += l;
  544. }
  545. - if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
  546. buffer = luaZ_openspace(L, &G(L)->buff, tl);
  547. tl = 0;
  548. for (i=n; i>0; i--) { /* concat all strings */
  549. ]]
  550. }
  551. Bug{
  552. what = [[lua_getupvalue and setupvalue do not check for index too small]],
  553. report = [[Mike Pall, ?/2004]],
  554. example = [[debug.getupvalue(function() end, 0)]],
  555. patch = [[
  556. * lapi.c
  557. 941c941
  558. < if (n > f->c.nupvalues) return NULL;
  559. ---
  560. > if (!(1 <= n && n <= f->c.nupvalues)) return NULL;
  561. 947c947
  562. < if (n > p->sizeupvalues) return NULL;
  563. ---
  564. > if (!(1 <= n && n <= p->sizeupvalues)) return NULL;
  565. ]]
  566. }
  567. Bug{
  568. what = [[values holded in open upvalues of suspended threads may be
  569. incorrectly collected]],
  570. report = [[Spencer Schumann, 31/12/2004]],
  571. example = [[
  572. local thread_id = 0
  573. local threads = {}
  574. function fn(thread)
  575. thread_id = thread_id + 1
  576. threads[thread_id] = function()
  577. thread = nil
  578. end
  579. coroutine.yield()
  580. end
  581. while true do
  582. local thread = coroutine.create(fn)
  583. coroutine.resume(thread, thread)
  584. end
  585. ]],
  586. patch = [[
  587. * lgc.c:
  588. 221,224c221,222
  589. < if (!u->marked) {
  590. < markobject(st, &u->value);
  591. < u->marked = 1;
  592. < }
  593. ---
  594. > markobject(st, u->v);
  595. > u->marked = 1;
  596. ]],
  597. }
  598. Bug{
  599. what = [[rawset/rawget do not ignore extra arguments]],
  600. report = [[Romulo Bahiense, 11/03/2005]],
  601. example = [[
  602. a = {}
  603. rawset(a, 1, 2, 3)
  604. print(a[1], a[2]) -- should be 2 and nil
  605. ]],
  606. patch = [[
  607. * lbaselib.c:
  608. 175a176
  609. > lua_settop(L, 2);
  610. 183a185
  611. > lua_settop(L, 3);
  612. ]],
  613. }
  614. Bug{
  615. what = [[weak tables that survive one collection are never collected]],
  616. report = [[Chromix, 02/01/2006]],
  617. example = [[
  618. a = {}
  619. print(gcinfo())
  620. for i = 1, 10000 do
  621. a[i] = setmetatable({}, {__mode = "v"})
  622. end
  623. collectgarbage()
  624. a = nil
  625. collectgarbage()
  626. print(gcinfo())
  627. ]],
  628. patch = [[
  629. * lgc.c
  630. @@ -366,7 +366,7 @@
  631. GCObject *curr;
  632. int count = 0; /* number of collected items */
  633. while ((curr = *p) != NULL) {
  634. - if (curr->gch.marked > limit) {
  635. + if ((curr->gch.marked & ~(KEYWEAK | VALUEWEAK)) > limit) {
  636. unmark(curr);
  637. p = &curr->gch.next;
  638. }
  639. ]],
  640. }
  641. Bug{
  642. what = [[Some "not not exp" may not result in boolean values]],
  643. report = [[]],
  644. since = [[4.0]],
  645. example = [[
  646. -- should print false, but prints nil
  647. print(not not (nil and 4))
  648. ]],
  649. patch = [[]],
  650. }
  651. Bug{
  652. what = [[On some machines, closing a "piped file" (created with io.popen)
  653. may crash Lua]],
  654. report = [[]],
  655. since = [[5.0]],
  656. example = [[
  657. -- only on some machines
  658. f = io.popen("ls")
  659. f:close()
  660. ]],
  661. patch = [[]],
  662. }
  663. -----------------------------------------------------------------
  664. -- Lua 5.1
  665. Bug{
  666. what = [[In 16-bit machines, expressions and/or with numeric constants as the
  667. right operand may result in weird values]],
  668. report = [[Andreas Stenius/Kein-Hong Man, 15/03/2006]],
  669. example = [[
  670. print(false or 0) -- on 16-bit machines
  671. ]],
  672. patch = [[
  673. * lcode.c:
  674. @@ -731,17 +731,15 @@
  675. case OPR_AND: {
  676. lua_assert(e1->t == NO_JUMP); /* list must be closed */
  677. luaK_dischargevars(fs, e2);
  678. - luaK_concat(fs, &e1->f, e2->f);
  679. - e1->k = e2->k; e1->u.s.info = e2->u.s.info;
  680. - e1->u.s.aux = e2->u.s.aux; e1->t = e2->t;
  681. + luaK_concat(fs, &e2->f, e1->f);
  682. + *e1 = *e2;
  683. break;
  684. }
  685. case OPR_OR: {
  686. lua_assert(e1->f == NO_JUMP); /* list must be closed */
  687. luaK_dischargevars(fs, e2);
  688. - luaK_concat(fs, &e1->t, e2->t);
  689. - e1->k = e2->k; e1->u.s.info = e2->u.s.info;
  690. - e1->u.s.aux = e2->u.s.aux; e1->f = e2->f;
  691. + luaK_concat(fs, &e2->t, e1->t);
  692. + *e1 = *e2;
  693. break;
  694. }
  695. ]],
  696. }
  697. Bug{
  698. what = [[luaL_checkudata may produce wrong error message]],
  699. report = [[Greg Falcon, 21/03/2006]],
  700. example = [[
  701. getmetatable(io.stdin).__gc()
  702. --> bad argument #1 to '__gc' (FILE* expected, got table)
  703. ]],
  704. patch = [[
  705. * lauxlib.c:
  706. @@ -123,11 +123,17 @@
  707. LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
  708. void *p = lua_touserdata(L, ud);
  709. - lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
  710. - if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2))
  711. - luaL_typerror(L, ud, tname);
  712. - lua_pop(L, 2); /* remove both metatables */
  713. - return p;
  714. + if (p != NULL) { /* value is a userdata? */
  715. + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
  716. + lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
  717. + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
  718. + lua_pop(L, 2); /* remove both metatables */
  719. + return p;
  720. + }
  721. + }
  722. + }
  723. + luaL_typerror(L, ud, tname); /* else error */
  724. + return NULL; /* to avoid warnings */
  725. }
  726. ]]
  727. }
  728. Bug{
  729. what = [[
  730. In Windows,
  731. when Lua is used in an application that also uses DirectX,
  732. it may present an erractic behavior.
  733. THIS IS NOT A LUA BUG!
  734. The problem is that DirectX violates an ABI that Lua depends on.]],
  735. patch = [[
  736. The simplest solution is to use DirectX with
  737. the D3DCREATE_FPU_PRESERVE flag.
  738. Otherwise, you can change the definition of lua_number2int,
  739. in luaconf.h, to this one:
  740. #define lua_number2int(i,d) __asm fld d __asm fistp i
  741. ]],
  742. }
  743. Bug{
  744. what = [[option '%q' in string.format does not handle '\r' correctly.]],
  745. example = [[
  746. local s = "a string with \r and \n and \r\n and \n\r"
  747. local c = string.format("return %q", s)
  748. assert(assert(loadstring(c))() == s)
  749. ]],
  750. patch = [[
  751. * lstrlib.c:
  752. @@ -703,6 +703,10 @@
  753. luaL_addchar(b, *s);
  754. break;
  755. }
  756. + case '\r': {
  757. + luaL_addlstring(b, "\\r", 2);
  758. + break;
  759. + }
  760. case '\0': {
  761. luaL_addlstring(b, "\\000", 4);
  762. break;
  763. ]],
  764. }
  765. Bug{
  766. what = [[lua_dostring/lua_dofile should return any values returned
  767. by the chunk]],
  768. patch = [[
  769. * lauxlib.h:
  770. @@ -108,9 +108,11 @@
  771. #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
  772. -#define luaL_dofile(L, fn) (luaL_loadfile(L, fn) || lua_pcall(L, 0, 0, 0))
  773. +#define luaL_dofile(L, fn) \
  774. + (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
  775. -#define luaL_dostring(L, s) (luaL_loadstring(L, s) || lua_pcall(L, 0, 0, 0))+#define luaL_dostring(L, s) \
  776. + (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
  777. #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
  778. ]],
  779. }
  780. Bug{
  781. what = [[garbage collector does not compensate enough for finalizers]],
  782. patch = [[
  783. lgc.c:
  784. @@ -322,4 +322,6 @@
  785. -static void propagateall (global_State *g) {
  786. - while (g->gray) propagatemark(g);
  787. +static size_t propagateall (global_State *g) {
  788. + size_t m = 0;
  789. + while (g->gray) m += propagatemark(g);
  790. + return m;
  791. }
  792. @@ -542,3 +544,3 @@
  793. marktmu(g); /* mark `preserved' userdata */
  794. - propagateall(g); /* remark, to propagate `preserveness' */
  795. + udsize += propagateall(g); /* remark, to propagate `preserveness' */
  796. cleartable(g->weak); /* remove collected objects from weak tables */
  797. @@ -592,2 +594,4 @@
  798. GCTM(L);
  799. + if (g->estimate > GCFINALIZECOST)
  800. + g->estimate -= GCFINALIZECOST;
  801. ]]
  802. }
  803. Bug{
  804. what = [[debug hooks may get wrong when mixed with coroutines]],
  805. report = [[by Ivko Stanilov, 03/06/2006]],
  806. example = [[
  807. co = coroutine.create(function (a,b)
  808. coroutine.yield(a, b)
  809. return b, "end"
  810. end)
  811. debug.sethook(co, function() end, "lcr")
  812. coroutine.resume(co, 100, 2000)
  813. coroutine.resume(co, 100, 2000)
  814. ]],
  815. patch = [[
  816. * ldo.c:
  817. @@ -389,6 +389,7 @@
  818. return;
  819. }
  820. else { /* resuming from previous yield */
  821. + L->status = 0;
  822. if (!f_isLua(ci)) { /* `common' yield? */
  823. /* finish interrupted execution of `OP_CALL' */
  824. lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL ||
  825. @@ -399,7 +400,6 @@
  826. else /* yielded inside a hook: just continue its execution */
  827. L->base = L->ci->base;
  828. }
  829. - L->status = 0;
  830. luaV_execute(L, cast_int(L->ci - L->base_ci));
  831. }
  832. ]],
  833. }
  834. -----------------------------------------------------------------
  835. -- Lua 5.1.1
  836. Bug{
  837. what = [[list constructors have wrong limit]],
  838. report = [[by Norman Ramsey, June 2006]],
  839. since = "Lua 5.1",
  840. example = [[
  841. a = {}
  842. a[1] = "x={1"
  843. for i = 2, 2^20 do
  844. a[i] = 1
  845. end
  846. a[#a + 1] = "}"
  847. s = table.concat(a, ",")
  848. assert(loadstring(s))()
  849. print(#x)
  850. ]],
  851. patch = [[
  852. * lparser.c:
  853. @@ -489,7 +489,7 @@
  854. static void listfield (LexState *ls, struct ConsControl *cc) {
  855. expr(ls, &cc->v);
  856. - luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor");
  857. + luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor");
  858. cc->na++;
  859. cc->tostore++;
  860. }
  861. ]],
  862. }
  863. Bug{
  864. what = [[wrong message error in some cases involving closures]],
  865. report = [[Shmuel Zeigerman, on 07/2006]],
  866. since = "Lua 5.1",
  867. example = [[
  868. local Var
  869. local function main()
  870. NoSuchName (function() Var=0 end)
  871. end
  872. main()
  873. --> lua5.1: temp:3: attempt to call upvalue 'Var' (a nil value)
  874. ]],
  875. patch = [[
  876. *ldebug.c:
  877. @@ -435,14 +435,16 @@
  878. break;
  879. }
  880. case OP_CLOSURE: {
  881. - int nup;
  882. + int nup, j;
  883. check(b < pt->sizep);
  884. nup = pt->p[b]->nups;
  885. check(pc + nup < pt->sizecode);
  886. - for (; nup>0; nup--) {
  887. - OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
  888. + for (j = 1; j <= nup; j++) {
  889. + OpCode op1 = GET_OPCODE(pt->code[pc + j]);
  890. check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
  891. }
  892. + if (reg != NO_REG) /* tracing? */
  893. + pc += nup; /* do not 'execute' these pseudo-instructions */
  894. break;
  895. }
  896. case OP_VARARG: {
  897. ]],
  898. }
  899. Bug{
  900. what = [[string.format("%") may read past the string]],
  901. report = [[Roberto, on 09/2006]],
  902. since = [[5.0 (at least)]],
  903. example = [[print(string.format("%"))]],
  904. patch = [[
  905. *lstrlib.c:
  906. @@ -723,7 +723,7 @@
  907. static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { const char *p = strfrmt;
  908. - while (strchr(FLAGS, *p)) p++; /* skip flags */
  909. + while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
  910. if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
  911. luaL_error(L, "invalid format (repeated flags)");
  912. if (isdigit(uchar(*p))) p++; /* skip width */
  913. ]],
  914. }
  915. Bug{
  916. what = [[os.date throws an error when result is the empty string]],
  917. report = [[]],
  918. since = [[4.0]],
  919. example = [[print(os.date(""))]],
  920. patch = [[
  921. *loslib.c:
  922. @@ -148,7 +148,18 @@
  923. else {
  924. - char b[256];
  925. - if (strftime(b, sizeof(b), s, stm))
  926. - lua_pushstring(L, b);
  927. - else
  928. - return luaL_error(L, LUA_QL("date") " format too long");
  929. + char cc[3];
  930. + luaL_Buffer b;
  931. + cc[0] = '%'; cc[2] = '\0';
  932. + luaL_buffinit(L, &b);
  933. + for (; *s; s++) {
  934. + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
  935. + luaL_addchar(&b, *s);
  936. + else {
  937. + size_t reslen;
  938. + char buff[200]; /* should be big enough for any conversion result */
  939. + cc[1] = *(++s);
  940. + reslen = strftime(buff, sizeof(buff), cc, stm);
  941. + luaL_addlstring(&b, buff, reslen);
  942. + }
  943. + }
  944. + luaL_pushresult(&b);
  945. }
  946. ]],
  947. }
  948. Bug{
  949. what = [[setfenv accepts invalid 1st argument]],
  950. report = [[Doug Rogers, on 02/2007]],
  951. since = [[5.0]],
  952. example = [[setfenv(nil, {}) -- should throw an error]],
  953. patch = [[
  954. *lbaselib.c:
  955. @@ -116,3 +116,3 @@
  956. -static void getfunc (lua_State *L) {
  957. +static void getfunc (lua_State *L, int opt) {
  958. if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
  959. @@ -120,3 +120,3 @@
  960. lua_Debug ar;
  961. - int level = luaL_optint(L, 1, 1);
  962. + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
  963. luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
  964. @@ -133,3 +133,3 @@
  965. static int luaB_getfenv (lua_State *L) {
  966. - getfunc(L);
  967. + getfunc(L, 1);
  968. if (lua_iscfunction(L, -1)) /* is a C function? */
  969. @@ -144,3 +144,3 @@
  970. luaL_checktype(L, 2, LUA_TTABLE);
  971. - getfunc(L);
  972. + getfunc(L, 0);
  973. lua_pushvalue(L, 2);
  974. ]],
  975. }
  976. Bug{
  977. what = [[wrong code for arithmetic expressions in some specific scenarios]],
  978. report = [[Thierry Grellier, on 01/2007]],
  979. since = [[5.1]],
  980. example = [[
  981. -- use a large number of names (almost 256)
  982. v1=1; v2=1; v3=1; v4=1; v5=1; v6=1; v7=1; v8=1; v9=1;
  983. v10=1; v11=1; v12=1; v13=1; v14=1; v15=1; v16=1; v17=1;
  984. v18=1; v19=1; v20=1; v21=1; v22=1; v23=1; v24=1; v25=1;
  985. v26=1; v27=1; v28=1; v29=1; v30=1; v31=1; v32=1; v33=1;
  986. v34=1; v35=1; v36=1; v37=1; v38=1; v39=1; v40=1; v41=1;
  987. v42=1; v43=1; v44=1; v45=1; v46=1; v47=1; v48=1; v49=1;
  988. v50=1; v51=1; v52=1; v53=1; v54=1; v55=1; v56=1; v57=1;
  989. v58=1; v59=1; v60=1; v61=1; v62=1; v63=1; v64=1; v65=1;
  990. v66=1; v67=1; v68=1; v69=1; v70=1; v71=1; v72=1; v73=1;
  991. v74=1; v75=1; v76=1; v77=1; v78=1; v79=1; v80=1; v81=1;
  992. v82=1; v83=1; v84=1; v85=1; v86=1; v87=1; v88=1; v89=1;
  993. v90=1; v91=1; v92=1; v93=1; v94=1; v95=1; v96=1; v97=1;
  994. v98=1; v99=1; v100=1; v101=1; v102=1; v103=1; v104=1; v105=1;
  995. v106=1; v107=1; v108=1; v109=1; v110=1; v111=1; v112=1; v113=1;
  996. v114=1; v115=1; v116=1; v117=1; v118=1; v119=1; v120=1; v121=1;
  997. v122=1; v123=1; v124=1; v125=1; v126=1; v127=1; v128=1; v129=1;
  998. v130=1; v131=1; v132=1; v133=1; v134=1; v135=1; v136=1; v137=1;
  999. v138=1; v139=1; v140=1; v141=1; v142=1; v143=1; v144=1; v145=1;
  1000. v146=1; v147=1; v148=1; v149=1; v150=1; v151=1; v152=1; v153=1;
  1001. v154=1; v155=1; v156=1; v157=1; v158=1; v159=1; v160=1; v161=1;
  1002. v162=1; v163=1; v164=1; v165=1; v166=1; v167=1; v168=1; v169=1;
  1003. v170=1; v171=1; v172=1; v173=1; v174=1; v175=1; v176=1; v177=1;
  1004. v178=1; v179=1; v180=1; v181=1; v182=1; v183=1; v184=1; v185=1;
  1005. v186=1; v187=1; v188=1; v189=1; v190=1; v191=1; v192=1; v193=1;
  1006. v194=1; v195=1; v196=1; v197=1; v198=1; v199=1; v200=1; v201=1;
  1007. v202=1; v203=1; v204=1; v205=1; v206=1; v207=1; v208=1; v209=1;
  1008. v210=1; v211=1; v212=1; v213=1; v214=1; v215=1; v216=1; v217=1;
  1009. v218=1; v219=1; v220=1; v221=1; v222=1; v223=1; v224=1; v225=1;
  1010. v226=1; v227=1; v228=1; v229=1; v230=1; v231=1; v232=1; v233=1;
  1011. v234=1; v235=1; v236=1; v237=1; v238=1; v239=1; v240=1; v241=1;
  1012. v242=1; v243=1; v244=1; v245=1; v246=1; v247=1; v248=1; v249=1;
  1013. v250=1;
  1014. v251={k1 = 1};
  1015. v252=1;
  1016. print(2 * v251.k1, v251.k1 * 2); -- 2 2, OK
  1017. v253=1;
  1018. print(2 * v251.k1, v251.k1 * 2); -- 1 2, ???
  1019. ]],
  1020. patch = [[
  1021. *lcode.c:
  1022. @@ -657,10 +657,16 @@
  1023. if (constfolding(op, e1, e2))
  1024. return;
  1025. else {
  1026. - int o1 = luaK_exp2RK(fs, e1);
  1027. int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0;
  1028. - freeexp(fs, e2);
  1029. - freeexp(fs, e1);
  1030. + int o1 = luaK_exp2RK(fs, e1);
  1031. + if (o1 > o2) {
  1032. + freeexp(fs, e1);
  1033. + freeexp(fs, e2);
  1034. + }
  1035. + else {
  1036. + freeexp(fs, e2);
  1037. + freeexp(fs, e1);
  1038. + }
  1039. e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2);
  1040. e1->k = VRELOCABLE;
  1041. }
  1042. @@ -718,10 +724,15 @@
  1043. luaK_exp2nextreg(fs, v); /* operand must be on the `stack' */
  1044. break;
  1045. }
  1046. - default: {
  1047. + case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
  1048. + case OPR_MOD: case OPR_POW: {
  1049. if (!isnumeral(v)) luaK_exp2RK(fs, v);
  1050. break;
  1051. }
  1052. + default: {
  1053. + luaK_exp2RK(fs, v);
  1054. + break;
  1055. + }
  1056. }
  1057. }
  1058. ]],
  1059. }
  1060. Bug{
  1061. what = [[assignment of nil to parameter may be optimized away]],
  1062. report = [[Thomas Lauer, on 03/2007]],
  1063. since = [[5.1]],
  1064. example = [[
  1065. function f (a)
  1066. a=nil
  1067. return a
  1068. end
  1069. print(f("test"))
  1070. ]],
  1071. patch = [[
  1072. *lcode.c:
  1073. @@ -35,16 +35,20 @@
  1074. void luaK_nil (FuncState *fs, int from, int n) {
  1075. Instruction *previous;
  1076. if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
  1077. - if (fs->pc == 0) /* function start? */
  1078. - return; /* positions are already clean */
  1079. - previous = &fs->f->code[fs->pc-1];
  1080. - if (GET_OPCODE(*previous) == OP_LOADNIL) {
  1081. - int pfrom = GETARG_A(*previous);
  1082. - int pto = GETARG_B(*previous);
  1083. - if (pfrom <= from && from <= pto+1) { /* can connect both? */
  1084. - if (from+n-1 > pto)
  1085. - SETARG_B(*previous, from+n-1);
  1086. - return;
  1087. + if (fs->pc == 0) { /* function start? */
  1088. + if (from >= fs->nactvar)
  1089. + return; /* positions are already clean */
  1090. + }
  1091. + else {
  1092. + previous = &fs->f->code[fs->pc-1];
  1093. + if (GET_OPCODE(*previous) == OP_LOADNIL) {
  1094. + int pfrom = GETARG_A(*previous);
  1095. + int pto = GETARG_B(*previous);
  1096. + if (pfrom <= from && from <= pto+1) { /* can connect both? */
  1097. + if (from+n-1 > pto)
  1098. + SETARG_B(*previous, from+n-1);
  1099. + return;
  1100. + }
  1101. }
  1102. }
  1103. }
  1104. ]],
  1105. }
  1106. Bug{
  1107. what = [[__concat metamethod converts numbers to strings]],
  1108. report = [[Paul Winwood, on 12/2006]],
  1109. since = [[5.0]],
  1110. example = [[
  1111. a = {}
  1112. setmetatable(a, {__concat = function (a,b) print(type(a), type(b)) end})
  1113. a = 4 .. a
  1114. ]],
  1115. patch = [[
  1116. *lvm.c:
  1117. @@ -281,10 +281,12 @@
  1118. do {
  1119. StkId top = L->base + last + 1;
  1120. int n = 2; /* number of elements handled in this pass (at least 2) */
  1121. - if (!tostring(L, top-2) || !tostring(L, top-1)) {
  1122. + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
  1123. if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
  1124. luaG_concaterror(L, top-2, top-1);
  1125. - } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */
  1126. + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */
  1127. + (void)tostring(L, top - 2); /* result is first op (as string) */
  1128. + else {
  1129. /* at least two string values; get as many as possible */
  1130. size_t tl = tsvalue(top-1)->len;
  1131. char *buffer;
  1132. ]],
  1133. }
  1134. Bug{
  1135. what = [[As a library, loadlib.c should not access Lua internals
  1136. (via lobject.h)]],
  1137. report = [[Jérôme Vuarand, on 03/2007]],
  1138. since = [[5.0 (at least)]],
  1139. example = [[the bug has no effect on external behavior]],
  1140. patch = [[remove the '#include "lobject.h" and use
  1141. 'lua_pushfstring' instead of 'luaO_pushfstring']],
  1142. }
  1143. -----------------------------------------------------------------
  1144. -- Lua 5.1.2
  1145. Bug{
  1146. what = [[Lua may close standard files,
  1147. which then may be used by C]],
  1148. report = [[David Manura/Ross Berteig, on 04/2007]],
  1149. since = [[ ]],
  1150. example = [[
  1151. io.close(io.stderr)
  1152. -- in some systems, following attempts to write to 'stderr' may crash
  1153. a = a + 1
  1154. ]],
  1155. patch = [[
  1156. ]],
  1157. }
  1158. Bug{
  1159. what = [[code generated for "-nil", "-true", and "-false" is wrong]],
  1160. report = [[David Manura/Rici Lake, on 04/2007]],
  1161. since = [[5.1]],
  1162. example = [[print(-nil)]],
  1163. patch = [[
  1164. lcode.c:
  1165. @@ -699,7 +699,7 @@
  1166. e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0;
  1167. switch (op) {
  1168. case OPR_MINUS: {
  1169. - if (e->k == VK)
  1170. + if (!isnumeral(e))
  1171. luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */
  1172. codearith(fs, OP_UNM, e, &e2);
  1173. break;
  1174. ]],
  1175. }
  1176. Bug{
  1177. what = [[Count hook may be called without being set.]],
  1178. report = [[Mike Pall, on 05/2007]],
  1179. since = [[?]],
  1180. example = [[ ]],
  1181. patch = [[
  1182. lvm.c:
  1183. @@ -61,11 +61,9 @@
  1184. lu_byte mask = L->hookmask;
  1185. const Instruction *oldpc = L->savedpc;
  1186. L->savedpc = pc;
  1187. - if (mask > LUA_MASKLINE) { /* instruction-hook set? */
  1188. - if (L->hookcount == 0) {
  1189. - resethookcount(L);
  1190. - luaD_callhook(L, LUA_HOOKCOUNT, -1);
  1191. - }
  1192. + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
  1193. + resethookcount(L);
  1194. + luaD_callhook(L, LUA_HOOKCOUNT, -1);
  1195. }
  1196. if (mask & LUA_MASKLINE) {
  1197. Proto *p = ci_func(L->ci)->l.p;
  1198. ]],
  1199. }
  1200. Bug{
  1201. what = [[recursive coroutines may overflow C stack]],
  1202. report = [[ , on ]],
  1203. since = [[5.0]],
  1204. example = [[
  1205. a = function(a) coroutine.wrap(a)(a) end
  1206. a(a)
  1207. ]],
  1208. patch = [[The 'nCcalls' counter should be shared by all threads.
  1209. (That is, it should be declared in the 'global_State' structure,
  1210. not in 'lua_State'.)
  1211. ]],
  1212. }
  1213. Bug{
  1214. what = [[wrong error message in some concatenations]],
  1215. report = [[Alex Davies, on 05/2007]],
  1216. since = [[5.1.2]],
  1217. example = [[a = nil; a = (1)..a]],
  1218. patch = [[
  1219. ldebug.c:
  1220. @@ -563,8 +563,8 @@
  1221. void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
  1222. - if (ttisstring(p1)) p1 = p2;
  1223. - lua_assert(!ttisstring(p1));
  1224. + if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
  1225. + lua_assert(!ttisstring(p1) && !ttisnumber(p1));
  1226. luaG_typeerror(L, p1, "concatenate");
  1227. }
  1228. ]],
  1229. }
  1230. Bug{
  1231. what = [[Very small numbers all collide in the hash function.
  1232. (This creates only performance problems; the behavoir is correct.)]],
  1233. report = [[, on ]],
  1234. since = [[Lua 5.0]],
  1235. example = [[ ]],
  1236. patch = [[
  1237. ltable.c:
  1238. 87,88c87,88
  1239. < n += 1; /* normalize number (avoid -0) */
  1240. < lua_assert(sizeof(a) <= sizeof(n));
  1241. ---
  1242. > if (luai_numeq(n, 0)) /* avoid problems with -0 */
  1243. > return gnode(t, 0);
  1244. ]],
  1245. }
  1246. Bug{
  1247. what = [[Too many variables in an assignment may cause a
  1248. C stack overflow]],
  1249. report = [[Mike Pall, on 07/2007]],
  1250. since = [[5.0]],
  1251. example = [[
  1252. $ ulimit -s 1024 # Reduce C stack to 1MB for quicker results
  1253. $ lua -e 'local s = "a,"; for i=1,18 do s = s..s end print(loadstring("local a;"..s.."a=nil", ""))'
  1254. ]],
  1255. patch = [[
  1256. lparser.c:
  1257. @@ -938,6 +938,8 @@
  1258. primaryexp(ls, &nv.v);
  1259. if (nv.v.k == VLOCAL)
  1260. check_conflict(ls, lh, &nv.v);
  1261. + luaY_checklimit(ls->fs, nvars, LUAI_MAXCCALLS - ls->L->nCcalls,
  1262. + "variable names");
  1263. assignment(ls, &nv, nvars+1);
  1264. }
  1265. else { /* assignment -> `=' explist1 */
  1266. ]],
  1267. }
  1268. Bug{
  1269. what = [[An error in a module loaded through the '-l' option
  1270. shows no traceback]],
  1271. report = [[David Manura, on 08/2007]],
  1272. since = [[5.1]],
  1273. example = [[lua -ltemp (assuming temp.lua has an error)]],
  1274. patch = [[
  1275. lua.c:
  1276. @@ -144,7 +144,7 @@
  1277. static int dolibrary (lua_State *L, const char *name) {
  1278. lua_getglobal(L, "require");
  1279. lua_pushstring(L, name);
  1280. - return report(L, lua_pcall(L, 1, 0, 0));
  1281. + return report(L, docall(L, 1, 1));
  1282. }
  1283. ]],
  1284. }
  1285. Bug{
  1286. what = [['gsub' may go wild when wrongly called without its third
  1287. argument and with a large subject]],
  1288. report = [[Florian Berger, on 10/2007]],
  1289. since = [[5.1]],
  1290. example = [[
  1291. x = string.rep('a', 10000) .. string.rep('b', 10000)
  1292. print(#string.gsub(x, 'b'))
  1293. ]],
  1294. patch = [[
  1295. lstrlib.c:
  1296. @@ -631,6 +631,2 @@
  1297. }
  1298. - default: {
  1299. - luaL_argerror(L, 3, "string/function/table expected");
  1300. - return;
  1301. - }
  1302. }
  1303. @@ -650,2 +646,3 @@
  1304. const char *p = luaL_checkstring(L, 2);
  1305. + int tr = lua_type(L, 3);
  1306. int max_s = luaL_optint(L, 4, srcl+1);
  1307. @@ -655,2 +652,5 @@
  1308. luaL_Buffer b;
  1309. + luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
  1310. + tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
  1311. + "string/function/table expected");
  1312. luaL_buffinit(L, &b);
  1313. ]],
  1314. }
  1315. Bug{
  1316. what = [[table.remove removes last element of a table when given
  1317. an out-of-bound index]],
  1318. report = [[Patrick Donnelly, on 11/2007]],
  1319. since = [[at least 5.0]],
  1320. example = [[
  1321. a = {1,2,3}
  1322. table.remove(a, 4)
  1323. print(a[3]) --> nil (should be 3)
  1324. ]],
  1325. patch = [[
  1326. ltablib.c:
  1327. @@ -118,7 +118,8 @@
  1328. static int tremove (lua_State *L) {
  1329. int e = aux_getn(L, 1);
  1330. int pos = luaL_optint(L, 2, e);
  1331. - if (e == 0) return 0; /* table is `empty' */
  1332. + if (!(1 <= pos && pos <= e)) /* position is outside bounds? */
  1333. + return 0; /* nothing to remove */
  1334. luaL_setn(L, 1, e - 1); /* t.n = n-1 */
  1335. lua_rawgeti(L, 1, pos); /* result = t[pos] */
  1336. for ( ;pos<e; pos++) {
  1337. ]],
  1338. }
  1339. Bug{
  1340. what = [[lua_setfenv may crash if called over an invalid object]],
  1341. report = [[Mike Pall, on 11/2007]],
  1342. since = [[5.1]],
  1343. example = [[
  1344. > debug.setfenv(3, {})
  1345. ]],
  1346. patch = [[
  1347. lapi.c:
  1348. @@ -749,7 +749,7 @@
  1349. res = 0;
  1350. break;
  1351. }
  1352. - luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
  1353. + if (res) luaC_objbarrier(L, gcvalue(o), hvalue(L->top - 1));
  1354. L->top--;
  1355. lua_unlock(L);
  1356. return res;
  1357. ]],
  1358. }
  1359. Bug{
  1360. what = [[stand-alone interpreter shows incorrect error message
  1361. when the "message" is a coroutine]],
  1362. report = [[Patrick Donnelly, on 17/12/2007]],
  1363. since = [[i ]],
  1364. example = [[> error(coroutine.create(function() end))]],
  1365. patch = [[
  1366. lua.c:
  1367. @@ -74,6 +74,8 @@
  1368. static int traceback (lua_State *L) {
  1369. + if (!lua_isstring(L, 1)) /* 'message' not a string? */
  1370. + return 1; /* keep it intact */
  1371. lua_getfield(L, LUA_GLOBALSINDEX, "debug");
  1372. if (!lua_istable(L, -1)) {
  1373. lua_pop(L, 1);
  1374. ]],
  1375. }
  1376. Bug{
  1377. what = [[debug.sethook/gethook may overflow the thread's stack]],
  1378. report = [[Ivko Stanilov, on 2008/01/04]],
  1379. since = [[5.1]],
  1380. example = [[
  1381. a = coroutine.create(function() yield() end)
  1382. coroutine.resume(a)
  1383. debug.sethook(a) -- may overflow the stack of 'a'
  1384. ]],
  1385. patch = [[
  1386. ldblib.c:
  1387. @@ -268,12 +268,11 @@
  1388. count = luaL_optint(L, arg+3, 0);
  1389. func = hookf; mask = makemask(smask, count);
  1390. }
  1391. - gethooktable(L1);
  1392. - lua_pushlightuserdata(L1, L1);
  1393. + gethooktable(L);
  1394. + lua_pushlightuserdata(L, L1);
  1395. lua_pushvalue(L, arg+1);
  1396. - lua_xmove(L, L1, 1);
  1397. - lua_rawset(L1, -3); /* set new hook */
  1398. - lua_pop(L1, 1); /* remove hook table */
  1399. + lua_rawset(L, -3); /* set new hook */
  1400. + lua_pop(L, 1); /* remove hook table */
  1401. lua_sethook(L1, func, mask, count); /* set hooks */
  1402. return 0;
  1403. }
  1404. @@ -288,11 +287,10 @@
  1405. if (hook != NULL && hook != hookf) /* external hook? */
  1406. lua_pushliteral(L, "external hook");
  1407. else {
  1408. - gethooktable(L1);
  1409. - lua_pushlightuserdata(L1, L1);
  1410. - lua_rawget(L1, -2); /* get hook */
  1411. - lua_remove(L1, -2); /* remove hook table */
  1412. - lua_xmove(L1, L, 1);
  1413. + gethooktable(L);
  1414. + lua_pushlightuserdata(L, L1);
  1415. + lua_rawget(L, -2); /* get hook */
  1416. + lua_remove(L, -2); /* remove hook table */
  1417. }
  1418. lua_pushstring(L, unmakemask(mask, buff));
  1419. lua_pushinteger(L, lua_gethookcount(L1));
  1420. ]]
  1421. }
  1422. -----------------------------------------------------------------
  1423. -- Lua 5.1.3
  1424. Bug{
  1425. what = [[LUAI_MAXCSTACK must be smaller than -LUA_REGISTRYINDEX]],
  1426. report = [[Patrick Donnelly, on 2008/02/11]],
  1427. since = [[5.1.3]],
  1428. example = [[
  1429. j = 1e4
  1430. co = coroutine.create(function()
  1431. t = {}
  1432. for i = 1, j do t[i] = i end
  1433. return unpack(t)
  1434. end)
  1435. print(coroutine.resume(co))
  1436. ]],
  1437. patch = [[
  1438. luaconf.h:
  1439. 443c443,444
  1440. < ** functions to consume unlimited stack space.
  1441. ---
  1442. > ** functions to consume unlimited stack space. (must be smaller than
  1443. > ** -LUA_REGISTRYINDEX)
  1444. 445,446c446
  1445. < #define LUAI_MCS_AUX ((int)(INT_MAX / (4*sizeof(LUA_NUMBER))))
  1446. < #define LUAI_MAXCSTACK (LUAI_MCS_AUX > SHRT_MAX ? SHRT_MAX : LUAI_MCS_AUX)
  1447. ---
  1448. > #define LUAI_MAXCSTACK 8000
  1449. ]],
  1450. }
  1451. Bug{
  1452. what = [[coroutine.resume pushes element without ensuring stack size]],
  1453. report = [[on 2008/02/11]],
  1454. since = [[5.0]],
  1455. example = [[(this bug cannot be detected without internal assertions)]],
  1456. patch = [[
  1457. lbaselib.c:
  1458. @@ -526,7 +526,7 @@
  1459. status = lua_resume(co, narg);
  1460. if (status == 0 || status == LUA_YIELD) {
  1461. int nres = lua_gettop(co);
  1462. - if (!lua_checkstack(L, nres))
  1463. + if (!lua_checkstack(L, nres + 1))
  1464. luaL_error(L, "too many results to resume");
  1465. lua_xmove(co, L, nres); /* move yielded values */
  1466. return nres;
  1467. ]],
  1468. }
  1469. Bug{
  1470. what = [[lua_checkstack may have arithmetic overflow for large 'size']],
  1471. report = [[Patrick Donnelly, on 2008/02/12]],
  1472. since = [[5.0]],
  1473. example = [[
  1474. print(unpack({1,2,3}, 0, 2^31-3))
  1475. ]],
  1476. patch = [[
  1477. --- lapi.c 2008/01/03 15:20:39 2.55.1.3
  1478. +++ lapi.c 2008/02/14 16:05:21
  1479. @@ -93,15 +93,14 @@
  1480. LUA_API int lua_checkstack (lua_State *L, int size) {
  1481. - int res;
  1482. + int res = 1;
  1483. lua_lock(L);
  1484. - if ((L->top - L->base + size) > LUAI_MAXCSTACK)
  1485. + if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK)
  1486. res = 0; /* stack overflow */
  1487. - else {
  1488. + else if (size > 0) {
  1489. luaD_checkstack(L, size);
  1490. if (L->ci->top < L->top + size)
  1491. L->ci->top = L->top + size;
  1492. - res = 1;
  1493. }
  1494. lua_unlock(L);
  1495. return res;
  1496. ]],
  1497. }
  1498. Bug{
  1499. what = [[unpack with maximum indices may crash due to arithmetic overflow]],
  1500. report = [[Patrick Donnelly, on 2008/02/12]],
  1501. since = [[5.1]],
  1502. example = [[
  1503. print(unpack({1,2,3}, 2^31-1, 2^31-1))
  1504. ]],
  1505. patch = [[
  1506. --- lbaselib.c 2008/02/11 16:24:24 1.191.1.5
  1507. +++ lbaselib.c 2008/02/14 16:10:25
  1508. @@ -344,10 +344,12 @@
  1509. luaL_checktype(L, 1, LUA_TTABLE);
  1510. i = luaL_optint(L, 2, 1);
  1511. e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
  1512. + if (i > e) return 0; /* empty range */
  1513. n = e - i + 1; /* number of elements */
  1514. - if (n <= 0) return 0; /* empty range */
  1515. - luaL_checkstack(L, n, "table too big to unpack");
  1516. - for (; i<=e; i++) /* push arg[i...e] */
  1517. + if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
  1518. + return luaL_error(L, "too many results to unpack");
  1519. + lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
  1520. + while (i++ < e) /* push arg[i + 1...e] */
  1521. lua_rawgeti(L, 1, i);
  1522. return n;
  1523. }
  1524. ]],
  1525. }
  1526. Bug{
  1527. what = [[The validator for precompiled code has several flaws that
  1528. allow malicious binary code to crash the application]],
  1529. report = [[Peter Cawley, on 2008/03/24]],
  1530. since = [[5.0]],
  1531. example = [[
  1532. a = string.dump(function()return;end)
  1533. a = a:gsub(string.char(30,37,122,128), string.char(34,0,0), 1)
  1534. loadstring(a)()
  1535. ]],
  1536. patch = [[
  1537. --- ldebug.c 2007/12/28 15:32:23 2.29.1.3
  1538. +++ ldebug.c 2008/04/04 15:15:40
  1539. @@ -275,12 +275,12 @@
  1540. static int precheck (const Proto *pt) {
  1541. check(pt->maxstacksize <= MAXSTACK);
  1542. - lua_assert(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
  1543. - lua_assert(!(pt->is_vararg & VARARG_NEEDSARG) ||
  1544. + check(pt->numparams+(pt->is_vararg & VARARG_HASARG) <= pt->maxstacksize);
  1545. + check(!(pt->is_vararg & VARARG_NEEDSARG) ||
  1546. (pt->is_vararg & VARARG_HASARG));
  1547. check(pt->sizeupvalues <= pt->nups);
  1548. check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
  1549. - check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
  1550. + check(pt->sizecode > 0 && GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
  1551. return 1;
  1552. }
  1553. @@ -363,7 +363,11 @@
  1554. }
  1555. switch (op) {
  1556. case OP_LOADBOOL: {
  1557. - check(c == 0 || pc+2 < pt->sizecode); /* check its jump */
  1558. + if (c == 1) { /* does it jump? */
  1559. + check(pc+2 < pt->sizecode); /* check its jump */
  1560. + check(GET_OPCODE(pt->code[pc+1]) != OP_SETLIST ||
  1561. + GETARG_C(pt->code[pc+1]) != 0);
  1562. + }
  1563. break;
  1564. }
  1565. case OP_LOADNIL: {
  1566. @@ -428,7 +432,10 @@
  1567. }
  1568. case OP_SETLIST: {
  1569. if (b > 0) checkreg(pt, a + b);
  1570. - if (c == 0) pc++;
  1571. + if (c == 0) {
  1572. + pc++;
  1573. + check(pc < pt->sizecode - 1);
  1574. + }
  1575. break;
  1576. }
  1577. case OP_CLOSURE: {
  1578. ]],
  1579. }
  1580. Bug{
  1581. what = [[maliciously crafted precompiled code can blow the C stack]],
  1582. report = [[Greg Falcon, on 2008/03/25]],
  1583. since = [[5.0]],
  1584. example = [[
  1585. function crash(depth)
  1586. local init = '\27\76\117\97\81\0\1\4\4\4\8\0\7\0\0\0\61\115\116' ..
  1587. '\100\105\110\0\1\0\0\0\1\0\0\0\0\0\0\2\2\0\0\0\36' ..
  1588. '\0\0\0\30\0\128\0\0\0\0\0\1\0\0\0\0\0\0\0\1\0\0\0' ..
  1589. '\1\0\0\0\0\0\0\2'
  1590. local mid = '\1\0\0\0\30\0\128\0\0\0\0\0\0\0\0\0\1\0\0\0\1\0\0\0\0'
  1591. local fin = '\0\0\0\0\0\0\0\2\0\0\0\1\0\0\0\1\0\0\0\1\0\0\0\2\0' ..
  1592. '\0\0\97\0\1\0\0\0\1\0\0\0\0\0\0\0'
  1593. local lch = '\2\0\0\0\36\0\0\0\30\0\128\0\0\0\0\0\1\0\0\0\0\0\0' ..
  1594. '\0\1\0\0\0\1\0\0\0\0\0\0\2'
  1595. local rch = '\0\0\0\0\0\0\0\2\0\0\0\1\0\0\0\1\0\0\0\1\0\0\0\2\0' ..
  1596. '\0\0\97\0\1\0\0\0\1'
  1597. for i=1,depth do lch,rch = lch..lch,rch..rch end
  1598. loadstring(init .. lch .. mid .. rch .. fin)
  1599. end
  1600. for i=1,25 do print(i); crash(i) end
  1601. ]],
  1602. patch = [[
  1603. --- lundump.c 2008/04/04 16:00:45 2.7.1.3
  1604. +++ lundump.c 2008/04/04 19:51:41 2.7.1.4
  1605. @@ -1,5 +1,5 @@
  1606. /*
  1607. -** $Id: bugs,v 1.114 2012/05/11 14:10:28 roberto Exp roberto $
  1608. +** $Id: bugs,v 1.114 2012/05/11 14:10:28 roberto Exp roberto $
  1609. ** load precompiled Lua chunks
  1610. ** See Copyright Notice in lua.h
  1611. */
  1612. @@ -161,7 +161,9 @@
  1613. static Proto* LoadFunction(LoadState* S, TString* p)
  1614. {
  1615. - Proto* f=luaF_newproto(S->L);
  1616. + Proto* f;
  1617. + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
  1618. + f=luaF_newproto(S->L);
  1619. setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
  1620. f->source=LoadString(S); if (f->source==NULL) f->source=p;
  1621. f->linedefined=LoadInt(S);
  1622. @@ -175,6 +177,7 @@
  1623. LoadDebug(S,f);
  1624. IF (!luaG_checkcode(f), "bad code");
  1625. S->L->top--;
  1626. + S->L->nCcalls--;
  1627. return f;
  1628. }
  1629. ]],
  1630. }
  1631. Bug{
  1632. what = [[code validator may reject (maliciously crafted) correct code]],
  1633. report = [[Greg Falcon, on 2008/03/26]],
  1634. since = [[5.0]],
  1635. example = [[
  1636. z={}
  1637. for i=1,27290 do z[i]='1,' end
  1638. z = 'if 1+1==2 then local a={' .. table.concat(z) .. '} end'
  1639. func = loadstring(z)
  1640. print(loadstring(string.dump(func)))
  1641. ]],
  1642. patch = [[
  1643. --- ldebug.c 2008/04/04 15:30:05 2.29.1.4
  1644. +++ ldebug.c 2008/04/04 15:47:10
  1645. @@ -346,9 +346,18 @@
  1646. int dest = pc+1+b;
  1647. check(0 <= dest && dest < pt->sizecode);
  1648. if (dest > 0) {
  1649. - /* cannot jump to a setlist count */
  1650. - Instruction d = pt->code[dest-1];
  1651. - check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
  1652. + int j;
  1653. + /* check that it does not jump to a setlist count; this
  1654. + is tricky, because the count from a previous setlist may
  1655. + have the same value of an invalid setlist; so, we must
  1656. + go all the way back to the first of them (if any) */
  1657. + for (j = 0; j < dest; j++) {
  1658. + Instruction d = pt->code[dest-1-j];
  1659. + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
  1660. + }
  1661. + /* if 'j' is even, previous value is not a setlist (even if
  1662. + it looks like one) */
  1663. + check((j&1) == 0);
  1664. }
  1665. }
  1666. break;
  1667. ]],
  1668. }
  1669. Bug{
  1670. what = [[maliciously crafted precompiled code can inject invalid boolean
  1671. values into Lua code]],
  1672. report = [[Greg Falcon, on 2008/03/27]],
  1673. since = [[5.0]],
  1674. example = [[
  1675. maybe = string.dump(function() return ({[true]=true})[true] end)
  1676. maybe = maybe:gsub('\1\1','\1\2')
  1677. maybe = loadstring(maybe)()
  1678. assert(type(maybe) == "boolean" and maybe ~= true and maybe ~= false)
  1679. ]],
  1680. patch = [[
  1681. --- lundump.c 2008/01/18 16:39:11 2.7.1.2
  1682. +++ lundump.c 2008/04/04 15:50:39
  1683. @@ -115,7 +115,7 @@
  1684. setnilvalue(o);
  1685. break;
  1686. case LUA_TBOOLEAN:
  1687. - setbvalue(o,LoadChar(S));
  1688. + setbvalue(o,LoadChar(S)!=0);
  1689. break;
  1690. case LUA_TNUMBER:
  1691. setnvalue(o,LoadNumber(S));
  1692. ]],
  1693. }
  1694. Bug{
  1695. what = [['string.byte' gets confused with some out-of-range negative indices]],
  1696. report = [[Mike Pall, on 2008/06/03]],
  1697. since = [[5.1]],
  1698. example = [[
  1699. print(string.byte("abc", -5)) --> 97 98 99 (should print nothing)
  1700. ]],
  1701. patch = [[
  1702. --- lstrlib.c 2007/12/28 15:32:23 1.132.1.3
  1703. +++ lstrlib.c 2008/07/05 11:53:42
  1704. @@ -35,7 +35,8 @@
  1705. static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {
  1706. /* relative string position: negative means back from end */
  1707. - return (pos>=0) ? pos : (ptrdiff_t)len+pos+1;
  1708. + if (pos < 0) pos += (ptrdiff_t)len + 1;
  1709. + return (pos >= 0) ? pos : 0;
  1710. }
  1711. ]],
  1712. }
  1713. Bug{
  1714. what = [[user-requested GC step may loop forever]],
  1715. report = [[Makoto Hamanaka, on 2008/07/01]],
  1716. since = [[5.1]],
  1717. example = [[
  1718. collectgarbage("setpause", 100) -- small value
  1719. collectgarbage("setstepmul", 2000) -- large value
  1720. collectgarbage("step",0)
  1721. ]],
  1722. patch = [[
  1723. --- lapi.c 2008/02/14 16:46:39 2.55.1.4
  1724. +++ lapi.c 2008/07/04 18:34:48
  1725. @@ -929,10 +929,13 @@
  1726. g->GCthreshold = g->totalbytes - a;
  1727. else
  1728. g->GCthreshold = 0;
  1729. - while (g->GCthreshold <= g->totalbytes)
  1730. + while (g->GCthreshold <= g->totalbytes) {
  1731. luaC_step(L);
  1732. - if (g->gcstate == GCSpause) /* end of cycle? */
  1733. - res = 1; /* signal it */
  1734. + if (g->gcstate == GCSpause) { /* end of cycle? */
  1735. + res = 1; /* signal it */
  1736. + break;
  1737. + }
  1738. + }
  1739. break;
  1740. }
  1741. case LUA_GCSETPAUSE: {
  1742. ]],
  1743. }
  1744. Bug{
  1745. what = [['module' may change the environment of a C function]],
  1746. report = [[Peter Cawley, on 2008/07/16]],
  1747. since = [[5.1]],
  1748. example = [[
  1749. pcall(module, "xuxu")
  1750. assert(debug.getfenv(pcall) == xuxu)
  1751. ]],
  1752. patch = [[
  1753. --- loadlib.c 2007/12/28 14:58:43 1.52.1.2
  1754. +++ loadlib.c 2008/08/05 19:39:00
  1755. @@ -506,8 +506,11 @@
  1756. static void setfenv (lua_State *L) {
  1757. lua_Debug ar;
  1758. - lua_getstack(L, 1, &ar);
  1759. - lua_getinfo(L, "f", &ar);
  1760. + if (lua_getstack(L, 1, &ar) == 0 ||
  1761. + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
  1762. + lua_iscfunction(L, -1))
  1763. + luaL_error(L, "function " LUA_QL("module")
  1764. + " not called from a Lua function");
  1765. lua_pushvalue(L, -2);
  1766. lua_setfenv(L, -2);
  1767. lua_pop(L, 1);
  1768. ]],
  1769. }
  1770. Bug{
  1771. what = [[internal macro 'svalue' is wrong]],
  1772. report = [[Martijn van Buul, on 2008/08/04]],
  1773. since = [[5.1]],
  1774. example = [[
  1775. /* in luaconf.h */
  1776. #define LUAI_USER_ALIGNMENT_T union { char b[32]; }
  1777. ]],
  1778. patch = [[
  1779. --- lobject.h 2007/12/27 13:02:25 2.20.1.1
  1780. +++ lobject.h 2008/08/05 19:40:48
  1781. @@ -210,3 +210,3 @@
  1782. #define getstr(ts) cast(const char *, (ts) + 1)
  1783. -#define svalue(o) getstr(tsvalue(o))
  1784. +#define svalue(o) getstr(rawtsvalue(o))
  1785. ]],
  1786. }
  1787. -----------------------------------------------------------------
  1788. -- Lua 5.1.4
  1789. Bug{
  1790. what = [[malicious zero-length string in binary code may segfault Lua]],
  1791. report = [[Peter Cawley, on 2008/09/01]],
  1792. since = [[5.1]],
  1793. example = [[
  1794. loadstring(('').dump(function()X''end):gsub('\2%z%z%zX','\0\0\0'))()
  1795. ]],
  1796. patch = [[
  1797. ]],
  1798. }
  1799. Bug{
  1800. what = [[wrong code generation for some particular boolean expressions]],
  1801. report = [[Brian Kelley, on 2009/04/15]],
  1802. since = [[5.0]],
  1803. example = [[
  1804. print(((1 or false) and true) or false) --> 1
  1805. -- should be 'true'
  1806. ]],
  1807. patch = [[
  1808. --- lcode.c 2007/12/28 15:32:23 2.25.1.3
  1809. +++ lcode.c 2009/06/15 14:07:34
  1810. @@ -544,15 +544,18 @@
  1811. pc = NO_JUMP; /* always true; do nothing */
  1812. break;
  1813. }
  1814. - case VFALSE: {
  1815. - pc = luaK_jump(fs); /* always jump */
  1816. - break;
  1817. - }
  1818. case VJMP: {
  1819. invertjump(fs, e);
  1820. pc = e->u.s.info;
  1821. break;
  1822. }
  1823. + case VFALSE: {
  1824. + if (!hasjumps(e)) {
  1825. + pc = luaK_jump(fs); /* always jump */
  1826. + break;
  1827. + }
  1828. + /* else go through */
  1829. + }
  1830. default: {
  1831. pc = jumponcond(fs, e, 0);
  1832. break;
  1833. @@ -572,14 +575,17 @@
  1834. pc = NO_JUMP; /* always false; do nothing */
  1835. break;
  1836. }
  1837. - case VTRUE: {
  1838. - pc = luaK_jump(fs); /* always jump */
  1839. - break;
  1840. - }
  1841. case VJMP: {
  1842. pc = e->u.s.info;
  1843. break;
  1844. }
  1845. + case VTRUE: {
  1846. + if (!hasjumps(e)) {
  1847. + pc = luaK_jump(fs); /* always jump */
  1848. + break;
  1849. + }
  1850. + /* else go through */
  1851. + }
  1852. default: {
  1853. pc = jumponcond(fs, e, 1);
  1854. break;
  1855. ]],
  1856. }
  1857. Bug{
  1858. what = [['luaV_settable' may invalidate a reference to a table and try
  1859. to reuse it]],
  1860. report = [[Mark Feldman, on 2009/06/27]],
  1861. since = [[5.0]],
  1862. example = [[
  1863. grandparent = {}
  1864. grandparent.__newindex = function(s,_,_) print(s) end
  1865. parent = {}
  1866. parent.__newindex = parent
  1867. setmetatable(parent, grandparent)
  1868. child = setmetatable({}, parent)
  1869. child.foo = 10 --> (crash on some machines)
  1870. ]],
  1871. patch = [[
  1872. --- lvm.c 2007/12/28 15:32:23 2.63.1.3
  1873. +++ lvm.c 2009/07/01 20:36:59
  1874. @@ -133,6 +133,7 @@
  1875. void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
  1876. int loop;
  1877. + TValue temp;
  1878. for (loop = 0; loop < MAXTAGLOOP; loop++) {
  1879. const TValue *tm;
  1880. if (ttistable(t)) { /* `t' is a table? */
  1881. @@ -152,7 +153,9 @@
  1882. callTM(L, tm, t, key, val);
  1883. return;
  1884. }
  1885. - t = tm; /* else repeat with `tm' */
  1886. + /* else repeat with `tm' */
  1887. + setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */
  1888. + t = &temp;
  1889. }
  1890. luaG_runerror(L, "loop in settable");
  1891. }
  1892. ]],
  1893. }
  1894. Bug{
  1895. what = [[smart use of varargs may create functions that return too
  1896. many arguments and overflow the stack of C functions]],
  1897. report = [[Patrick Donnelly, on 2008/12/10]],
  1898. since = [[]],
  1899. example = [[
  1900. local function lunpack(i, ...)
  1901. if i == 0 then return ...
  1902. else
  1903. return lunpack(i-1, 1, ...)
  1904. end
  1905. end
  1906. Now, if C calls lunpack(n) with a huge n, it may end with
  1907. too many values in its stack and confuse its stack indices.
  1908. ]],
  1909. patch = [[
  1910. ]],
  1911. }
  1912. Bug{
  1913. what = [['debug.getfenv' does not check whether it has an argument]],
  1914. report = [[Patrick Donnelly, 2009/07/30]],
  1915. since = [[5.1]],
  1916. example = [[debug.getfenv() -- should raise an error]],
  1917. patch = [[
  1918. --- ldblib.c 2008/01/21 13:11:21 1.104.1.3
  1919. +++ ldblib.c 2009/08/04 18:43:12
  1920. @@ -45,6 +45,7 @@
  1921. static int db_getfenv (lua_State *L) {
  1922. + luaL_checkany(L, 1);
  1923. lua_getfenv(L, 1);
  1924. return 1;
  1925. }
  1926. ]],
  1927. }
  1928. Bug{
  1929. what = [[GC may get stuck during a parser and avoids proper resizing of
  1930. the string table,
  1931. making its lists grow too much and degrading performance]],
  1932. report = [[Sean Conner, 2009/11/10]],
  1933. since = [[5.1]],
  1934. example = [[See http://lua-users.org/lists/lua-l/2009-11/msg00463.html]],
  1935. patch = [[
  1936. --- llex.c 2007/12/27 13:02:25 2.20.1.1
  1937. +++ llex.c 2009/11/23 14:49:40
  1938. @@ -118,8 +118,10 @@
  1939. lua_State *L = ls->L;
  1940. TString *ts = luaS_newlstr(L, str, l);
  1941. TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
  1942. - if (ttisnil(o))
  1943. + if (ttisnil(o)) {
  1944. setbvalue(o, 1); /* make sure `str' will not be collected */
  1945. + luaC_checkGC(L);
  1946. + }
  1947. return ts;
  1948. }
  1949. ]]
  1950. }
  1951. Bug{
  1952. what = [['string.format' may get buffer as an argument when there are
  1953. missing arguments and format string is too long]],
  1954. report = [[Roberto I., 2010/04/12]],
  1955. since = [[5.0]],
  1956. example = [[
  1957. x = string.rep("x", 10000) .. "%d"
  1958. print(string.format(x)) -- gives wrong error message
  1959. ]],
  1960. patch = [[
  1961. --- lstrlib.c 2008/07/11 17:27:21 1.132.1.4
  1962. +++ lstrlib.c 2010/05/14 15:12:53
  1963. @@ -754,6 +754,7 @@
  1964. static int str_format (lua_State *L) {
  1965. + int top = lua_gettop(L);
  1966. int arg = 1;
  1967. size_t sfl;
  1968. const char *strfrmt = luaL_checklstring(L, arg, &sfl);
  1969. @@ -768,7 +769,8 @@
  1970. else { /* format item */
  1971. char form[MAX_FORMAT]; /* to store the format (`%...') */
  1972. char buff[MAX_ITEM]; /* to store the formatted item */
  1973. - arg++;
  1974. + if (++arg > top)
  1975. + luaL_argerror(L, arg, "no value");
  1976. strfrmt = scanformat(L, strfrmt, form);
  1977. switch (*strfrmt++) {
  1978. case 'c': {
  1979. ]]
  1980. }
  1981. Bug{
  1982. what = [['io.read(op, "*n")' may return garbage if second read fails]],
  1983. report = [[Roberto I., 2010/04/12]],
  1984. since = [[5.0]],
  1985. example = [[
  1986. print(io.read("*n", "*n")) --<< enter "10 hi"
  1987. --> file (0x884420) nil
  1988. ]],
  1989. patch = [[
  1990. --- liolib.c 2008/01/18 17:47:43 2.73.1.3
  1991. +++ liolib.c 2010/05/14 15:29:29
  1992. @@ -276,7 +276,10 @@
  1993. lua_pushnumber(L, d);
  1994. return 1;
  1995. }
  1996. - else return 0; /* read fails */
  1997. + else {
  1998. + lua_pushnil(L); /* "result" to be removed */
  1999. + return 0; /* read fails */
  2000. + }
  2001. }
  2002. ]]
  2003. }
  2004. Bug{
  2005. what = [[wrong code generation for some particular boolean expressions]],
  2006. report = [[Thierry Van Elsuwe, 2011/01/20]],
  2007. since = [[5.0]],
  2008. example = [[
  2009. print((('hi' or true) and true) or true)
  2010. --> hi (should be true)
  2011. print(((nil and nil) or false) and true)
  2012. --> nil (should be false)
  2013. ]],
  2014. patch = [[
  2015. --- lcode.c 2009/06/15 14:12:25 2.25.1.4
  2016. +++ lcode.c 2011/01/31 14:44:25
  2017. @@ -549,13 +549,6 @@
  2018. pc = e->u.s.info;
  2019. break;
  2020. }
  2021. - case VFALSE: {
  2022. - if (!hasjumps(e)) {
  2023. - pc = luaK_jump(fs); /* always jump */
  2024. - break;
  2025. - }
  2026. - /* else go through */
  2027. - }
  2028. default: {
  2029. pc = jumponcond(fs, e, 0);
  2030. break;
  2031. @@ -579,13 +572,6 @@
  2032. pc = e->u.s.info;
  2033. break;
  2034. }
  2035. - case VTRUE: {
  2036. - if (!hasjumps(e)) {
  2037. - pc = luaK_jump(fs); /* always jump */
  2038. - break;
  2039. - }
  2040. - /* else go through */
  2041. - }
  2042. default: {
  2043. pc = jumponcond(fs, e, 1);
  2044. break;
  2045. ]]
  2046. }
  2047. Bug{
  2048. what = [[__newindex metamethod may not work if metatable is its own
  2049. metatable]],
  2050. report = [[Cuero Bugot, 2011/08/09]],
  2051. since = [[5.1]],
  2052. example = [[
  2053. meta={}
  2054. setmetatable(meta, meta)
  2055. meta.__newindex = function(t, key, value) print("set") end
  2056. o = setmetatable({}, meta)
  2057. o.x = 10 -- should print 'set'
  2058. ]],
  2059. patch = [[
  2060. --- lvm.c 2009/07/01 21:10:33 2.63.1.4
  2061. +++ lvm.c 2011/08/17 20:36:28
  2062. @@ -142,6 +142,7 @@
  2063. if (!ttisnil(oldval) || /* result is no nil? */
  2064. (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
  2065. setobj2t(L, oldval, val);
  2066. + h->flags = 0;
  2067. luaC_barriert(L, h, val);
  2068. return;
  2069. }
  2070. ]]
  2071. }
  2072. Bug{
  2073. what = [[parser may collect a prototype while building it]],
  2074. report = [[Ingo van Lil, 2011/10/13]],
  2075. since = [[5.1.4 (caused by patch 5.1.4-6)]],
  2076. example = nil,
  2077. patch = [[
  2078. --- lparser.c 2007/12/28 15:32:23 2.42.1.3
  2079. +++ lparser.c 2011/10/17 13:10:43
  2080. @@ -374,9 +374,9 @@
  2081. lua_assert(luaG_checkcode(f));
  2082. lua_assert(fs->bl == NULL);
  2083. ls->fs = fs->prev;
  2084. - L->top -= 2; /* remove table and prototype from the stack */
  2085. /* last token read was anchored in defunct function; must reanchor it */
  2086. if (fs) anchor_token(ls);
  2087. + L->top -= 2; /* remove table and prototype from the stack */
  2088. }
  2089. ]]
  2090. }
  2091. -----------------------------------------------------------------
  2092. -- Lua 5.2.0
  2093. Bug{
  2094. what = [[memory hoarding when creating Lua hooks for coroutines]],
  2095. report = [[Arseny Vakhrushev, 2012/01/16]],
  2096. since = [[5.1]],
  2097. example = [[
  2098. collectgarbage(); print(collectgarbage'count' * 1024)
  2099. for i = 1, 100 do
  2100. local co = coroutine.create(function () end)
  2101. local x = {}
  2102. for j=1,1000 do x[j] = j end
  2103. debug.sethook(co, function () return x end, 'l')
  2104. end
  2105. collectgarbage(); print(collectgarbage'count' * 1024)
  2106. -- value should back to near the original level
  2107. ]],
  2108. patch = [[
  2109. -- For 5.2
  2110. --- ldblib.c 2011/10/24 14:54:05 1.131
  2111. +++ ldblib.c 2012/01/18 02:36:59
  2112. @@ -253,14 +253,15 @@
  2113. }
  2114. -#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY);
  2115. +#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
  2116. static void hookf (lua_State *L, lua_Debug *ar) {
  2117. static const char *const hooknames[] =
  2118. {"call", "return", "line", "count", "tail call"};
  2119. gethooktable(L);
  2120. - lua_rawgetp(L, -1, L);
  2121. + lua_pushthread(L);
  2122. + lua_rawget(L, -2);
  2123. if (lua_isfunction(L, -1)) {
  2124. lua_pushstring(L, hooknames[(int)ar->event]);
  2125. if (ar->currentline >= 0)
  2126. @@ -306,10 +307,15 @@
  2127. count = luaL_optint(L, arg+3, 0);
  2128. func = hookf; mask = makemask(smask, count);
  2129. }
  2130. - gethooktable(L);
  2131. + if (gethooktable(L) == 0) { /* creating hook table? */
  2132. + lua_pushstring(L, "k");
  2133. + lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
  2134. + lua_pushvalue(L, -1);
  2135. + lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
  2136. + }
  2137. + lua_pushthread(L1); lua_xmove(L1, L, 1);
  2138. lua_pushvalue(L, arg+1);
  2139. - lua_rawsetp(L, -2, L1); /* set new hook */
  2140. - lua_pop(L, 1); /* remove hook table */
  2141. + lua_rawset(L, -3); /* set new hook */
  2142. lua_sethook(L1, func, mask, count); /* set hooks */
  2143. return 0;
  2144. }
  2145. @@ -325,7 +331,8 @@
  2146. lua_pushliteral(L, "external hook");
  2147. else {
  2148. gethooktable(L);
  2149. - lua_rawgetp(L, -1, L1); /* get hook */
  2150. + lua_pushthread(L1); lua_xmove(L1, L, 1);
  2151. + lua_rawget(L, -2); /* get hook */
  2152. lua_remove(L, -2); /* remove hook table */
  2153. }
  2154. lua_pushstring(L, unmakemask(mask, buff));
  2155. ]]
  2156. }
  2157. Bug{
  2158. what = [[Lexical gets confused with some combination of arithmetic
  2159. operators and hexadecimal numbers]],
  2160. report = [[Alexandra Barros, 2012/01/17]],
  2161. since = [[5.2.0]],
  2162. example = [[print(0xE+1)]],
  2163. patch = [[
  2164. --- llex.c 2011/11/30 12:43:51 2.59
  2165. +++ llex.c 2012/01/20 18:22:50
  2166. @@ -223,12 +223,19 @@
  2167. /* LUA_NUMBER */
  2168. static void read_numeral (LexState *ls, SemInfo *seminfo) {
  2169. + const char *expo = "Ee";
  2170. + int first = ls->current;
  2171. lua_assert(lisdigit(ls->current));
  2172. - do {
  2173. - save_and_next(ls);
  2174. - if (check_next(ls, "EePp")) /* exponent part? */
  2175. + save_and_next(ls);
  2176. + if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
  2177. + expo = "Pp";
  2178. + for (;;) {
  2179. + if (check_next(ls, expo)) /* exponent part? */
  2180. check_next(ls, "+-"); /* optional exponent sign */
  2181. - } while (lislalnum(ls->current) || ls->current == '.');
  2182. + if (lisxdigit(ls->current) || ls->current == '.')
  2183. + save_and_next(ls);
  2184. + else break;
  2185. + }
  2186. save(ls, '\0');
  2187. buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
  2188. if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
  2189. ]]
  2190. }
  2191. Bug{
  2192. what = [[Finalizers may call functions from a dynamic library after
  2193. the library has been unloaded]],
  2194. report = [[Josh Haberman, 2012/04/08]],
  2195. since = [[5.1]],
  2196. example = [[
  2197. local u = setmetatable({}, {__gc = function () foo() end})
  2198. local m = require 'mod' -- 'mod' may be any dynamic library written in C
  2199. foo = m.foo -- 'foo' may be any function from 'mod'
  2200. -- end program; it crashes
  2201. ]],
  2202. patch = [[
  2203. loadlib.c:
  2204. 95c95
  2205. < #define LIBPREFIX "LOADLIB: "
  2206. ---
  2207. > #define CLIBS "_CLIBS"
  2208. 251,266c251,256
  2209. <
  2210. < static void **ll_register (lua_State *L, const char *path) {
  2211. < void **plib;
  2212. < lua_pushfstring(L, "%s%s", LIBPREFIX, path);
  2213. < lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
  2214. < if (!lua_isnil(L, -1)) /* is there an entry? */
  2215. < plib = (void **)lua_touserdata(L, -1);
  2216. < else { /* no entry yet; create one */
  2217. < lua_pop(L, 1); /* remove result from gettable */
  2218. < plib = (void **)lua_newuserdata(L, sizeof(const void *));
  2219. < *plib = NULL;
  2220. < luaL_setmetatable(L, "_LOADLIB");
  2221. < lua_pushfstring(L, "%s%s", LIBPREFIX, path);
  2222. < lua_pushvalue(L, -2);
  2223. < lua_settable(L, LUA_REGISTRYINDEX);
  2224. < }
  2225. ---
  2226. > static void *ll_checkclib (lua_State *L, const char *path) {
  2227. > void *plib;
  2228. > lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
  2229. > lua_getfield(L, -1, path);
  2230. > plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */
  2231. > lua_pop(L, 2); /* pop CLIBS table and 'plib' */
  2232. 270a261,270
  2233. > static void ll_addtoclib (lua_State *L, const char *path, void *plib) {
  2234. > lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
  2235. > lua_pushlightuserdata(L, plib);
  2236. > lua_pushvalue(L, -1);
  2237. > lua_setfield(L, -3, path); /* CLIBS[path] = plib */
  2238. > lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
  2239. > lua_pop(L, 1); /* pop CLIBS table */
  2240. > }
  2241. >
  2242. >
  2243. 272,273c272,273
  2244. < ** __gc tag method: calls library's `ll_unloadlib' function with the lib
  2245. < ** handle
  2246. ---
  2247. > ** __gc tag method for CLIBS table: calls 'll_unloadlib' for all lib
  2248. > ** handles in list CLIBS
  2249. 276,278c276,281
  2250. < void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
  2251. < if (*lib) ll_unloadlib(*lib);
  2252. < *lib = NULL; /* mark library as closed */
  2253. ---
  2254. > int n = luaL_len(L, 1);
  2255. > for (; n >= 1; n--) { /* for each handle, in reverse order */
  2256. > lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */
  2257. > ll_unloadlib(lua_touserdata(L, -1));
  2258. > lua_pop(L, 1); /* pop handle */
  2259. > }
  2260. 284,286c287,292
  2261. < void **reg = ll_register(L, path);
  2262. < if (*reg == NULL) *reg = ll_load(L, path, *sym == '*');
  2263. < if (*reg == NULL) return ERRLIB; /* unable to load library */
  2264. ---
  2265. > void *reg = ll_checkclib(L, path); /* check loaded C libraries */
  2266. > if (reg == NULL) { /* must load library? */
  2267. > reg = ll_load(L, path, *sym == '*');
  2268. > if (reg == NULL) return ERRLIB; /* unable to load library */
  2269. > ll_addtoclib(L, path, reg);
  2270. > }
  2271. 292c298
  2272. < lua_CFunction f = ll_sym(L, *reg, sym);
  2273. ---
  2274. > lua_CFunction f = ll_sym(L, reg, sym);
  2275. 675,676c681,683
  2276. < /* create new type _LOADLIB */
  2277. < luaL_newmetatable(L, "_LOADLIB");
  2278. ---
  2279. > /* create table CLIBS to keep track of loaded C libraries */
  2280. > luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
  2281. > lua_createtable(L, 0, 1); /* metatable for CLIBS */
  2282. 678a686
  2283. > lua_setmetatable(L, -2);
  2284. ]]
  2285. }
  2286. Bug{
  2287. what = [[wrong handling of 'nCcalls' in coroutines]],
  2288. report = [[Alexander Gavrilov, 2012/04/18]],
  2289. since = [[5.2.0]],
  2290. example = [[
  2291. coroutine.wrap(function()
  2292. print(pcall(pcall,pcall,pcall,pcall,pcall,error,3))
  2293. end)()
  2294. ]],
  2295. patch = [[
  2296. --- ldo.c 2011/11/29 15:55:08 2.102
  2297. +++ ldo.c 2012/04/26 20:38:32
  2298. @@ -402,8 +402,6 @@
  2299. int n;
  2300. lua_assert(ci->u.c.k != NULL); /* must have a continuation */
  2301. lua_assert(L->nny == 0);
  2302. - /* finish 'luaD_call' */
  2303. - L->nCcalls--;
  2304. /* finish 'lua_callk' */
  2305. adjustresults(L, ci->nresults);
  2306. /* call continuation function */
  2307. @@ -513,7 +511,6 @@
  2308. api_checknelems(L, n);
  2309. firstArg = L->top - n; /* yield results come from continuation */
  2310. }
  2311. - L->nCcalls--; /* finish 'luaD_call' */
  2312. luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
  2313. }
  2314. unroll(L, NULL);
  2315. ]]
  2316. }
  2317. Bug{
  2318. what = [[Internal Lua values may escape through the debug API]],
  2319. report = [[Dan Tull, 2012/04/20]],
  2320. since = [[5.1]],
  2321. example = [[
  2322. -- for Lua 5.1
  2323. local firsttime = true
  2324. local function foo ()
  2325. if firsttime then
  2326. firsttime = false
  2327. return "a = 1"
  2328. else
  2329. for i = 1, 10 do
  2330. print(debug.getlocal(2, i))
  2331. end
  2332. end
  2333. end
  2334. print(load(foo)) -- prints some lines and then seg. fault.
  2335. ]],
  2336. patch = [[
  2337. ]]
  2338. }
  2339. Bug{
  2340. what = [[Problems when yielding from debug hooks]],
  2341. report = [[Erik Cassel, 2012/06/05]],
  2342. since = [[5.2.0]],
  2343. example = [[
  2344. Set, in C, a line hook that simply yields,
  2345. and then call any Lua function.
  2346. You get an infinite loop of yields.
  2347. ]],
  2348. patch = [[
  2349. ]]
  2350. }
  2351. --[=[
  2352. Bug{
  2353. what = [[ ]],
  2354. report = [[ ]],
  2355. since = [[ ]],
  2356. example = [[ ]],
  2357. patch = [[
  2358. ]]
  2359. }
  2360. ]=]