Skip to content

Commit 017e8a0

Browse files
Merge pull request #745 from robertdavidgraham/integration
Fixed mingw issues
2 parents 2a547f7 + 09ff4df commit 017e8a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+332
-307
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
paused.conf
22
.Makefile.swp
33
.vscode
4+
vs10/.vs/

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# If Windows, then assume the compiler is `gcc` for the
2+
# MinGW environment. I can't figure out how to tell if it's
3+
# actually MingGW. FIXME TODO
4+
ifeq ($(OS),Windows_NT)
5+
CC = gcc
6+
endif
7+
18
# Try to figure out the default compiler. I dont know the best
29
# way to do this with `gmake`. If you have better ideas, please
310
# submit a pull request on github.
@@ -55,7 +62,7 @@ endif
5562
ifneq (, $(findstring mingw, $(SYS)))
5663
INCLUDES = -Ivs10/include
5764
LIBS = -L vs10/lib -lIPHLPAPI -lWs2_32
58-
FLAGS2 = -march=i686
65+
#FLAGS2 = -march=i686
5966
endif
6067

6168
# Cygwin

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ probably faster than you want anyway.
504504
A bounty is offered for vulnerabilities, see the VULNINFO.md file for more
505505
information.
506506

507-
This project uses safe functions like `strcpy_s()` instead of unsafe functions
507+
This project uses safe functions like `safe_strcpy()` instead of unsafe functions
508508
like `strcpy()`.
509509

510510
This project has automated unit regression tests (`make regress`).

src/crypto-blackrock2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "pixie-timer.h"
33
#include "unusedparm.h"
44
#include "util-malloc.h"
5-
#include "string_s.h"
5+
#include "util-safefunc.h"
66
#include <stdint.h>
77
#include <string.h>
88
#include <stdlib.h>

src/crypto-lcg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include "crypto-lcg.h"
77
#include "crypto-primegen.h" /* DJB's prime factoring code */
8-
#include "string_s.h"
8+
#include "util-safefunc.h"
99
#include "util-malloc.h"
1010

1111
#include <math.h> /* for 'sqrt()', may need -lm for gcc */

src/in-binary.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "masscan-status.h"
1010
#include "main-globals.h"
1111
#include "output.h"
12-
#include "string_s.h"
12+
#include "util-safefunc.h"
1313
#include "in-filter.h"
1414
#include "in-report.h"
1515
#include "util-malloc.h"
@@ -18,6 +18,10 @@
1818
#include <stdlib.h>
1919
#include <assert.h>
2020

21+
#ifdef _MSC_VER
22+
#pragma warning(disable:4996)
23+
#endif
24+
2125
static const size_t BUF_MAX = 1024*1024;
2226

2327
struct MasscanRecord {
@@ -474,15 +478,15 @@ _binaryfile_parse(struct Output *out, const char *filename,
474478
unsigned char *buf = 0;
475479
size_t bytes_read;
476480
uint64_t total_records = 0;
477-
int x;
478481

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

482485
/* Open the file */
483-
x = fopen_s(&fp, filename, "rb");
484-
if (x != 0 || fp == NULL) {
485-
perror(filename);
486+
fp = fopen(filename, "rb");
487+
if (fp == NULL) {
488+
fprintf(stderr, "[-] FAIL: --readscan\n");
489+
fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));
486490
goto end;
487491
}
488492

src/main-conf.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "masscan.h"
1515
#include "massip-addr.h"
1616
#include "masscan-version.h"
17-
#include "string_s.h"
17+
#include "util-safefunc.h"
1818
#include "util-logger.h"
1919
#include "proto-banner1.h"
2020
#include "templ-payloads.h"
@@ -100,6 +100,10 @@ print_version()
100100
);
101101
printf("Compiled on: %s %s\n", __DATE__, __TIME__);
102102

