bugs 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617
  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 = "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 = "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]],
  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]],
  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 = [[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 = [[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 = [[5.1]],
  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. @@ -161,7 +161,9 @@
  1606. static Proto* LoadFunction(LoadState* S, TString* p)
  1607. {
  1608. - Proto* f=luaF_newproto(S->L);
  1609. + Proto* f;
  1610. + if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
  1611. + f=luaF_newproto(S->L);
  1612. setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
  1613. f->source=LoadString(S); if (f->source==NULL) f->source=p;
  1614. f->linedefined=LoadInt(S);
  1615. @@ -175,6 +177,7 @@
  1616. LoadDebug(S,f);
  1617. IF (!luaG_checkcode(f), "bad code");
  1618. S->L->top--;
  1619. + S->L->nCcalls--;
  1620. return f;
  1621. }
  1622. ]],
  1623. }
  1624. Bug{
  1625. what = [[code validator may reject (maliciously crafted) correct code]],
  1626. report = [[Greg Falcon, on 2008/03/26]],
  1627. since = [[5.0]],
  1628. example = [[
  1629. z={}
  1630. for i=1,27290 do z[i]='1,' end
  1631. z = 'if 1+1==2 then local a={' .. table.concat(z) .. '} end'
  1632. func = loadstring(z)
  1633. print(loadstring(string.dump(func)))
  1634. ]],
  1635. patch = [[
  1636. --- ldebug.c 2008/04/04 15:30:05 2.29.1.4
  1637. +++ ldebug.c 2008/04/04 15:47:10
  1638. @@ -346,9 +346,18 @@
  1639. int dest = pc+1+b;
  1640. check(0 <= dest && dest < pt->sizecode);
  1641. if (dest > 0) {
  1642. - /* cannot jump to a setlist count */
  1643. - Instruction d = pt->code[dest-1];
  1644. - check(!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0));
  1645. + int j;
  1646. + /* check that it does not jump to a setlist count; this
  1647. + is tricky, because the count from a previous setlist may
  1648. + have the same value of an invalid setlist; so, we must
  1649. + go all the way back to the first of them (if any) */
  1650. + for (j = 0; j < dest; j++) {
  1651. + Instruction d = pt->code[dest-1-j];
  1652. + if (!(GET_OPCODE(d) == OP_SETLIST && GETARG_C(d) == 0)) break;
  1653. + }
  1654. + /* if 'j' is even, previous value is not a setlist (even if
  1655. + it looks like one) */
  1656. + check((j&1) == 0);
  1657. }
  1658. }
  1659. break;
  1660. ]],
  1661. }
  1662. Bug{
  1663. what = [[maliciously crafted precompiled code can inject invalid boolean
  1664. values into Lua code]],
  1665. report = [[Greg Falcon, on 2008/03/27]],
  1666. since = [[5.0]],
  1667. example = [[
  1668. maybe = string.dump(function() return ({[true]=true})[true] end)
  1669. maybe = maybe:gsub('\1\1','\1\2')
  1670. maybe = loadstring(maybe)()
  1671. assert(type(maybe) == "boolean" and maybe ~= true and maybe ~= false)
  1672. ]],
  1673. patch = [[
  1674. --- lundump.c 2008/01/18 16:39:11 2.7.1.2
  1675. +++ lundump.c 2008/04/04 15:50:39
  1676. @@ -115,7 +115,7 @@
  1677. setnilvalue(o);
  1678. break;
  1679. case LUA_TBOOLEAN:
  1680. - setbvalue(o,LoadChar(S));
  1681. + setbvalue(o,LoadChar(S)!=0);
  1682. break;
  1683. case LUA_TNUMBER:
  1684. setnvalue(o,LoadNumber(S));
  1685. ]],
  1686. }
  1687. Bug{
  1688. what = [['string.byte' gets confused with some out-of-range negative indices]],
  1689. report = [[Mike Pall, on 2008/06/03]],
  1690. since = [[5.1]],
  1691. example = [[
  1692. print(string.byte("abc", -5)) --> 97 98 99 (should print nothing)
  1693. ]],
  1694. patch = [[
  1695. --- lstrlib.c 2007/12/28 15:32:23 1.132.1.3
  1696. +++ lstrlib.c 2008/07/05 11:53:42
  1697. @@ -35,7 +35,8 @@
  1698. static ptrdiff_t posrelat (ptrdiff_t pos, size_t len) {
  1699. /* relative string position: negative means back from end */
  1700. - return (pos>=0) ? pos : (ptrdiff_t)len+pos+1;
  1701. + if (pos < 0) pos += (ptrdiff_t)len + 1;
  1702. + return (pos >= 0) ? pos : 0;
  1703. }
  1704. ]],
  1705. }
  1706. Bug{
  1707. what = [[user-requested GC step may loop forever]],
  1708. report = [[Makoto Hamanaka, on 2008/07/01]],
  1709. since = [[5.1]],
  1710. example = [[
  1711. collectgarbage("setpause", 100) -- small value
  1712. collectgarbage("setstepmul", 2000) -- large value
  1713. collectgarbage("step",0)
  1714. ]],
  1715. patch = [[
  1716. --- lapi.c 2008/02/14 16:46:39 2.55.1.4
  1717. +++ lapi.c 2008/07/04 18:34:48
  1718. @@ -929,10 +929,13 @@
  1719. g->GCthreshold = g->totalbytes - a;
  1720. else
  1721. g->GCthreshold = 0;
  1722. - while (g->GCthreshold <= g->totalbytes)
  1723. + while (g->GCthreshold <= g->totalbytes) {
  1724. luaC_step(L);
  1725. - if (g->gcstate == GCSpause) /* end of cycle? */
  1726. - res = 1; /* signal it */
  1727. + if (g->gcstate == GCSpause) { /* end of cycle? */
  1728. + res = 1; /* signal it */
  1729. + break;
  1730. + }
  1731. + }
  1732. break;
  1733. }
  1734. case LUA_GCSETPAUSE: {
  1735. ]],
  1736. }
  1737. Bug{
  1738. what = [['module' may change the environment of a C function]],
  1739. report = [[Peter Cawley, on 2008/07/16]],
  1740. since = [[5.1]],
  1741. example = [[
  1742. pcall(module, "xuxu")
  1743. assert(debug.getfenv(pcall) == xuxu)
  1744. ]],
  1745. patch = [[
  1746. --- loadlib.c 2007/12/28 14:58:43 1.52.1.2
  1747. +++ loadlib.c 2008/08/05 19:39:00
  1748. @@ -506,8 +506,11 @@
  1749. static void setfenv (lua_State *L) {
  1750. lua_Debug ar;
  1751. - lua_getstack(L, 1, &ar);
  1752. - lua_getinfo(L, "f", &ar);
  1753. + if (lua_getstack(L, 1, &ar) == 0 ||
  1754. + lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
  1755. + lua_iscfunction(L, -1))
  1756. + luaL_error(L, "function " LUA_QL("module")
  1757. + " not called from a Lua function");
  1758. lua_pushvalue(L, -2);
  1759. lua_setfenv(L, -2);
  1760. lua_pop(L, 1);
  1761. ]],
  1762. }
  1763. Bug{
  1764. what = [[internal macro 'svalue' is wrong]],
  1765. report = [[Martijn van Buul, on 2008/08/04]],
  1766. since = [[5.1]],
  1767. example = [[
  1768. /* in luaconf.h */
  1769. #define LUAI_USER_ALIGNMENT_T union { char b[32]; }
  1770. ]],
  1771. patch = [[
  1772. --- lobject.h 2007/12/27 13:02:25 2.20.1.1
  1773. +++ lobject.h 2008/08/05 19:40:48
  1774. @@ -210,3 +210,3 @@
  1775. #define getstr(ts) cast(const char *, (ts) + 1)
  1776. -#define svalue(o) getstr(tsvalue(o))
  1777. +#define svalue(o) getstr(rawtsvalue(o))
  1778. ]],
  1779. }
  1780. -----------------------------------------------------------------
  1781. -- Lua 5.1.4
  1782. Bug{
  1783. what = [[malicious zero-length string in binary code may segfault Lua]],
  1784. report = [[Peter Cawley, on 2008/09/01]],
  1785. since = [[5.1]],
  1786. example = [[
  1787. loadstring(('').dump(function()X''end):gsub('\2%z%z%zX','\0\0\0'))()
  1788. ]],
  1789. patch = [[
  1790. ]],
  1791. }
  1792. Bug{
  1793. what = [[wrong code generation for some particular boolean expressions]],
  1794. report = [[Brian Kelley, on 2009/04/15]],
  1795. since = [[5.0]],
  1796. example = [[
  1797. print(((1 or false) and true) or false) --> 1
  1798. -- should be 'true'
  1799. ]],
  1800. patch = [[
  1801. --- lcode.c 2007/12/28 15:32:23 2.25.1.3
  1802. +++ lcode.c 2009/06/15 14:07:34
  1803. @@ -544,15 +544,18 @@
  1804. pc = NO_JUMP; /* always true; do nothing */
  1805. break;
  1806. }
  1807. - case VFALSE: {
  1808. - pc = luaK_jump(fs); /* always jump */
  1809. - break;
  1810. - }
  1811. case VJMP: {
  1812. invertjump(fs, e);
  1813. pc = e->u.s.info;
  1814. break;
  1815. }
  1816. + case VFALSE: {
  1817. + if (!hasjumps(e)) {
  1818. + pc = luaK_jump(fs); /* always jump */
  1819. + break;
  1820. + }
  1821. + /* else go through */
  1822. + }
  1823. default: {
  1824. pc = jumponcond(fs, e, 0);
  1825. break;
  1826. @@ -572,14 +575,17 @@
  1827. pc = NO_JUMP; /* always false; do nothing */
  1828. break;
  1829. }
  1830. - case VTRUE: {
  1831. - pc = luaK_jump(fs); /* always jump */
  1832. - break;
  1833. - }
  1834. case VJMP: {
  1835. pc = e->u.s.info;
  1836. break;
  1837. }
  1838. + case VTRUE: {
  1839. + if (!hasjumps(e)) {
  1840. + pc = luaK_jump(fs); /* always jump */
  1841. + break;
  1842. + }
  1843. + /* else go through */
  1844. + }
  1845. default: {
  1846. pc = jumponcond(fs, e, 1);
  1847. break;
  1848. ]],
  1849. }
  1850. Bug{
  1851. what = [['luaV_settable' may invalidate a reference to a table and try
  1852. to reuse it]],
  1853. report = [[Mark Feldman, on 2009/06/27]],
  1854. since = [[5.0]],
  1855. example = [[
  1856. grandparent = {}
  1857. grandparent.__newindex = function(s,_,_) print(s) end
  1858. parent = {}
  1859. parent.__newindex = parent
  1860. setmetatable(parent, grandparent)
  1861. child = setmetatable({}, parent)
  1862. child.foo = 10 --> (crash on some machines)
  1863. ]],
  1864. patch = [[
  1865. --- lvm.c 2007/12/28 15:32:23 2.63.1.3
  1866. +++ lvm.c 2009/07/01 20:36:59
  1867. @@ -133,6 +133,7 @@
  1868. void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
  1869. int loop;
  1870. + TValue temp;
  1871. for (loop = 0; loop < MAXTAGLOOP; loop++) {
  1872. const TValue *tm;
  1873. if (ttistable(t)) { /* `t' is a table? */
  1874. @@ -152,7 +153,9 @@
  1875. callTM(L, tm, t, key, val);
  1876. return;
  1877. }
  1878. - t = tm; /* else repeat with `tm' */
  1879. + /* else repeat with `tm' */
  1880. + setobj(L, &temp, tm); /* avoid pointing inside table (may rehash) */
  1881. + t = &temp;
  1882. }
  1883. luaG_runerror(L, "loop in settable");
  1884. }
  1885. ]],
  1886. }
  1887. Bug{
  1888. what = [[smart use of varargs may create functions that return too
  1889. many arguments and overflow the stack of C functions]],
  1890. report = [[Patrick Donnelly, on 2008/12/10]],
  1891. since = [[]],
  1892. example = [[
  1893. local function lunpack(i, ...)
  1894. if i == 0 then return ...
  1895. else
  1896. return lunpack(i-1, 1, ...)
  1897. end
  1898. end
  1899. Now, if C calls lunpack(n) with a huge n, it may end with
  1900. too many values in its stack and confuse its stack indices.
  1901. ]],
  1902. patch = [[
  1903. ]],
  1904. }
  1905. Bug{
  1906. what = [['debug.getfenv' does not check whether it has an argument]],
  1907. report = [[Patrick Donnelly, 2009/07/30]],
  1908. since = [[5.1]],
  1909. example = [[debug.getfenv() -- should raise an error]],
  1910. patch = [[
  1911. --- ldblib.c 2008/01/21 13:11:21 1.104.1.3
  1912. +++ ldblib.c 2009/08/04 18:43:12
  1913. @@ -45,6 +45,7 @@
  1914. static int db_getfenv (lua_State *L) {
  1915. + luaL_checkany(L, 1);
  1916. lua_getfenv(L, 1);
  1917. return 1;
  1918. }
  1919. ]],
  1920. }
  1921. Bug{
  1922. what = [[GC may get stuck during a parser and avoids proper resizing of
  1923. the string table,
  1924. making its lists grow too much and degrading performance]],
  1925. report = [[Sean Conner, 2009/11/10]],
  1926. since = [[5.1]],
  1927. example = [[See http://lua-users.org/lists/lua-l/2009-11/msg00463.html]],
  1928. patch = [[
  1929. --- llex.c 2007/12/27 13:02:25 2.20.1.1
  1930. +++ llex.c 2009/11/23 14:49:40
  1931. @@ -118,8 +118,10 @@
  1932. lua_State *L = ls->L;
  1933. TString *ts = luaS_newlstr(L, str, l);
  1934. TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
  1935. - if (ttisnil(o))
  1936. + if (ttisnil(o)) {
  1937. setbvalue(o, 1); /* make sure `str' will not be collected */
  1938. + luaC_checkGC(L);
  1939. + }
  1940. return ts;
  1941. }
  1942. ]]
  1943. }
  1944. Bug{
  1945. what = [['string.format' may get buffer as an argument when there are
  1946. missing arguments and format string is too long]],
  1947. report = [[Roberto I., 2010/04/12]],
  1948. since = [[5.0]],
  1949. example = [[
  1950. x = string.rep("x", 10000) .. "%d"
  1951. print(string.format(x)) -- gives wrong error message
  1952. ]],
  1953. patch = [[
  1954. --- lstrlib.c 2008/07/11 17:27:21 1.132.1.4
  1955. +++ lstrlib.c 2010/05/14 15:12:53
  1956. @@ -754,6 +754,7 @@
  1957. static int str_format (lua_State *L) {
  1958. + int top = lua_gettop(L);
  1959. int arg = 1;
  1960. size_t sfl;
  1961. const char *strfrmt = luaL_checklstring(L, arg, &sfl);
  1962. @@ -768,7 +769,8 @@
  1963. else { /* format item */
  1964. char form[MAX_FORMAT]; /* to store the format (`%...') */
  1965. char buff[MAX_ITEM]; /* to store the formatted item */
  1966. - arg++;
  1967. + if (++arg > top)
  1968. + luaL_argerror(L, arg, "no value");
  1969. strfrmt = scanformat(L, strfrmt, form);
  1970. switch (*strfrmt++) {
  1971. case 'c': {
  1972. ]]
  1973. }
  1974. Bug{
  1975. what = [['io.read(op, "*n")' may return garbage if second read fails]],
  1976. report = [[Roberto I., 2010/04/12]],
  1977. since = [[5.0]],
  1978. example = [[
  1979. print(io.read("*n", "*n")) --<< enter "10 hi"
  1980. --> file (0x884420) nil
  1981. ]],
  1982. patch = [[
  1983. --- liolib.c 2008/01/18 17:47:43 2.73.1.3
  1984. +++ liolib.c 2010/05/14 15:29:29
  1985. @@ -276,7 +276,10 @@
  1986. lua_pushnumber(L, d);
  1987. return 1;
  1988. }
  1989. - else return 0; /* read fails */
  1990. + else {
  1991. + lua_pushnil(L); /* "result" to be removed */
  1992. + return 0; /* read fails */
  1993. + }
  1994. }
  1995. ]]
  1996. }
  1997. Bug{
  1998. what = [[wrong code generation for some particular boolean expressions]],
  1999. report = [[Thierry Van Elsuwe, 2011/01/20]],
  2000. since = [[5.0]],
  2001. example = [[
  2002. print((('hi' or true) and true) or true)
  2003. --> hi (should be true)
  2004. print(((nil and nil) or false) and true)
  2005. --> nil (should be false)
  2006. ]],
  2007. patch = [[
  2008. --- lcode.c 2009/06/15 14:12:25 2.25.1.4
  2009. +++ lcode.c 2011/01/31 14:44:25
  2010. @@ -549,13 +549,6 @@
  2011. pc = e->u.s.info;
  2012. break;
  2013. }
  2014. - case VFALSE: {
  2015. - if (!hasjumps(e)) {
  2016. - pc = luaK_jump(fs); /* always jump */
  2017. - break;
  2018. - }
  2019. - /* else go through */
  2020. - }
  2021. default: {
  2022. pc = jumponcond(fs, e, 0);
  2023. break;
  2024. @@ -579,13 +572,6 @@
  2025. pc = e->u.s.info;
  2026. break;
  2027. }
  2028. - case VTRUE: {
  2029. - if (!hasjumps(e)) {
  2030. - pc = luaK_jump(fs); /* always jump */
  2031. - break;
  2032. - }
  2033. - /* else go through */
  2034. - }
  2035. default: {
  2036. pc = jumponcond(fs, e, 1);
  2037. break;
  2038. ]]
  2039. }
  2040. Bug{
  2041. what = [[__newindex metamethod may not work if metatable is its own
  2042. metatable]],
  2043. report = [[Cuero Bugot, 2011/08/09]],
  2044. since = [[5.1]],
  2045. example = [[
  2046. meta={}
  2047. setmetatable(meta, meta)
  2048. meta.__newindex = function(t, key, value) print("set") end
  2049. o = setmetatable({}, meta)
  2050. o.x = 10 -- should print 'set'
  2051. ]],
  2052. patch = [[
  2053. --- lvm.c 2009/07/01 21:10:33 2.63.1.4
  2054. +++ lvm.c 2011/08/17 20:36:28
  2055. @@ -142,6 +142,7 @@
  2056. if (!ttisnil(oldval) || /* result is no nil? */
  2057. (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
  2058. setobj2t(L, oldval, val);
  2059. + h->flags = 0;
  2060. luaC_barriert(L, h, val);
  2061. return;
  2062. }
  2063. ]]
  2064. }
  2065. Bug{
  2066. what = [[parser may collect a prototype while building it]],
  2067. report = [[Ingo van Lil, 2011/10/13]],
  2068. since = [[5.1.4 (caused by patch 5.1.4-6)]],
  2069. example = nil,
  2070. patch = [[
  2071. --- lparser.c 2007/12/28 15:32:23 2.42.1.3
  2072. +++ lparser.c 2011/10/17 13:10:43
  2073. @@ -374,9 +374,9 @@
  2074. lua_assert(luaG_checkcode(f));
  2075. lua_assert(fs->bl == NULL);
  2076. ls->fs = fs->prev;
  2077. - L->top -= 2; /* remove table and prototype from the stack */
  2078. /* last token read was anchored in defunct function; must reanchor it */
  2079. if (fs) anchor_token(ls);
  2080. + L->top -= 2; /* remove table and prototype from the stack */
  2081. }
  2082. ]]
  2083. }
  2084. Bug{
  2085. what = [[When loading a file,
  2086. Lua may call the reader function again after it returned end of input
  2087. ]],
  2088. report = [[Chris Howie, 2013/06/05]],
  2089. since = [[5.1]],
  2090. fix = [[5.2]],
  2091. example = [[
  2092. load(function () print("called"); return nil end)
  2093. --> called
  2094. --> called (should be called only once!)
  2095. ]],
  2096. patch = [[
  2097. --- lzio.h 2007/12/27 13:02:25 1.21.1.1
  2098. +++ lzio.h 2013/07/04 13:55:59
  2099. @@ -59,6 +59,7 @@
  2100. lua_Reader reader;
  2101. void* data; /* additional data */
  2102. lua_State *L; /* Lua state (for reader) */
  2103. + int eoz; /* true if reader has no more data */
  2104. };
  2105. --- lzio.c 2007/12/27 13:02:25 1.31.1.1
  2106. +++ lzio.c 2013/07/04 13:53:06
  2107. @@ -22,10 +22,14 @@
  2108. size_t size;
  2109. lua_State *L = z->L;
  2110. const char *buff;
  2111. + if (z->eoz) return EOZ;
  2112. lua_unlock(L);
  2113. buff = z->reader(L, z->data, &size);
  2114. lua_lock(L);
  2115. - if (buff == NULL || size == 0) return EOZ;
  2116. + if (buff == NULL || size == 0) {
  2117. + z->eoz = 1; /* avoid calling reader function next time */
  2118. + return EOZ;
  2119. + }
  2120. z->n = size - 1;
  2121. z->p = buff;
  2122. return char2int(*(z->p++));
  2123. @@ -51,6 +55,7 @@
  2124. z->data = data;
  2125. z->n = 0;
  2126. z->p = NULL;
  2127. + z->eoz = 0;
  2128. }
  2129. ]]
  2130. }
  2131. -----------------------------------------------------------------
  2132. -- Lua 5.2.0
  2133. Bug{
  2134. what = [[memory hoarding when creating Lua hooks for coroutines]],
  2135. report = [[Arseny Vakhrushev, 2012/01/16]],
  2136. since = [[5.1]],
  2137. fix = [[5.2.1]],
  2138. example = [[
  2139. collectgarbage(); print(collectgarbage'count' * 1024)
  2140. for i = 1, 100 do
  2141. local co = coroutine.create(function () end)
  2142. local x = {}
  2143. for j=1,1000 do x[j] = j end
  2144. debug.sethook(co, function () return x end, 'l')
  2145. end
  2146. collectgarbage(); print(collectgarbage'count' * 1024)
  2147. -- value should back to near the original level
  2148. ]],
  2149. patch = [[
  2150. -- For 5.2
  2151. --- ldblib.c 2011/10/24 14:54:05 1.131
  2152. +++ ldblib.c 2012/01/18 02:36:59
  2153. @@ -253,14 +253,15 @@
  2154. }
  2155. -#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY);
  2156. +#define gethooktable(L) luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)
  2157. static void hookf (lua_State *L, lua_Debug *ar) {
  2158. static const char *const hooknames[] =
  2159. {"call", "return", "line", "count", "tail call"};
  2160. gethooktable(L);
  2161. - lua_rawgetp(L, -1, L);
  2162. + lua_pushthread(L);
  2163. + lua_rawget(L, -2);
  2164. if (lua_isfunction(L, -1)) {
  2165. lua_pushstring(L, hooknames[(int)ar->event]);
  2166. if (ar->currentline >= 0)
  2167. @@ -306,10 +307,15 @@
  2168. count = luaL_optint(L, arg+3, 0);
  2169. func = hookf; mask = makemask(smask, count);
  2170. }
  2171. - gethooktable(L);
  2172. + if (gethooktable(L) == 0) { /* creating hook table? */
  2173. + lua_pushstring(L, "k");
  2174. + lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
  2175. + lua_pushvalue(L, -1);
  2176. + lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
  2177. + }
  2178. + lua_pushthread(L1); lua_xmove(L1, L, 1);
  2179. lua_pushvalue(L, arg+1);
  2180. - lua_rawsetp(L, -2, L1); /* set new hook */
  2181. - lua_pop(L, 1); /* remove hook table */
  2182. + lua_rawset(L, -3); /* set new hook */
  2183. lua_sethook(L1, func, mask, count); /* set hooks */
  2184. return 0;
  2185. }
  2186. @@ -325,7 +331,8 @@
  2187. lua_pushliteral(L, "external hook");
  2188. else {
  2189. gethooktable(L);
  2190. - lua_rawgetp(L, -1, L1); /* get hook */
  2191. + lua_pushthread(L1); lua_xmove(L1, L, 1);
  2192. + lua_rawget(L, -2); /* get hook */
  2193. lua_remove(L, -2); /* remove hook table */
  2194. }
  2195. lua_pushstring(L, unmakemask(mask, buff));
  2196. ]]
  2197. }
  2198. Bug{
  2199. what = [[Lexical gets confused with some combination of arithmetic
  2200. operators and hexadecimal numbers]],
  2201. report = [[Alexandra Barros, 2012/01/17]],
  2202. since = [[5.2.0]],
  2203. fix = [[5.2.1]],
  2204. example = [[print(0xE+1)]],
  2205. patch = [[
  2206. --- llex.c 2011/11/30 12:43:51 2.59
  2207. +++ llex.c 2012/01/20 18:22:50
  2208. @@ -223,12 +223,19 @@
  2209. /* LUA_NUMBER */
  2210. static void read_numeral (LexState *ls, SemInfo *seminfo) {
  2211. + const char *expo = "Ee";
  2212. + int first = ls->current;
  2213. lua_assert(lisdigit(ls->current));
  2214. - do {
  2215. - save_and_next(ls);
  2216. - if (check_next(ls, "EePp")) /* exponent part? */
  2217. + save_and_next(ls);
  2218. + if (first == '0' && check_next(ls, "Xx")) /* hexadecimal? */
  2219. + expo = "Pp";
  2220. + for (;;) {
  2221. + if (check_next(ls, expo)) /* exponent part? */
  2222. check_next(ls, "+-"); /* optional exponent sign */
  2223. - } while (lislalnum(ls->current) || ls->current == '.');
  2224. + if (lisxdigit(ls->current) || ls->current == '.')
  2225. + save_and_next(ls);
  2226. + else break;
  2227. + }
  2228. save(ls, '\0');
  2229. buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
  2230. if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
  2231. ]]
  2232. }
  2233. Bug{
  2234. what = [[Finalizers may call functions from a dynamic library after
  2235. the library has been unloaded]],
  2236. report = [[Josh Haberman, 2012/04/08]],
  2237. since = [[5.1]],
  2238. fix = [[5.2.1]],
  2239. example = [[
  2240. local u = setmetatable({}, {__gc = function () foo() end})
  2241. local m = require 'mod' -- 'mod' may be any dynamic library written in C
  2242. foo = m.foo -- 'foo' may be any function from 'mod'
  2243. -- end program; it crashes
  2244. ]],
  2245. patch = [[
  2246. loadlib.c:
  2247. 95c95
  2248. < #define LIBPREFIX "LOADLIB: "
  2249. ---
  2250. > #define CLIBS "_CLIBS"
  2251. 251,266c251,256
  2252. <
  2253. < static void **ll_register (lua_State *L, const char *path) {
  2254. < void **plib;
  2255. < lua_pushfstring(L, "%s%s", LIBPREFIX, path);
  2256. < lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
  2257. < if (!lua_isnil(L, -1)) /* is there an entry? */
  2258. < plib = (void **)lua_touserdata(L, -1);
  2259. < else { /* no entry yet; create one */
  2260. < lua_pop(L, 1); /* remove result from gettable */
  2261. < plib = (void **)lua_newuserdata(L, sizeof(const void *));
  2262. < *plib = NULL;
  2263. < luaL_setmetatable(L, "_LOADLIB");
  2264. < lua_pushfstring(L, "%s%s", LIBPREFIX, path);
  2265. < lua_pushvalue(L, -2);
  2266. < lua_settable(L, LUA_REGISTRYINDEX);
  2267. < }
  2268. ---
  2269. > static void *ll_checkclib (lua_State *L, const char *path) {
  2270. > void *plib;
  2271. > lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
  2272. > lua_getfield(L, -1, path);
  2273. > plib = lua_touserdata(L, -1); /* plib = CLIBS[path] */
  2274. > lua_pop(L, 2); /* pop CLIBS table and 'plib' */
  2275. 270a261,270
  2276. > static void ll_addtoclib (lua_State *L, const char *path, void *plib) {
  2277. > lua_getfield(L, LUA_REGISTRYINDEX, CLIBS);
  2278. > lua_pushlightuserdata(L, plib);
  2279. > lua_pushvalue(L, -1);
  2280. > lua_setfield(L, -3, path); /* CLIBS[path] = plib */
  2281. > lua_rawseti(L, -2, luaL_len(L, -2) + 1); /* CLIBS[#CLIBS + 1] = plib */
  2282. > lua_pop(L, 1); /* pop CLIBS table */
  2283. > }
  2284. >
  2285. >
  2286. 272,273c272,273
  2287. < ** __gc tag method: calls library's `ll_unloadlib' function with the lib
  2288. < ** handle
  2289. ---
  2290. > ** __gc tag method for CLIBS table: calls 'll_unloadlib' for all lib
  2291. > ** handles in list CLIBS
  2292. 276,278c276,281
  2293. < void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
  2294. < if (*lib) ll_unloadlib(*lib);
  2295. < *lib = NULL; /* mark library as closed */
  2296. ---
  2297. > int n = luaL_len(L, 1);
  2298. > for (; n >= 1; n--) { /* for each handle, in reverse order */
  2299. > lua_rawgeti(L, 1, n); /* get handle CLIBS[n] */
  2300. > ll_unloadlib(lua_touserdata(L, -1));
  2301. > lua_pop(L, 1); /* pop handle */
  2302. > }
  2303. 284,286c287,292
  2304. < void **reg = ll_register(L, path);
  2305. < if (*reg == NULL) *reg = ll_load(L, path, *sym == '*');
  2306. < if (*reg == NULL) return ERRLIB; /* unable to load library */
  2307. ---
  2308. > void *reg = ll_checkclib(L, path); /* check loaded C libraries */
  2309. > if (reg == NULL) { /* must load library? */
  2310. > reg = ll_load(L, path, *sym == '*');
  2311. > if (reg == NULL) return ERRLIB; /* unable to load library */
  2312. > ll_addtoclib(L, path, reg);
  2313. > }
  2314. 292c298
  2315. < lua_CFunction f = ll_sym(L, *reg, sym);
  2316. ---
  2317. > lua_CFunction f = ll_sym(L, reg, sym);
  2318. 675,676c681,683
  2319. < /* create new type _LOADLIB */
  2320. < luaL_newmetatable(L, "_LOADLIB");
  2321. ---
  2322. > /* create table CLIBS to keep track of loaded C libraries */
  2323. > luaL_getsubtable(L, LUA_REGISTRYINDEX, CLIBS);
  2324. > lua_createtable(L, 0, 1); /* metatable for CLIBS */
  2325. 678a686
  2326. > lua_setmetatable(L, -2);
  2327. ]]
  2328. }
  2329. Bug{
  2330. what = [[wrong handling of 'nCcalls' in coroutines]],
  2331. report = [[Alexander Gavrilov, 2012/04/18]],
  2332. since = [[5.2.0]],
  2333. fix = [[5.2.1]],
  2334. example = [[
  2335. coroutine.wrap(function()
  2336. print(pcall(pcall,pcall,pcall,pcall,pcall,error,3))
  2337. end)()
  2338. ]],
  2339. patch = [[
  2340. --- ldo.c 2011/11/29 15:55:08 2.102
  2341. +++ ldo.c 2012/04/26 20:38:32
  2342. @@ -402,8 +402,6 @@
  2343. int n;
  2344. lua_assert(ci->u.c.k != NULL); /* must have a continuation */
  2345. lua_assert(L->nny == 0);
  2346. - /* finish 'luaD_call' */
  2347. - L->nCcalls--;
  2348. /* finish 'lua_callk' */
  2349. adjustresults(L, ci->nresults);
  2350. /* call continuation function */
  2351. @@ -513,7 +511,6 @@
  2352. api_checknelems(L, n);
  2353. firstArg = L->top - n; /* yield results come from continuation */
  2354. }
  2355. - L->nCcalls--; /* finish 'luaD_call' */
  2356. luaD_poscall(L, firstArg); /* finish 'luaD_precall' */
  2357. }
  2358. unroll(L, NULL);
  2359. ]]
  2360. }
  2361. Bug{
  2362. what = [[Internal Lua values may escape through the debug API]],
  2363. report = [[Dan Tull, 2012/04/20]],
  2364. since = [[5.1]],
  2365. fix = [[5.2.1]],
  2366. example = [[
  2367. -- for Lua 5.1
  2368. local firsttime = true
  2369. local function foo ()
  2370. if firsttime then
  2371. firsttime = false
  2372. return "a = 1"
  2373. else
  2374. for i = 1, 10 do
  2375. print(debug.getlocal(2, i))
  2376. end
  2377. end
  2378. end
  2379. print(load(foo)) -- prints some lines and then seg. fault.
  2380. ]],
  2381. patch = [[
  2382. ]]
  2383. }
  2384. Bug{
  2385. what = [[Problems when yielding from debug hooks]],
  2386. report = [[Erik Cassel, 2012/06/05]],
  2387. since = [[5.2.0]],
  2388. fix = [[5.2.1]],
  2389. example = [[
  2390. Set, in C, a line hook that simply yields,
  2391. and then call any Lua function.
  2392. You get an infinite loop of yields.
  2393. ]],
  2394. patch = [[
  2395. ]]
  2396. }
  2397. -----------------------------------------------------------------
  2398. -- Lua 5.2.1
  2399. Bug{
  2400. what = [[Some patterns can overflow the C stack, due to recursion]],
  2401. report = [[Tim Starling, 2012/07/08]],
  2402. since = [[2.5]],
  2403. fix = [[5.2.2]],
  2404. example = [[print(string.find(string.rep("a", 2^20), string.rep(".?", 2^20)))]],
  2405. patch = [[
  2406. ]]
  2407. }
  2408. Bug{
  2409. what = [['pcall' may not restore previous error function when
  2410. inside coroutines]],
  2411. report = [[Alexander Gavrilov, 2012/06/12]],
  2412. since = [[5.2.0]],
  2413. fix = [[5.2.2]],
  2414. example = [[
  2415. function errfunc(x)
  2416. return 'errfunc'
  2417. end
  2418. function test(do_yield)
  2419. print(do_yield and "yielding" or "not yielding")
  2420. pcall(function() -- this pcall sets errfunc back to none
  2421. if do_yield then
  2422. coroutine.yield() -- stops errfunc from being restored
  2423. end
  2424. end)
  2425. error('fail!')
  2426. end
  2427. coro = coroutine.wrap(function()
  2428. print(xpcall(test, errfunc, false))
  2429. print(xpcall(test, errfunc, true))
  2430. print(xpcall(test, errfunc, false))
  2431. end)
  2432. coro()
  2433. --> not yielding
  2434. --> false errfunc
  2435. --> yielding
  2436. coro()
  2437. --> false temp:12: fail! <<<< should be 'errfunc' too
  2438. --> not yielding
  2439. --> false errfunc
  2440. ]],
  2441. patch = [[
  2442. --- ldo.c 2012/08/28 18:30:45 2.107
  2443. +++ ldo.c 2012/09/23 15:49:55
  2444. @@ -403,7 +403,11 @@
  2445. int n;
  2446. lua_assert(ci->u.c.k != NULL); /* must have a continuation */
  2447. lua_assert(L->nny == 0);
  2448. - /* finish 'lua_callk' */
  2449. + if (ci->callstatus & CIST_YPCALL) { /* was inside a pcall? */
  2450. + ci->callstatus &= ~CIST_YPCALL; /* finish 'lua_pcall' */
  2451. + L->errfunc = ci->u.c.old_errfunc;
  2452. + }
  2453. + /* finish 'lua_callk'/'lua_pcall' */
  2454. adjustresults(L, ci->nresults);
  2455. /* call continuation function */
  2456. if (!(ci->callstatus & CIST_STAT)) /* no call status? */
  2457. ]]
  2458. }
  2459. Bug{
  2460. what = [[Check for garbage collector in function calls does not cover
  2461. all paths]],
  2462. report = [[Roberto, 2012/08/15]],
  2463. since = [[5.2.1]],
  2464. fix = [[5.2.2]],
  2465. example = [[
  2466. See <a href="http://lua-users.org/lists/lua-l/2012-08/msg00149.html">
  2467. http://lua-users.org/lists/lua-l/2012-08/msg00149.html</a>
  2468. ]],
  2469. patch = [[
  2470. @@ -311,6 +311,7 @@
  2471. ci->top = L->top + LUA_MINSTACK;
  2472. lua_assert(ci->top <= L->stack_last);
  2473. ci->callstatus = 0;
  2474. + luaC_checkGC(L); /* stack grow uses memory */
  2475. if (L->hookmask & LUA_MASKCALL)
  2476. luaD_hook(L, LUA_HOOKCALL, -1);
  2477. lua_unlock(L);
  2478. @@ -338,6 +339,7 @@
  2479. ci->u.l.savedpc = p->code; /* starting point */
  2480. ci->callstatus = CIST_LUA;
  2481. L->top = ci->top;
  2482. + luaC_checkGC(L); /* stack grow uses memory */
  2483. if (L->hookmask & LUA_MASKCALL)
  2484. callhook(L, ci);
  2485. return 0;
  2486. @@ -393,7 +395,6 @@
  2487. luaV_execute(L); /* call it */
  2488. if (!allowyield) L->nny--;
  2489. L->nCcalls--;
  2490. - luaC_checkGC(L);
  2491. }
  2492. ]]
  2493. }
  2494. Bug{
  2495. what = [[load/loadfile returns wrong result when given an environment
  2496. for a binary chunk with no upvalues]],
  2497. report = [[Vladimir Strakh, 2012/11/28]],
  2498. since = [[5.2.0]],
  2499. fix = [[5.2.2]],
  2500. example = [[
  2501. f = load(string.dump(function () return 1 end), nil, "b", {})
  2502. print(type(f)) --> table (whould be a function)
  2503. ]],
  2504. patch = [[
  2505. --- lbaselib.c 2012/04/27 14:13:19 1.274
  2506. +++ lbaselib.c 2012/12/03 20:08:15
  2507. @@ -244,5 +244,11 @@
  2508. -static int load_aux (lua_State *L, int status) {
  2509. - if (status == LUA_OK)
  2510. +static int load_aux (lua_State *L, int status, int envidx) {
  2511. + if (status == LUA_OK) {
  2512. + if (envidx != 0) { /* 'env' parameter? */
  2513. + lua_pushvalue(L, envidx); /* environment for loaded function */
  2514. + if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
  2515. + lua_pop(L, 1); /* remove 'env' if not used by previous call */
  2516. + }
  2517. return 1;
  2518. + }
  2519. else {
  2520. @@ -258,9 +264,5 @@
  2521. const char *mode = luaL_optstring(L, 2, NULL);
  2522. - int env = !lua_isnone(L, 3); /* 'env' parameter? */
  2523. + int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
  2524. int status = luaL_loadfilex(L, fname, mode);
  2525. - if (status == LUA_OK && env) { /* 'env' parameter? */
  2526. - lua_pushvalue(L, 3);
  2527. - lua_setupvalue(L, -2, 1); /* set it as 1st upvalue of loaded chunk */
  2528. - }
  2529. - return load_aux(L, status);
  2530. + return load_aux(L, status, env);
  2531. }
  2532. @@ -309,5 +311,5 @@
  2533. size_t l;
  2534. - int top = lua_gettop(L);
  2535. const char *s = lua_tolstring(L, 1, &l);
  2536. const char *mode = luaL_optstring(L, 3, "bt");
  2537. + int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
  2538. if (s != NULL) { /* loading a string? */
  2539. @@ -322,7 +324,3 @@
  2540. }
  2541. - if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */
  2542. - lua_pushvalue(L, 4); /* environment for loaded function */
  2543. - lua_setupvalue(L, -2, 1); /* set it as 1st upvalue */
  2544. - }
  2545. - return load_aux(L, status);
  2546. + return load_aux(L, status, env);
  2547. }
  2548. ]]
  2549. }
  2550. -----------------------------------------------------------------
  2551. -- Lua 5.2.2
  2552. Bug{
  2553. what = [[stack overflow in vararg functions with many fixed
  2554. parameters called with few arguments]],
  2555. report = [[云风, 2013/04/17]],
  2556. since = [[5.1]],
  2557. fix = [[5.2.3]],
  2558. example = [[
  2559. function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
  2560. p11, p12, p13, p14, p15, p16, p17, p18, p19, p20,
  2561. p21, p22, p23, p24, p25, p26, p27, p28, p29, p30,
  2562. p31, p32, p33, p34, p35, p36, p37, p38, p39, p40,
  2563. p41, p42, p43, p44, p45, p46, p48, p49, p50, ...)
  2564. local a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14
  2565. end
  2566. f() -- seg. fault (on some machines)
  2567. ]],
  2568. patch = [[
  2569. --- ldo.c 2012/10/01 14:05:04 2.108
  2570. +++ ldo.c 2013/04/19 20:56:06
  2571. @@ -324,7 +324,7 @@
  2572. case LUA_TLCL: { /* Lua function: prepare its call */
  2573. StkId base;
  2574. Proto *p = clLvalue(func)->p;
  2575. - luaD_checkstack(L, p->maxstacksize);
  2576. + luaD_checkstack(L, p->maxstacksize + p->numparams);
  2577. func = restorestack(L, funcr);
  2578. n = cast_int(L->top - func) - 1; /* number of real arguments */
  2579. for (; n < p->numparams; n++)
  2580. ]],
  2581. }
  2582. Bug{
  2583. what = [[garbage collector can trigger too many times in recursive loops]],
  2584. report = [[Roberto, 2013/04/25]],
  2585. since = [[5.2.2]],
  2586. fix = [[5.2.3]],
  2587. example = [[
  2588. function f() f() end
  2589. f() -- it takes too long before a "stack overflow" error
  2590. ]],
  2591. patch = [[
  2592. --- lgc.c 2013/04/12 18:48:47 2.140.1.1
  2593. +++ lgc.c 2013/04/25 21:30:20
  2594. @@ -495,2 +495,3 @@
  2595. static lu_mem traversestack (global_State *g, lua_State *th) {
  2596. + int n = 0;
  2597. StkId o = th->stack;
  2598. @@ -505,3 +506,9 @@
  2599. }
  2600. - return sizeof(lua_State) + sizeof(TValue) * th->stacksize;
  2601. + else { /* count call infos to compute size */
  2602. + CallInfo *ci;
  2603. + for (ci = &th->base_ci; ci != th->ci; ci = ci->next)
  2604. + n++;
  2605. + }
  2606. + return sizeof(lua_State) + sizeof(TValue) * th->stacksize +
  2607. + sizeof(CallInfo) * n;
  2608. }
  2609. ]]
  2610. }
  2611. -- [[]]
  2612. Bug{
  2613. what = [[Wrong assert when reporting concatenation errors
  2614. (manifests only when Lua is compiled in debug mode)]],
  2615. report = [[Roberto, 2013/05/05]],
  2616. since = [[?]],
  2617. fix = [[5.2.3]],
  2618. example = [[
  2619. -- only with Lua compiled in debug mode
  2620. print({} .. 2)
  2621. ]],
  2622. patch = [[
  2623. --- ldebug.c 2013/04/12 18:48:47 2.90.1.1
  2624. +++ ldebug.c 2013/05/05 14:38:30
  2625. @@ -519,5 +519,5 @@
  2626. l_noret luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
  2627. if (ttisstring(p1) || ttisnumber(p1)) p1 = p2;
  2628. - lua_assert(!ttisstring(p1) && !ttisnumber(p2));
  2629. + lua_assert(!ttisstring(p1) && !ttisnumber(p1));
  2630. luaG_typeerror(L, p1, "concatenate");
  2631. }
  2632. ]]
  2633. }
  2634. Bug{
  2635. what = [[Wrong error message in some short-cut expressions]],
  2636. report = [[Egor Skriptunoff, 2013/05/10]],
  2637. since = [[5.0]],
  2638. fix = [[5.2.3]],
  2639. example = [[
  2640. > a,b,c = true,true,true
  2641. > (a and b or c)('', '')
  2642. stdin:1: attempt to call a boolean value (global 'c')
  2643. (It should be global 'b' instead of 'c'.)
  2644. ]],
  2645. patch = [[
  2646. --- ldebug.c 2013/05/06 17:20:22 2.90.1.2
  2647. +++ ldebug.c 2013/05/14 19:52:48
  2648. @@ -327,12 +327,20 @@
  2649. }
  2650. +static int filterpc (int pc, int jmptarget) {
  2651. + if (pc < jmptarget) /* is code conditional (inside a jump)? */
  2652. + return -1; /* cannot know who sets that register */
  2653. + else return pc; /* current position sets that register */
  2654. +}
  2655. +
  2656. +
  2657. /*
  2658. ** try to find last instruction before 'lastpc' that modified register 'reg'
  2659. */
  2660. static int findsetreg (Proto *p, int lastpc, int reg) {
  2661. int pc;
  2662. int setreg = -1; /* keep last instruction that changed 'reg' */
  2663. + int jmptarget = 0; /* any code before this address is conditional */
  2664. for (pc = 0; pc < lastpc; pc++) {
  2665. Instruction i = p->code[pc];
  2666. OpCode op = GET_OPCODE(i);
  2667. @@ -341,33 +349,38 @@
  2668. case OP_LOADNIL: {
  2669. int b = GETARG_B(i);
  2670. if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
  2671. - setreg = pc;
  2672. + setreg = filterpc(pc, jmptarget);
  2673. break;
  2674. }
  2675. case OP_TFORCALL: {
  2676. - if (reg >= a + 2) setreg = pc; /* affect all regs above its base */
  2677. + if (reg >= a + 2) /* affect all regs above its base */
  2678. + setreg = filterpc(pc, jmptarget);
  2679. break;
  2680. }
  2681. case OP_CALL:
  2682. case OP_TAILCALL: {
  2683. - if (reg >= a) setreg = pc; /* affect all registers above base */
  2684. + if (reg >= a) /* affect all registers above base */
  2685. + setreg = filterpc(pc, jmptarget);
  2686. break;
  2687. }
  2688. case OP_JMP: {
  2689. int b = GETARG_sBx(i);
  2690. int dest = pc + 1 + b;
  2691. /* jump is forward and do not skip `lastpc'? */
  2692. - if (pc < dest && dest <= lastpc)
  2693. - pc += b; /* do the jump */
  2694. + if (pc < dest && dest <= lastpc) {
  2695. + if (dest > jmptarget)
  2696. + jmptarget = dest; /* update 'jmptarget' */
  2697. + }
  2698. break;
  2699. }
  2700. case OP_TEST: {
  2701. - if (reg == a) setreg = pc; /* jumped code can change 'a' */
  2702. + if (reg == a) /* jumped code can change 'a' */
  2703. + setreg = filterpc(pc, jmptarget);
  2704. break;
  2705. }
  2706. default:
  2707. if (testAMode(op) && reg == a) /* any instruction that set A */
  2708. - setreg = pc;
  2709. + setreg = filterpc(pc, jmptarget);
  2710. break;
  2711. }
  2712. }
  2713. ]]
  2714. }
  2715. Bug{
  2716. what = [[luac listings choke on long strings]],
  2717. report = [[Ashwin Hirschi, 2013/07/03]],
  2718. since = [[5.1.2]],
  2719. fix = [[5.2.3]],
  2720. example = [[
  2721. -- When you call 'luac -l' over this chunk, it chokes the output
  2722. s="Lorem ipsum dolor sit amet, consectetur, "
  2723. ]],
  2724. patch = [[
  2725. --- luac.c 2011-11-29 15:46:33 -0200 1.69
  2726. +++ luac.c 2013-07-03 21:26:01 -0300
  2727. @@ -251,7 +251,7 @@
  2728. static void PrintConstant(const Proto* f, int i)
  2729. {
  2730. const TValue* o=&f->k[i];
  2731. - switch (ttype(o))
  2732. + switch (ttypenv(o))
  2733. {
  2734. case LUA_TNIL:
  2735. printf("nil");
  2736. ]]
  2737. }
  2738. Bug{
  2739. what = [[GC can collect a long string still in use during parser]],
  2740. report = [[Roberto, 2013/08/30]],
  2741. since = [[5.2]],
  2742. fix = [[5.2.3]],
  2743. example = [[This bug is very difficult to happen (and to reproduce),
  2744. because it depends on the GC running in a very specific way when
  2745. parsing a source code with long (larger than 40 characters) identifiers.]],
  2746. patch = [[
  2747. --- ltable.h 2013/04/12 18:48:47 2.16.1.1
  2748. +++ ltable.h 2013/08/30 15:34:24
  2749. @@ -18,4 +18,8 @@
  2750. #define invalidateTMcache(t) ((t)->flags = 0)
  2751. +/* returns the key, given the value of a table entry */
  2752. +#define keyfromval(v) \
  2753. + (gkey(cast(Node *, cast(char *, (v)) - offsetof(Node, i_val))))
  2754. +
  2755. LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
  2756. --- llex.c 2013/04/12 18:48:47 2.63.1.1
  2757. +++ llex.c 2013/08/30 15:34:59
  2758. @@ -134,4 +134,7 @@
  2759. luaC_checkGC(L);
  2760. }
  2761. + else { /* string already present */
  2762. + ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */
  2763. + }
  2764. L->top--; /* remove string from stack */
  2765. return ts;
  2766. ]]
  2767. }
  2768. Bug{
  2769. what = [[Call to macro 'luai_userstateclose' should be done only
  2770. after the calls to __gc methods.]],
  2771. report = [[Jean-Luc Jumpertz, 2013/09/02]],
  2772. since = [[ ]],
  2773. fix = nil,
  2774. example = [[No example]],
  2775. patch = [[
  2776. --- lstate.c 2013/04/12 18:48:47 2.99.1.1
  2777. +++ lstate.c 2013/11/08 17:39:57
  2778. @@ -194,2 +194,4 @@
  2779. g->gcrunning = 1; /* allow gc */
  2780. + g->version = lua_version(NULL);
  2781. + luai_userstateopen(L);
  2782. }
  2783. @@ -224,2 +226,4 @@
  2784. luaC_freeallobjects(L); /* collect all objects */
  2785. + if (g->version) /* closing a fully built state? */
  2786. + luai_userstateclose(L);
  2787. luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
  2788. @@ -289,3 +293,3 @@
  2789. g->panic = NULL;
  2790. - g->version = lua_version(NULL);
  2791. + g->version = NULL;
  2792. g->gcstate = GCSpause;
  2793. @@ -308,4 +312,2 @@
  2794. }
  2795. - else
  2796. - luai_userstateopen(L);
  2797. return L;
  2798. @@ -317,3 +319,2 @@
  2799. lua_lock(L);
  2800. - luai_userstateclose(L);
  2801. close_state(L);
  2802. ]]
  2803. }
  2804. Bug{
  2805. what = [[Resuming the running coroutine makes it unyieldable]],
  2806. report = [[Florian Nücke, 2013/10/28]],
  2807. since = [[5.2]],
  2808. fix = [[5.2.3]],
  2809. example = [[
  2810. -- should print 'true'
  2811. print(coroutine.resume(coroutine.create(function()
  2812. coroutine.resume(coroutine.running())
  2813. coroutine.yield()
  2814. end)))
  2815. ]],
  2816. patch = [[
  2817. --- ldo.c 2013/04/19 21:03:23 2.108.1.2
  2818. +++ ldo.c 2013/11/08 18:20:57
  2819. @@ -536,2 +536,3 @@
  2820. int status;
  2821. + int oldnny = L->nny; /* save 'nny' */
  2822. lua_lock(L);
  2823. @@ -557,3 +558,3 @@
  2824. }
  2825. - L->nny = 1; /* do not allow yields */
  2826. + L->nny = oldnny; /* restore 'nny' */
  2827. L->nCcalls--;
  2828. ]]
  2829. }
  2830. -----------------------------------------------------------------
  2831. -- Lua 5.2.3
  2832. Bug{
  2833. what = [[compiler can optimize away overflow check in 'table.unpack']],
  2834. report = [[Paige DePol, 2014/03/30]],
  2835. since = [[5.1 (at least)]],
  2836. fix = nil,
  2837. example = [[
  2838. > unpack({}, 0, 2^31 - 1)
  2839. (segfaults on some platforms with some compiler options)
  2840. ]],
  2841. patch = [[
  2842. --- ltablib.c 2013/04/12 18:48:47 1.65.1.1
  2843. +++ ltablib.c 2014/05/07 16:32:55 1.65.1.2
  2844. @@ -134,13 +135,14 @@
  2845. static int unpack (lua_State *L) {
  2846. - int i, e, n;
  2847. + int i, e;
  2848. + unsigned int n;
  2849. luaL_checktype(L, 1, LUA_TTABLE);
  2850. i = luaL_optint(L, 2, 1);
  2851. e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1));
  2852. if (i > e) return 0; /* empty range */
  2853. - n = e - i + 1; /* number of elements */
  2854. - if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
  2855. + n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
  2856. + if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n))
  2857. return luaL_error(L, "too many results to unpack");
  2858. lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
  2859. while (i++ < e) /* push arg[i + 1...e] */
  2860. ]]
  2861. }
  2862. Bug{
  2863. what = [[Ephemeron table can wrongly collect entry with strong key]],
  2864. report = [[Jörg Richter, 2014/08/22]],
  2865. since = [[5.2]],
  2866. fix = nil,
  2867. example = [[
  2868. (This bug is very hard to reproduce,
  2869. because it depends on a specific interleaving of
  2870. events between the incremental collector and the program.)
  2871. ]],
  2872. patch = [[
  2873. --- lgc.c 2013/04/26 18:22:05 2.140.1.2
  2874. +++ lgc.c 2014/09/01 13:24:33
  2875. @@ -403,7 +403,7 @@
  2876. reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
  2877. }
  2878. }
  2879. - if (prop)
  2880. + if (g->gcstate != GCSatomic || prop)
  2881. linktable(h, &g->ephemeron); /* have to propagate again */
  2882. else if (hasclears) /* does table have white keys? */
  2883. linktable(h, &g->allweak); /* may have to clean white keys */
  2884. ]]
  2885. }
  2886. Bug{
  2887. what = [[Chunk with too many lines can seg. fault]],
  2888. report = [[Roberto, 2014/11/14]],
  2889. since = [[5.1 (at least)]],
  2890. fix = nil,
  2891. example = [[
  2892. -- the cause of the bug is the use of an unitialized variable, so
  2893. -- it cannot be reproduced reliably
  2894. local s = string.rep("\n", 2^24)
  2895. print(load(function () return s end))
  2896. ]],
  2897. patch = [[
  2898. --- llex.c 2013/08/30 15:49:41 2.63.1.2
  2899. +++ llex.c 2015/02/09 17:05:31
  2900. @@ -153,5 +153,5 @@
  2901. next(ls); /* skip `\n\r' or `\r\n' */
  2902. if (++ls->linenumber >= MAX_INT)
  2903. - luaX_syntaxerror(ls, "chunk has too many lines");
  2904. + lexerror(ls, "chunk has too many lines", 0);
  2905. }
  2906. ]]
  2907. }
  2908. -----------------------------------------------------------------
  2909. -- Lua 5.3.0
  2910. Bug{
  2911. what = [['string.format("%f")' can cause a buffer overflow
  2912. (only when 'lua_Number' is long double!)]],
  2913. report = [[Roberto, 2015/01/13]],
  2914. since = [[5.3]],
  2915. fix = nil,
  2916. example = [[string.format("%.99f", 1e4000) -- when floats are long double]],
  2917. patch = [[
  2918. --- lstrlib.c 2014/12/11 14:03:07 1.221
  2919. +++ lstrlib.c 2015/02/23 19:01:42
  2920. @@ -800,3 +800,4 @@
  2921. /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
  2922. -#define MAX_ITEM 512
  2923. +#define MAX_ITEM \
  2924. + (sizeof(lua_Number) <= 4 ? 150 : sizeof(lua_Number) <= 8 ? 450 : 5050)
  2925. ]]
  2926. }
  2927. Bug{
  2928. what = [['debug.getlocal' on a coroutine suspended in a hook
  2929. can crash the interpreter]],
  2930. report = [[云风, 2015/02/11]],
  2931. since = [[5.2]],
  2932. fix = nil,
  2933. example = [[see http://lua-users.org/lists/lua-l/2015-02/msg00146.html]],
  2934. patch = [[
  2935. --- ldebug.c 2015/01/02 12:52:22 2.110
  2936. +++ ldebug.c 2015/02/13 16:03:23
  2937. @@ -49,4 +49,14 @@
  2938. +static void swapextra (lua_State *L) {
  2939. + if (L->status == LUA_YIELD) {
  2940. + CallInfo *ci = L->ci; /* get function that yielded */
  2941. + StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
  2942. + ci->func = restorestack(L, ci->extra);
  2943. + ci->extra = savestack(L, temp);
  2944. + }
  2945. +}
  2946. +
  2947. +
  2948. /*
  2949. ** this function can be called asynchronous (e.g. during a signal)
  2950. @@ -145,4 +155,5 @@
  2951. const char *name;
  2952. lua_lock(L);
  2953. + swapextra(L);
  2954. if (ar == NULL) { /* information about non-active function? */
  2955. if (!isLfunction(L->top - 1)) /* not a Lua function? */
  2956. @@ -159,4 +170,5 @@
  2957. }
  2958. }
  2959. + swapextra(L);
  2960. lua_unlock(L);
  2961. return name;
  2962. @@ -166,10 +178,13 @@
  2963. LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
  2964. StkId pos = 0; /* to avoid warnings */
  2965. - const char *name = findlocal(L, ar->i_ci, n, &pos);
  2966. + const char *name;
  2967. lua_lock(L);
  2968. + swapextra(L);
  2969. + name = findlocal(L, ar->i_ci, n, &pos);
  2970. if (name) {
  2971. setobjs2s(L, pos, L->top - 1);
  2972. L->top--; /* pop value */
  2973. }
  2974. + swapextra(L);
  2975. lua_unlock(L);
  2976. return name;
  2977. @@ -271,4 +286,5 @@
  2978. StkId func;
  2979. lua_lock(L);
  2980. + swapextra(L);
  2981. if (*what == '>') {
  2982. ci = NULL;
  2983. @@ -289,4 +305,5 @@
  2984. api_incr_top(L);
  2985. }
  2986. + swapextra(L);
  2987. if (strchr(what, 'L'))
  2988. collectvalidlines(L, cl);
  2989. ]]
  2990. }
  2991. Bug{
  2992. what = [[suspended '__le' metamethod can give wrong result]],
  2993. report = [[Eric Zhong, 2015/04/07]],
  2994. since = [[5.2]],
  2995. fix = nil,
  2996. example = [[
  2997. mt = {__le = function (a,b) coroutine.yield("yield"); return a.x <= b.x end}
  2998. t1 = setmetatable({x=1}, mt)
  2999. t2 = {x=2}
  3000. co = coroutine.wrap(function (a,b) return t2 <= t1 end)
  3001. co()
  3002. print(co()) --> true (should be false)
  3003. ]],
  3004. patch = [[
  3005. --- lstate.h 2014/10/30 18:53:28 2.119
  3006. +++ lstate.h 2015/04/13 15:58:40
  3007. @@ -94,6 +94,7 @@
  3008. #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
  3009. #define CIST_TAIL (1<<5) /* call was tail called */
  3010. #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
  3011. +#define CIST_LEQ (1<<7) /* using __lt for __le */
  3012. #define isLua(ci) ((ci)->callstatus & CIST_LUA)
  3013. --- lvm.c 2014/12/27 20:30:38 2.232
  3014. +++ lvm.c 2015/04/13 15:51:30
  3015. @@ -292,9 +292,14 @@
  3016. return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;
  3017. else if ((res = luaT_callorderTM(L, l, r, TM_LE)) >= 0) /* first try 'le' */
  3018. return res;
  3019. - else if ((res = luaT_callorderTM(L, r, l, TM_LT)) < 0) /* else try 'lt' */
  3020. - luaG_ordererror(L, l, r);
  3021. - return !res;
  3022. + else { /* try 'lt': */
  3023. + L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */
  3024. + res = luaT_callorderTM(L, r, l, TM_LT);
  3025. + L->ci->callstatus ^= CIST_LEQ; /* clear mark */
  3026. + if (res < 0)
  3027. + luaG_ordererror(L, l, r);
  3028. + return !res; /* result is negated */
  3029. + }
  3030. }
  3031. @@ -553,11 +558,11 @@
  3032. case OP_LE: case OP_LT: case OP_EQ: {
  3033. int res = !l_isfalse(L->top - 1);
  3034. L->top--;
  3035. - /* metamethod should not be called when operand is K */
  3036. - lua_assert(!ISK(GETARG_B(inst)));
  3037. - if (op == OP_LE && /* "<=" using "<" instead? */
  3038. - ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
  3039. - res = !res; /* invert result */
  3040. + if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */
  3041. + lua_assert(op == OP_LE);
  3042. + ci->callstatus ^= CIST_LEQ; /* clear mark */
  3043. + res = !res; /* negate result */
  3044. + }
  3045. lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
  3046. if (res != GETARG_A(inst)) /* condition failed? */
  3047. ci->u.l.savedpc++; /* skip jump instruction */
  3048. ]]
  3049. }
  3050. Bug{
  3051. what = [[return hook may not see correct values for
  3052. active local variables when function returns]],
  3053. report = [[Philipp Janda/Peng Yi, 2015/05/19]],
  3054. since = [[5.0]],
  3055. fix = nil,
  3056. example = [[
  3057. see messasge http://lua-users.org/lists/lua-l/2015-05/msg00376.html]],
  3058. patch = [[
  3059. ]]
  3060. }
  3061. -----------------------------------------------------------------
  3062. -- Lua 5.3.1
  3063. Bug{
  3064. what = [['io.lines' does not check maximum number of options]],
  3065. report = [[Patrick Donnell, 2015/07/10]],
  3066. since = [[5.3.0]],
  3067. fix = nil,
  3068. example = [[
  3069. -- can segfault in some machines
  3070. t ={}; for i = 1, 253 do t[i] = 1 end
  3071. io.lines("someexistingfile", table.unpack(t))()
  3072. ]],
  3073. patch = [[
  3074. --- liolib.c 2015/07/07 17:03:34 2.146
  3075. +++ liolib.c 2015/07/15 14:40:28 2.147
  3076. @@ -318,8 +318,15 @@
  3077. static int io_readline (lua_State *L);
  3078. +/*
  3079. +** maximum number of arguments to 'f:lines'/'io.lines' (it + 3 must fit
  3080. +** in the limit for upvalues of a closure)
  3081. +*/
  3082. +#define MAXARGLINE 250
  3083. +
  3084. static void aux_lines (lua_State *L, int toclose) {
  3085. int n = lua_gettop(L) - 1; /* number of arguments to read */
  3086. + luaL_argcheck(L, n <= MAXARGLINE, MAXARGLINE + 2, "too many arguments");
  3087. lua_pushinteger(L, n); /* number of arguments to read */
  3088. lua_pushboolean(L, toclose); /* close/not close file when finished */
  3089. lua_rotate(L, 2, 2); /* move 'n' and 'toclose' to their positions */
  3090. ]]
  3091. }
  3092. -----------------------------------------------------------------
  3093. -- Lua 5.3.2
  3094. Bug{
  3095. what = [[Metatable may access its own dealocated field when
  3096. it has a self reference in __newindex]],
  3097. report = [[[email protected], 2016/01/01]],
  3098. since = [[5.3.2]],
  3099. fix = nil,
  3100. example = [[
  3101. local mt = {}
  3102. mt.__newindex = mt
  3103. local t = setmetatable({}, mt)
  3104. t[1] = 1 -- will segfault on some machines
  3105. ]],
  3106. patch = [[
  3107. --- lvm.c 2015/11/23 11:30:45 2.265
  3108. +++ lvm.c 2016/01/01 14:34:12
  3109. @@ -190,18 +190,19 @@
  3110. for (loop = 0; loop < MAXTAGLOOP; loop++) {
  3111. const TValue *tm;
  3112. if (oldval != NULL) {
  3113. - lua_assert(ttistable(t) && ttisnil(oldval));
  3114. + Table *h = hvalue(t); /* save 't' table */
  3115. + lua_assert(ttisnil(oldval));
  3116. /* must check the metamethod */
  3117. - if ((tm = fasttm(L, hvalue(t)->metatable, TM_NEWINDEX)) == NULL &&
  3118. + if ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
  3119. /* no metamethod; is there a previous entry in the table? */
  3120. (oldval != luaO_nilobject ||
  3121. /* no previous entry; must create one. (The next test is
  3122. always true; we only need the assignment.) */
  3123. - (oldval = luaH_newkey(L, hvalue(t), key), 1))) {
  3124. + (oldval = luaH_newkey(L, h, key), 1))) {
  3125. /* no metamethod and (now) there is an entry with given key */
  3126. setobj2t(L, cast(TValue *, oldval), val);
  3127. - invalidateTMcache(hvalue(t));
  3128. - luaC_barrierback(L, hvalue(t), val);
  3129. + invalidateTMcache(h);
  3130. + luaC_barrierback(L, h, val);
  3131. return;
  3132. }
  3133. /* else will try the metamethod */
  3134. ]]
  3135. }
  3136. Bug{
  3137. what = [[label between local definitions can mix-up their initializations]],
  3138. report = [[Karel Tuma, 2016/03/01]],
  3139. since = [[5.2]],
  3140. fix = nil,
  3141. example = [[
  3142. do
  3143. local k = 0
  3144. local x
  3145. ::foo::
  3146. local y -- should be reset to nil after goto, but it is not
  3147. assert(not y)
  3148. y = true
  3149. k = k + 1
  3150. if k < 2 then goto foo end
  3151. end
  3152. ]],
  3153. patch = [[
  3154. --- lparser.c 2015/11/02 16:09:30 2.149
  3155. +++ lparser.c 2016/03/03 12:03:37
  3156. @@ -1226,7 +1226,7 @@
  3157. checkrepeated(fs, ll, label); /* check for repeated labels */
  3158. checknext(ls, TK_DBCOLON); /* skip double colon */
  3159. /* create new entry for this label */
  3160. - l = newlabelentry(ls, ll, label, line, fs->pc);
  3161. + l = newlabelentry(ls, ll, label, line, luaK_getlabel(fs));
  3162. skipnoopstat(ls); /* skip other no-op statements */
  3163. if (block_follow(ls, 0)) { /* label is last no-op statement in the block? */
  3164. /* assume that locals are already out of scope */
  3165. ]]
  3166. }
  3167. Bug{
  3168. what = [['gmatch' iterator fails when called from a coroutine different
  3169. from the one that created it]],
  3170. report = [[Nagaev Boris, 2016/03/18]],
  3171. since = [[5.3.2]],
  3172. fix = nil,
  3173. example = [[
  3174. local f = string.gmatch("1 2 3 4 5", "%d+")
  3175. print(f()) --> 1
  3176. co = coroutine.wrap(f)
  3177. print(co()) --> ??? (should be 2)
  3178. ]],
  3179. patch = [[
  3180. --- lstrlib.c 2015/11/25 16:28:17 1.239
  3181. +++ lstrlib.c 2016/04/11 15:29:41
  3182. @@ -688,6 +688,7 @@
  3183. static int gmatch_aux (lua_State *L) {
  3184. GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));
  3185. const char *src;
  3186. + gm->ms.L = L;
  3187. for (src = gm->src; src <= gm->ms.src_end; src++) {
  3188. const char *e;
  3189. reprepstate(&gm->ms);
  3190. ]]
  3191. }
  3192. --[=[
  3193. Bug{
  3194. what = [[ ]],
  3195. report = [[ ]],
  3196. since = [[ ]],
  3197. fix = nil,
  3198. example = [[ ]],
  3199. patch = [[
  3200. ]]
  3201. }
  3202. ]=]