Skip to content

Commit

Permalink
Merge pull request #745 from robertdavidgraham/integration
Browse files Browse the repository at this point in the history
Fixed mingw issues
  • Loading branch information
robertdavidgraham authored Nov 17, 2023
2 parents 2a547f7 + 09ff4df commit 017e8a0
Show file tree
Hide file tree
Showing 63 changed files with 332 additions and 307 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
paused.conf
.Makefile.swp
.vscode
vs10/.vs/
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# If Windows, then assume the compiler is `gcc` for the
# MinGW environment. I can't figure out how to tell if it's
# actually MingGW. FIXME TODO
ifeq ($(OS),Windows_NT)
CC = gcc
endif

# Try to figure out the default compiler. I dont know the best
# way to do this with `gmake`. If you have better ideas, please
# submit a pull request on github.
Expand Down Expand Up @@ -55,7 +62,7 @@ endif
ifneq (, $(findstring mingw, $(SYS)))
INCLUDES = -Ivs10/include
LIBS = -L vs10/lib -lIPHLPAPI -lWs2_32
FLAGS2 = -march=i686
#FLAGS2 = -march=i686
endif

# Cygwin
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ probably faster than you want anyway.
A bounty is offered for vulnerabilities, see the VULNINFO.md file for more
information.

This project uses safe functions like `strcpy_s()` instead of unsafe functions
This project uses safe functions like `safe_strcpy()` instead of unsafe functions
like `strcpy()`.

This project has automated unit regression tests (`make regress`).
Expand Down
2 changes: 1 addition & 1 deletion src/crypto-blackrock2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "pixie-timer.h"
#include "unusedparm.h"
#include "util-malloc.h"
#include "string_s.h"
#include "util-safefunc.h"
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion src/crypto-lcg.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "crypto-lcg.h"
#include "crypto-primegen.h" /* DJB's prime factoring code */
#include "string_s.h"
#include "util-safefunc.h"
#include "util-malloc.h"

#include <math.h> /* for 'sqrt()', may need -lm for gcc */
Expand Down
14 changes: 9 additions & 5 deletions src/in-binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "masscan-status.h"
#include "main-globals.h"
#include "output.h"
#include "string_s.h"
#include "util-safefunc.h"
#include "in-filter.h"
#include "in-report.h"
#include "util-malloc.h"
Expand All @@ -18,6 +18,10 @@
#include <stdlib.h>
#include <assert.h>

#ifdef _MSC_VER
#pragma warning(disable:4996)
#endif

static const size_t BUF_MAX = 1024*1024;

struct MasscanRecord {
Expand Down Expand Up @@ -474,15 +478,15 @@ _binaryfile_parse(struct Output *out, const char *filename,
unsigned char *buf = 0;
size_t bytes_read;
uint64_t total_records = 0;
int x;

/* Allocate a buffer of up to one megabyte per record */
buf = MALLOC(BUF_MAX);

/* Open the file */
x = fopen_s(&fp, filename, "rb");
if (x != 0 || fp == NULL) {
perror(filename);
fp = fopen(filename, "rb");
if (fp == NULL) {
fprintf(stderr, "[-] FAIL: --readscan\n");
fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));
goto end;
}

Expand Down
75 changes: 40 additions & 35 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "masscan.h"
#include "massip-addr.h"
#include "masscan-version.h"
#include "string_s.h"
#include "util-safefunc.h"
#include "util-logger.h"
#include "proto-banner1.h"
#include "templ-payloads.h"
Expand Down Expand Up @@ -100,6 +100,10 @@ print_version()
);
printf("Compiled on: %s %s\n", __DATE__, __TIME__);

#if defined(__x86_64) || defined(__x86_64__)
cpu = "x86";
#endif

#if defined(_MSC_VER)
#if defined(_M_AMD64) || defined(_M_X64)
cpu = "x86";
Expand Down Expand Up @@ -296,7 +300,7 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i)
if (masscan->nic_count <= 1)
idx_str[0] = '\0';
else
sprintf_s(idx_str, sizeof(idx_str), "[%u]", i);
snprintf(idx_str, sizeof(idx_str), "[%u]", i);