103+
#if defined(__x86_64) || defined(__x86_64__)
104+
cpu = "x86";
105+
#endif
106+
103107
#if defined(_MSC_VER)
104108
#if defined(_M_AMD64) || defined(_M_X64)
105109
cpu = "x86";
@@ -296,7 +300,7 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i)
296300
if (masscan->nic_count <= 1)
297301
idx_str[0] = '\0';
298302
else
299-
sprintf_s(idx_str, sizeof(idx_str), "[%u]", i);
303+
snprintf(idx_str, sizeof(idx_str), "[%u]", i);
300304

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

397-
strcpy_s(filename, sizeof(filename), "paused.conf");
399+
safe_strcpy(filename, sizeof(filename), "paused.conf");
398400
fprintf(stderr, " "
399401
" \r");
400402
fprintf(stderr, "saving resume file to: %s\n", filename);
401403

402-
err = fopen_s(&fp, filename, "wt");
403-
if (err) {
404-
perror(filename);
404+
fp = fopen(filename, "wt");
405+
if (fp == NULL) {
406+
fprintf(stderr, "[-] FAIL: saving resume file\n");
407+
fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));
405408
return;
406409
}
407410

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

434-
err = fopen_s(&fp, filename, "rt");
435-
if (err) {
436+
fp = fopen(filename, "rt");
437+
if (fp) {
436438
perror(filename);
437439
exit(1); /* HARD EXIT: because if it's an exclusion file, we don't
438440
* want to continue. We don't want ANY chance of
@@ -1205,7 +1207,6 @@ static int SET_hello_file(struct Masscan *masscan, const char *name, const char
12051207
{
12061208
unsigned index;
12071209
FILE *fp;
1208-
int x;
12091210
char buf[16384];
12101211
char buf2[16384];
12111212
size_t bytes_read;
@@ -1225,10 +1226,10 @@ static int SET_hello_file(struct Masscan *masscan, const char *name, const char
12251226
}
12261227

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

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

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

12491250
masscan_set_parameter(masscan, foo, buf2);
12501251

@@ -1636,7 +1637,7 @@ static int SET_output_filename(struct Masscan *masscan, const char *name, const
16361637
}
16371638
if (masscan->output.format == 0)
16381639
masscan->output.format = Output_XML; /*TODO: Why is the default XML?*/
1639-
strcpy_s(masscan->output.filename,
1640+
safe_strcpy(masscan->output.filename,
16401641
sizeof(masscan->output.filename),
16411642
value);
16421643
return CONF_OK;
@@ -1806,7 +1807,7 @@ static int SET_pcap_filename(struct Masscan *masscan, const char *name, const ch
18061807
return 0;
18071808
}
18081809
if (value)
1809-
strcpy_s(masscan->pcap_filename, sizeof(masscan->pcap_filename), value);
1810+
safe_strcpy(masscan->pcap_filename, sizeof(masscan->pcap_filename), value);
18101811
return CONF_OK;
18111812
}
18121813

@@ -1960,7 +1961,7 @@ static int SET_rotate_directory(struct Masscan *masscan, const char *name, const
19601961
}
19611962
return 0;
19621963
}
1963-
strcpy_s( masscan->output.rotate.directory,
1964+
safe_strcpy( masscan->output.rotate.directory,
19641965
sizeof(masscan->output.rotate.directory),
19651966
value);
19661967
/* strip trailing slashes */
@@ -2087,7 +2088,7 @@ static int SET_output_stylesheet(struct Masscan *masscan, const char *name, cons
20872088
if (masscan->output.format == 0)
20882089
masscan->output.format = Output_XML;
20892090

2090-
strcpy_s(masscan->output.stylesheet, sizeof(masscan->output.stylesheet), value);
2091+
safe_strcpy(masscan->output.stylesheet, sizeof(masscan->output.stylesheet), value);
20912092
return CONF_OK;
20922093
}
20932094

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

23332334

23342335
static int SET_debug_tcp(struct Masscan *masscan, const char *name, const char *value) {
2335-
extern int is_tcp_debug;
2336+
extern int is_tcp_debug; /* global */
2337+
UNUSEDPARM(name);
2338+
UNUSEDPARM(masscan);
2339+
23362340
if (value == 0 || value[0] == '\0')
23372341
is_tcp_debug = 1;
23382342
else
@@ -2459,7 +2463,7 @@ masscan_set_parameter(struct Masscan *masscan,
24592463
}
24602464
if (masscan->nic_count < index + 1)
24612465
masscan->nic_count = index + 1;
2462-
sprintf_s( masscan->nic[index].ifname,
2466+
snprintf( masscan->nic[index].ifname,
24632467
sizeof(masscan->nic[index].ifname),
24642468
"%s",
24652469
value);
@@ -2748,7 +2752,7 @@ masscan_set_parameter(struct Masscan *masscan,
27482752
/* The timeout for banners TCP connections */
27492753
masscan->tcp_connection_timeout = (unsigned)parseInt(value);
27502754
} else if (EQUALS("datadir", name)) {
2751-
strcpy_s(masscan->nmap.datadir, sizeof(masscan->nmap.datadir), value);
2755+
safe_strcpy(masscan->nmap.datadir, sizeof(masscan->nmap.datadir), value);
27522756
} else if (EQUALS("data-length", name)) {
27532757
unsigned x = (unsigned)strtoul(value, 0, 0);
27542758
if (x >= 1514 - 14 - 40) {
@@ -2898,7 +2902,7 @@ masscan_set_parameter(struct Masscan *masscan,
28982902

28992903
masscan->redis.port = port;
29002904
masscan->output.format = Output_Redis;
2901-
strcpy_s(masscan->output.filename,
2905+
safe_strcpy(masscan->output.filename,
29022906
sizeof(masscan->output.filename),
29032907
"<redis>");
29042908
} else if(EQUALS("redis-pwd", name)) {
@@ -3153,17 +3157,16 @@ masscan_load_database_files(struct Masscan *masscan)
31533157
}
31543158

31553159
/*
3156-
* "nmap-payloads"
3160+
* `--nmap-payloads`
31573161
*/
31583162
filename = masscan->payloads.nmap_payloads_filename;
31593163
if (filename) {
31603164
FILE *fp;
3161-
int err;
3162-
31633165

3164-
err = fopen_s(&fp, filename, "rt");
3165-
if (err || fp == NULL) {
3166-
perror(filename);
3166+
fp = fopen(filename, "rt");
3167+
if (fp == NULL) {
3168+
fprintf(stderr, "[-] FAIL: --nmap-payloads\n");
3169+
fprintf(stderr, "[-] %s:%s\n", filename, strerror(errno));
31673170
} else {
31683171
if (masscan->payloads.udp == NULL)
31693172
masscan->payloads.udp = payloads_udp_create();
@@ -3866,14 +3869,16 @@ void
38663869
masscan_read_config_file(struct Masscan *masscan, const char *filename)
38673870
{
38683871
FILE *fp;
3869-
errno_t err;
38703872
char line[65536];
38713873

3872-
err = fopen_s(&fp, filename, "rt");
3873-
if (err) {
3874+
fp = fopen(filename, "rt");
3875+
if (fp == NULL) {
38743876
char dir[512];
38753877
char *x;
3876-
perror(filename);
3878+
3879+
fprintf(stderr, "[-] FAIL: reading configuration file\n");
3880+
fprintf(stderr, "[-] %s: %s\n", filename, strerror(errno));
3881+
38773882
x = getcwd(dir, sizeof(dir));
38783883
if (x)
38793884
fprintf(stderr, "[-] cwd = %s\n", dir);

src/main-ptrace.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "main-ptrace.h"
22
#include "proto-preprocess.h"
33
#include "pixie-timer.h"
4-
#include "string_s.h"
4+
#include "util-safefunc.h"
55

66

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

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

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

4343
switch (parsed.found) {
4444
case FOUND_ARP:
4545
type = px[offset+6]<<8 | px[offset+7];
4646
*strchr(to, ':') = '\0';
4747
*strchr(from, ':') = '\0';
4848
switch (type) {
49-
case 1:strcpy_s(sz_type, sizeof(sz_type), "request"); break;
50-
case 2:strcpy_s(sz_type, sizeof(sz_type), "response"); break;
51-
default: sprintf_s(sz_type, sizeof(sz_type), "unknown(%u)", type); break;
49+
case 1:safe_strcpy(sz_type, sizeof(sz_type), "request"); break;
50+
case 2:safe_strcpy(sz_type, sizeof(sz_type), "response"); break;
51+
default: snprintf(sz_type, sizeof(sz_type), "unknown(%u)", type); break;
5252
}
5353
fprintf(fp, "%s (%5.4f) ARP %-21s > %-21s %s\n", direction,
5454
timestamp - pt_start, from, to, sz_type);
@@ -65,19 +65,19 @@ packet_trace(FILE *fp, double pt_start, const unsigned char *px, size_t length,
6565
case FOUND_TCP:
6666
type = px[offset+13];
6767
switch (type) {
68-
case 0x00: strcpy_s(sz_type, sizeof(sz_type), "NULL"); break;
69-
case 0x01: strcpy_s(sz_type, sizeof(sz_type), "FIN"); break;
70-
case 0x11: strcpy_s(sz_type, sizeof(sz_type), "FIN-ACK"); break;
71-
case 0x19: strcpy_s(sz_type, sizeof(sz_type), "FIN-ACK-PSH"); break;
72-
case 0x02: strcpy_s(sz_type, sizeof(sz_type), "SYN"); break;
73-
case 0x12: strcpy_s(sz_type, sizeof(sz_type), "SYN-ACK"); break;
74-
case 0x04: strcpy_s(sz_type, sizeof(sz_type), "RST"); break;
75-
case 0x14: strcpy_s(sz_type, sizeof(sz_type), "RST-ACK"); break;
76-
case 0x15: strcpy_s(sz_type, sizeof(sz_type), "RST-FIN-ACK"); break;
77-
case 0x10: strcpy_s(sz_type, sizeof(sz_type), "ACK"); break;
78-
case 0x18: strcpy_s(sz_type, sizeof(sz_type), "ACK-PSH"); break;
68+
case 0x00: safe_strcpy(sz_type, sizeof(sz_type), "NULL"); break;
69+
case 0x01: safe_strcpy(sz_type, sizeof(sz_type), "FIN"); break;
70+
case 0x11: safe_strcpy(sz_type, sizeof(sz_type), "FIN-ACK"); break;
71+
case 0x19: safe_strcpy(sz_type, sizeof(sz_type), "FIN-ACK-PSH"); break;
72+
case 0x02: safe_strcpy(sz_type, sizeof(sz_type), "SYN"); break;
73+
case 0x12: safe_strcpy(sz_type, sizeof(sz_type), "SYN-ACK"); break;
74+
case 0x04: safe_strcpy(sz_type, sizeof(sz_type), "RST"); break;
75+
case 0x14: safe_strcpy(sz_type, sizeof(sz_type), "RST-ACK"); break;
76+
case 0x15: safe_strcpy(sz_type, sizeof(sz_type), "RST-FIN-ACK"); break;
77+
case 0x10: safe_strcpy(sz_type, sizeof(sz_type), "ACK"); break;
78+
case 0x18: safe_strcpy(sz_type, sizeof(sz_type), "ACK-PSH"); break;
7979
default:
80-
sprintf_s(sz_type, sizeof(sz_type),
80+
snprintf(sz_type, sizeof(sz_type),
8181
"%s%s%s%s%s%s%s%s",
8282
(type&0x01)?"FIN":"",
8383
(type&0x02)?"SYN":"",

src/main-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "pixie-timer.h"
1313
#include "unusedparm.h"
1414
#include "main-globals.h"
15-
#include "string_s.h"
15+
#include "util-safefunc.h"
1616
#include "util-bool.h"
1717
#include <stdio.h>
1818

0 commit comments

Comments
 (0)