@@ -52,13 +52,6 @@ struct metrics {
5252
5353static struct metrics metrics;
5454
55- static void
56- Hook (lua_State *L, lua_Debug *ar)
57- {
58- (void )L;
59- (void )ar;
60- }
61-
6255UNUSED static void
6356jit_attach (lua_State *L, void *func, const char *event)
6457{
@@ -260,73 +253,6 @@ disable_lj_metrics(lua_State *L, struct metrics *metrics)
260253 jit_attach (L, (void *)trace_cb, NULL );
261254}
262255
263- struct str_Writer {
264- /* Non-zero when buffer has been initialized. */
265- int init;
266- luaL_Buffer B;
267- size_t bufsize;
268- };
269-
270- static int
271- writer (lua_State *L, const void *b, size_t size, void *ud) {
272- struct str_Writer *state = (struct str_Writer *)ud;
273- if (!state->init ) {
274- state->init = 1 ;
275- luaL_buffinit (L, &state->B );
276- }
277- /* Finishing dump? */
278- if (b == NULL ) {
279- luaL_pushresult (&state->B );
280- /* Move result to reserved slot. */
281- lua_replace (L, 1 );
282- }
283- else {
284- luaL_addlstring (&state->B , (const char *)b, size);
285- state->bufsize += size;
286- }
287- return 0 ;
288- }
289-
290- /*
291- * Loads a buffer as a Lua bytecode chunk. This function uses luaL_loadstring
292- * to load the chunk in the buffer pointed to by buff, lua_dump to dump
293- * produced bytecode and luaL_loadbuffer to load produced bytecode to the
294- * stack. This function returns the same results as luaL_loadbuffer.
295- * name is the chunk name, used for debug information and error messages.
296- */
297- static int
298- luaL_loadbytecode (lua_State *L, const char *buff, size_t sz, const char *name)
299- {
300- /* Compile Lua source code to bytecode. */
301- int rc = luaL_loadstring (L, buff);
302- if (rc != 0 ) {
303- return LUA_ERRSYNTAX;
304- }
305-
306- /* Dump a Lua bytecode to a buffer. */
307- struct str_Writer state;
308- memset (&state, 0 , sizeof (struct str_Writer ));
309- #if LUA_VERSION_NUM < 503
310- rc = lua_dump (L, writer, &state);
311- #else /* Lua 5.3+ */
312- rc = lua_dump (L, writer, &state, 0 );
313- #endif /* LUA_VERSION_NUM */
314- if (rc != 0 ) {
315- return rc;
316- }
317-
318- /* Leave final result on top. */
319- lua_settop (L, 1 );
320- const char *bc = lua_tolstring (L, -1 , &state.bufsize );
321- /* Load Lua bytecode. */
322- rc = luaL_loadbuffer (L, bc, state.bufsize , " bytecode" );
323- if (rc != 0 ) {
324- return rc;
325- }
326-
327- return 0 ;
328- }
329-
330256DEFINE_PROTO_FUZZER (const lua_grammar::Block &message)
331257{
332258 lua_State *L = luaL_newstate ();
@@ -342,11 +268,6 @@ DEFINE_PROTO_FUZZER(const lua_grammar::Block &message)
342268
343269 luaL_openlibs (L);
344270
345- int flag = LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE;
346- int count = 0 ;
347- /* Enable debugging hook. */
348- lua_sethook (L, Hook, flag, count);
349-
350271#ifdef LUAJIT
351272 enable_lj_metrics (L, &metrics);
352273
@@ -399,21 +320,9 @@ DEFINE_PROTO_FUZZER(const lua_grammar::Block &message)
399320 goto end;
400321 }
401322
402- /*
403- * With luaL_loadbytecode we build a bytecode from a Lua code and then
404- * execute produced bytecode chunk.
405- */
406- if (luaL_loadbytecode (L, code.c_str (), code.size (), " fuzz" ) != LUA_OK)
407- goto end;
408-
409- if (lua_pcall (L, 0 , 0 , 0 ) != LUA_OK) {
410- report_error (L, " lua_pcall()" );
411- }
412-
413323end:
414324 metrics_increment_num_samples (&metrics);
415325 /* Disable debugging hook. */
416- lua_sethook (L, Hook, 0 , count);
417326#ifdef LUAJIT
418327 disable_lj_metrics (L, &metrics);
419328 /* Stop profiler. */
0 commit comments