if (masscan->nic[i].ifname[0])
fprintf(fp, "adapter%s = %s\n", idx_str, masscan->nic[i].ifname);
Expand Down Expand Up @@ -391,17 +395,16 @@ masscan_save_state(struct Masscan *masscan)
{
char filename[512];
FILE *fp;
int err;


strcpy_s(filename, sizeof(filename), "paused.conf");
safe_strcpy(filename, sizeof(filename), "paused.conf");
fprintf(stderr, " "
" \r");
fprintf(stderr, "saving resume file to: %s\n", filename);

err = fopen_s(&fp, filename, "wt");
if (err) {
perror(filename);
fp = fopen(filename, "wt");
if (fp == NULL) {
fprintf(stderr, "[-] FAIL: saving resume file\n");
fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));
return;
}

Expand All @@ -428,11 +431,10 @@ static void
ranges_from_file(struct RangeList *ranges, const char *filename)
{
FILE *fp;
errno_t err;
unsigned line_number = 0;

err = fopen_s(&fp, filename, "rt");
if (err) {
fp = fopen(filename, "rt");
if (fp) {
perror(filename);
exit(1); /* HARD EXIT: because if it's an exclusion file, we don't
* want to continue. We don't want ANY chance of
Expand Down Expand Up @@ -1205,7 +1207,6 @@ static int SET_hello_file(struct Masscan *masscan, const char *name, const char
{
unsigned index;
FILE *fp;
int x;
char buf[16384];
char buf2[16384];
size_t bytes_read;
Expand All @@ -1225,10 +1226,10 @@ static int SET_hello_file(struct Masscan *masscan, const char *name, const char
}

/* When connecting via TCP, send this file */
x = fopen_s(&fp, value, "rb");
if (x != 0) {
LOG(0, "[FAILED] could not read hello file\n");
perror(value);
fp = fopen(value, "rb");
if (fp == NULL) {
LOG(0, "[-] [FAILED] --hello-file\n");
LOG(0, "[-] %s: %s\n", value, strerror(errno));
return CONF_ERR;
}

Expand All @@ -1244,7 +1245,7 @@ static int SET_hello_file(struct Masscan *masscan, const char *name, const char
bytes_encoded = base64_encode(buf2, sizeof(buf2)-1, buf, bytes_read);
buf2[bytes_encoded] = '\0';

sprintf_s(foo, sizeof(foo), "hello-string[%u]", (unsigned)index);
snprintf(foo, sizeof(foo), "hello-string[%u]", (unsigned)index);

masscan_set_parameter(masscan, foo, buf2);

Expand Down Expand Up @@ -1636,7 +1637,7 @@ static int SET_output_filename(struct Masscan *masscan, const char *name, const
}
if (masscan->output.format == 0)
masscan->output.format = Output_XML; /*TODO: Why is the default XML?*/
strcpy_s(masscan->output.filename,
safe_strcpy(masscan->output.filename,
sizeof(masscan->output.filename),
value);
return CONF_OK;
Expand Down Expand Up @@ -1806,7 +1807,7 @@ static int SET_pcap_filename(struct Masscan *masscan, const char *name, const ch
return 0;
}
if (value)
strcpy_s(masscan->pcap_filename, sizeof(masscan->pcap_filename), value);
safe_strcpy(masscan->pcap_filename, sizeof(masscan->pcap_filename), value);
return CONF_OK;
}

Expand Down Expand Up @@ -1960,7 +1961,7 @@ static int SET_rotate_directory(struct Masscan *masscan, const char *name, const
}
return 0;
}
strcpy_s( masscan->output.rotate.directory,
safe_strcpy( masscan->output.rotate.directory,
sizeof(masscan->output.rotate.directory),
value);
/* strip trailing slashes */
Expand Down Expand Up @@ -2087,7 +2088,7 @@ static int SET_output_stylesheet(struct Masscan *masscan, const char *name, cons
if (masscan->output.format == 0)
masscan->output.format = Output_XML;

strcpy_s(masscan->output.stylesheet, sizeof(masscan->output.stylesheet), value);
safe_strcpy(masscan->output.stylesheet, sizeof(masscan->output.stylesheet), value);
return CONF_OK;
}

Expand Down Expand Up @@ -2332,7 +2333,10 @@ static int SET_tcp_sackok(struct Masscan *masscan, const char *name, const char


static int SET_debug_tcp(struct Masscan *masscan, const char *name, const char *value) {
extern int is_tcp_debug;
extern int is_tcp_debug; /* global */
UNUSEDPARM(name);
UNUSEDPARM(masscan);

if (value == 0 || value[0] == '\0')
is_tcp_debug = 1;
else
Expand Down Expand Up @@ -2459,7 +2463,7 @@ masscan_set_parameter(struct Masscan *masscan,
}
if (masscan->nic_count < index + 1)
masscan->nic_count = index + 1;
sprintf_s( masscan->nic[index].ifname,
snprintf( masscan->nic[index].ifname,
sizeof(masscan->nic[index].ifname),
"%s",
value);
Expand Down Expand Up @@ -2748,7 +2752,7 @@ masscan_set_parameter(struct Masscan *masscan,
/* The timeout for banners TCP connections */
masscan->tcp_connection_timeout = (unsigned)parseInt(value);
} else if (EQUALS("datadir", name)) {
strcpy_s(masscan->nmap.datadir, sizeof(masscan->nmap.datadir), value);
safe_strcpy(masscan->nmap.datadir, sizeof(masscan->nmap.datadir), value);
} else if (EQUALS("data-length", name)) {
unsigned x = (unsigned)strtoul(value, 0, 0);
if (x >= 1514 - 14 - 40) {
Expand Down Expand Up @@ -2898,7 +2902,7 @@ masscan_set_parameter(struct Masscan *masscan,

masscan->redis.port = port;
masscan->output.format = Output_Redis;
strcpy_s(masscan->output.filename,
safe_strcpy(masscan->output.filename,
sizeof(masscan->output.filename),
"<redis>");
} else if(EQUALS("redis-pwd", name)) {
Expand Down Expand Up @@ -3153,17 +3157,16 @@ masscan_load_database_files(struct Masscan *masscan)
}

/*
* "nmap-payloads"
* `--nmap-payloads`
*/
filename = masscan->payloads.nmap_payloads_filename;
if (filename) {
FILE *fp;
int err;


err = fopen_s(&fp, filename, "rt");
if (err || fp == NULL) {
perror(filename);
fp = fopen(filename, "rt");
if (fp == NULL) {
fprintf(stderr, "[-] FAIL: --nmap-payloads\n");
fprintf(stderr, "[-] %s:%s\n", filename, strerror(errno));
} else {
if (masscan->payloads.udp == NULL)
masscan->payloads.udp = payloads_udp_create();
Expand Down Expand Up @@ -3866,14 +3869,16 @@ void
masscan_read_config_file(struct Masscan *masscan, const char *filename)
{
FILE *fp;
errno_t err;
char line[65536];

err = fopen_s(&fp, filename, "rt");
if (err) {
fp = fopen(filename, "rt");
if (fp == NULL) {
char dir[512];
char *x;
perror(filename);

fprintf(stderr, "[-] FAIL: reading configuration file\n");
fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));

x = getcwd(dir, sizeof(dir));
if (x)
fprintf(stderr, "[-] cwd = %s\n", dir);
Expand Down
36 changes: 18 additions & 18 deletions src/main-ptrace.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "main-ptrace.h"
#include "proto-preprocess.h"
#include "pixie-timer.h"
#include "string_s.h"
#include "util-safefunc.h"


/***************************************************************************
Expand Down Expand Up @@ -35,20 +35,20 @@ packet_trace(FILE *fp, double pt_start, const unsigned char *px, size_t length,

/* format the IP addresses into fixed-width fields */
fmt = ipaddress_fmt(parsed.src_ip);
sprintf_s(from, sizeof(from), "[%s]:%u", fmt.string, parsed.port_src);
snprintf(from, sizeof(from), "[%s]:%u", fmt.string, parsed.port_src);

fmt = ipaddress_fmt(parsed.dst_ip);
sprintf_s(to, sizeof(to), "[%s]:%u", fmt.string, parsed.port_dst);
snprintf(to, sizeof(to), "[%s]:%u", fmt.string, parsed.port_dst);

switch (parsed.found) {
case FOUND_ARP:
type = px[offset+6]<<8 | px[offset+7];
*strchr(to, ':') = '\0';
*strchr(from, ':') = '\0';
switch (type) {
case 1:strcpy_s(sz_type, sizeof(sz_type), "request"); break;
case 2:strcpy_s(sz_type, sizeof(sz_type), "response"); break;
default: sprintf_s(sz_type, sizeof(sz_type), "unknown(%u)", type); break;
case 1:safe_strcpy(sz_type, sizeof(sz_type), "request"); break;
case 2:safe_strcpy(sz_type, sizeof(sz_type), "response"); break;
default: snprintf(sz_type, sizeof(sz_type), "unknown(%u)", type); break;
}
fprintf(fp, "%s (%5.4f) ARP %-21s > %-21s %s\n", direction,
timestamp - pt_start, from, to, sz_type);
Expand All @@ -65,19 +65,19 @@ packet_trace(FILE *fp, double pt_start, const unsigned char *px, size_t length,
case FOUND_TCP:
type = px[offset+13];
switch (type) {
case 0x00: strcpy_s(sz_type, sizeof(sz_type), "NULL"); break;
case 0x01: strcpy_s(sz_type, sizeof(sz_type), "FIN"); break;
case 0x11: strcpy_s(sz_type, sizeof(sz_type), "FIN-ACK"); break;
case 0x19: strcpy_s(sz_type, sizeof(sz_type), "FIN-ACK-PSH"); break;
case 0x02: strcpy_s(sz_type, sizeof(sz_type), "SYN"); break;
case 0x12: strcpy_s(sz_type, sizeof(sz_type), "SYN-ACK"); break;
case 0x04: strcpy_s(sz_type, sizeof(sz_type), "RST"); break;
case 0x14: strcpy_s(sz_type, sizeof(sz_type), "RST-ACK"); break;
case 0x15: strcpy_s(sz_type, sizeof(sz_type), "RST-FIN-ACK"); break;
case 0x10: strcpy_s(sz_type, sizeof(sz_type), "ACK"); break;
case 0x18: strcpy_s(sz_type, sizeof(sz_type), "ACK-PSH"); break;
case 0x00: safe_strcpy(sz_type, sizeof(sz_type), "NULL"); break;
case 0x01: safe_strcpy(sz_type, sizeof(sz_type), "FIN"); break;
case 0x11: safe_strcpy(sz_type, sizeof(sz_type), "FIN-ACK"); break;
case 0x19: safe_strcpy(sz_type, sizeof(sz_type), "FIN-ACK-PSH"); break;
case 0x02: safe_strcpy(sz_type, sizeof(sz_type), "SYN"); break;
case 0x12: safe_strcpy(sz_type, sizeof(sz_type), "SYN-ACK"); break;
case 0x04: safe_strcpy(sz_type, sizeof(sz_type), "RST"); break;
case 0x14: safe_strcpy(sz_type, sizeof(sz_type), "RST-ACK"); break;
case 0x15: safe_strcpy(sz_type, sizeof(sz_type), "RST-FIN-ACK"); break;
case 0x10: safe_strcpy(sz_type, sizeof(sz_type), "ACK"); break;
case 0x18: safe_strcpy(sz_type, sizeof(sz_type), "ACK-PSH"); break;
default:
sprintf_s(sz_type, sizeof(sz_type),
snprintf(sz_type, sizeof(sz_type),
"%s%s%s%s%s%s%s%s",
(type&0x01)?"FIN":"",
(type&0x02)?"SYN":"",
Expand Down
2 changes: 1 addition & 1 deletion src/main-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "pixie-timer.h"
#include "unusedparm.h"
#include "main-globals.h"
#include "string_s.h"
#include "util-safefunc.h"
#include "util-bool.h"
#include <stdio.h>

Expand Down
Loading

0 comments on commit 017e8a0

Please sign in to comment.