Wednesday 4 March 2015

UDP server problem with NodeMCU build 0.95 / nodemcu_20150213.bin

For an upcoming project I need to run a DNS server on the ESP8266 module (ESP-01). All this server has to do is reply to any DNS query with the modules' IP address.
Basically that is what some captive portals do.

I developed that script on nodemcu_20150212.bin without any significant trouble and it ran ok there.

To make use of the node.compile() option, I upgraded to the 20150213.bin but the MCU crashed and rebooted when trying to send back the DNS reply.

The LUA script looks like this:

 svr=net.createServer(net.UDP)   
 svr:on("receive",function(svr,pl)  
 decodedns(pl)  
 encodedns (query, transaction_id)  
 svr:send(response)  
 end)  
 svr:listen(53)  
 function decodedns(pl)  
      --do some magic  
 end  
 function encodedns(query, transaction_id)  
      --do some more magic  
 end  

The svr:send failed and crashed the mcu. It totally lacks all input sanitation and can easily be derailed, but that is another story.

Looking at the changes from 20150212 to 20150213, the only suspicious change was this:

app/lua/luaconf.h
  @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.  
  */  
 -#define LUAL_BUFFERSIZE          BUFSIZ  
 +#define LUAL_BUFFERSIZE          (BUFSIZ*4)  
  /* }================================================================== */  

I changed that back to the original buffer size and sure enough my script was fine again.

No comments:

Post a Comment