diff --git a/nse_dnet.cc b/nse_dnet.cc index 685fcbb76..fc1401991 100644 --- a/nse_dnet.cc +++ b/nse_dnet.cc @@ -260,7 +260,7 @@ usesock: ret = send_ip_packet(udata->sock, NULL, (u8 *) packet, lua_objlen(L, 2)); } if (ret == -1) - return luaL_error(L, "error while sending: %s (errno %d)", + return safe_error(L, "error while sending: %s (errno %d)", socket_strerror(socket_errno()), socket_errno()); return success(L); diff --git a/nse_utility.cc b/nse_utility.cc index 4d20e52d1..45e48016a 100644 --- a/nse_utility.cc +++ b/nse_utility.cc @@ -1,4 +1,5 @@ #include +#include #include "Target.h" #include "portlist.h" @@ -57,10 +58,13 @@ int success (lua_State *L) return 1; } -int safe_error (lua_State *L, const char *message) +int safe_error (lua_State *L, const char *fmt, ...) { + va_list va; lua_pushboolean(L, false); - lua_pushstring(L, message); + va_start(va, fmt); + lua_pushvfstring(L, fmt, va); + va_end(va); return 2; } diff --git a/nse_utility.h b/nse_utility.h index 1718b598f..b8d0d7681 100644 --- a/nse_utility.h +++ b/nse_utility.h @@ -8,7 +8,7 @@ void setbfield (lua_State *, int, const char *, int); void weak_table (lua_State *, int, int, const char *); int success (lua_State *); -int safe_error (lua_State *, const char *); +int safe_error (lua_State *, const char *, ...); void check_target (lua_State *, int, const char **, const char **); unsigned short check_port (lua_State *, int, const char **);