This commit is contained in:
Sparshagarwal0110 2026-11-25 04:09:27 +00:00 • committed by GitHub
commit 56cf381783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View file

@ -4,6 +4,7 @@
#include <math.h>
#include "nmap.h"
#include "output.h"
#include "nmap_error.h"
#include "NmapOps.h"
#include "FingerPrintResults.h"
@ -618,7 +619,13 @@ static int l_log_write (lua_State *L)
static const char * const ops[] = {"stdout", "stderr", NULL};
static const int logs[] = {LOG_STDOUT, LOG_STDERR};
int log = logs[luaL_checkoption(L, 1, NULL, ops)];
log_write(log, "%s: %s\n", SCRIPT_ENGINE, luaL_checkstring(L, 2));
size_t message_len;
const char *message = luaL_checklstring(L, 2, &message_len);
std::string escaped_message =
escape_for_screen(std::string(message, message_len));
log_write(log, "%s: %s\n", SCRIPT_ENGINE, escaped_message.c_str());
log_flush(log);
return 0;
}

View file

@ -388,7 +388,7 @@ int print_iflist(void) {
#ifndef NOLUA
/* Escape control characters to make a string safe to display on a terminal. */
static std::string escape_for_screen(const std::string s) {
std::string escape_for_screen(const std::string s) {
std::string r;
for (unsigned int i = 0; i < s.size(); i++) {

View file

@ -112,6 +112,11 @@ class Target;
#include <stdarg.h>
#include <string>
#ifndef NOLUA
/* Escape control characters to make a string safe to display on a terminal. */
std::string escape_for_screen(const std::string s);
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif