AP_Scripting: use luaL_checklstring for serial port writestring

Avoids potential null pointer dereferences if a port write method can't
handle a null pointer when doing a zero length write. Also provides a
nice type error if something that can't be converted to a string is
passed.
This commit is contained in:
Thomas Watson
2025-05-17 09:56:05 -05:00
committed by Andrew Tridgell
parent a20dd5af68
commit 55889f6db7

View File

@@ -813,7 +813,7 @@ int lua_serial_writestring(lua_State *L)
// get the bytes the user wants to write, along with their length
size_t req_bytes;
const char *data = lua_tolstring(L, 2, &req_bytes);
const char *data = luaL_checklstring(L, 2, &req_bytes);
// write up to that number of bytes
const uint32_t written_bytes = port->write((const uint8_t*)data, req_bytes);