From e39eeea8ba18b02e7e54ec40e4970f10cae7bc79 Mon Sep 17 00:00:00 2001 From: kris Date: Thu, 11 Nov 2010 01:11:13 +0000 Subject: [PATCH] Since r20267 (NSE Nsock maintenance), failures in raw IP sends from NSE cause scripts to bail. (This is why Ron saw a backtrace when path-mtu elicited an EMSGSIZE [a separate issue I'm still working on] instead of path-mtu recognizing the failure and resending with a smaller MTU like it would do before.) I'm changing this back to the original design of returning false to scripts (just like connect-mode send failures). I've changed safe_error() in nse_utility.cc to support varargs. --- nse_dnet.cc | 2 +- nse_utility.cc | 8 ++++++-- nse_utility.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) 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 **);