Skip to content

Commit 792e0e2

Browse files
committed
Made masscan somehow compatible to C++ compilers
* mostly cast fixes for malloc * typed some ints to the correct enums, which also benefits clarity * fixed some other variables types and eliminated some UB as signed-unsigned comparison * added a missing check for a returned value * made signatures consistent (plain C is shit that ignores the inconsistencies, that can cause hard-to-debug errors, it is another reason to never use plain C compiler) * added some abstraction layer addressing the deprecations in C++ >=17 Also the editor has removed the unneeded whitespaces, it was noticed too late to address, so let these changes be here too.
1 parent 2895fa0 commit 792e0e2

Some content is hidden

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

70 files changed

+1034
-991
lines changed

src/compiler_abs_layer.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#ifndef COMPILER_ABS_LAYER_H
3+
#define COMPILER_ABS_LAYER_H
4+
5+
#if defined(__cplusplus) && __cplusplus >= 201703L
6+
#define REGISTER
7+
#else
8+
#define REGISTER register
9+
#endif
10+
11+
#endif // COMPILER_ABS_LAYER_H

src/crypto-blackrock2.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ blackrock2_init(struct BlackRock *br, uint64_t range, uint64_t seed, unsigned ro
285285

286286
/***************************************************************************
287287
* The inner round/mixer function. In DES, it's a series of S-box lookups,
288-
* which
288+
* which
289289
***************************************************************************/
290290
static inline uint64_t
291291
ROUND(uint64_t r, uint64_t R, uint64_t seed)
292292
{
293293
#define GETBYTE(R,n) ((uint64_t)(((((R)>>(n*8ULL)))&0xFFULL)))
294-
#if 0
294+
#if 0
295295
uint64_t r0, r1, r2, r3;
296296
#endif
297297
uint64_t T, Y;
@@ -308,7 +308,7 @@ ROUND(uint64_t r, uint64_t R, uint64_t seed)
308308
Y = SB7[ (T ) & 0x3F ] ^ \
309309
SB5[ (T >> 8) & 0x3F ] ^ \
310310
SB3[ (T >> 16) & 0x3F ] ^ \
311-
SB1[ (T >> 24) & 0x3F ];
311+
SB1[ (T >> 24) & 0x3F ];
312312
}
313313
return Y;
314314
#if 0
@@ -451,8 +451,8 @@ verify(struct BlackRock *br, uint64_t max)
451451
uint64_t range = br->range;
452452

453453
/* Allocate a list of 1-byte counters */
454-
list = CALLOC(1, (size_t)((range<max)?range:max));
455-
454+
list = (unsigned char *) CALLOC(1, (size_t)((range<max)?range:max));
455+
456456
/* For all numbers in the range, verify increment the counter for the
457457
* the output. */
458458
for (i=0; i<range; i++) {

src/event-timeout.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
/***************************************************************************
37-
* The timeout system is a circular ring. We move an index around the
37+
* The timeout system is a circular ring. We move an index around the
3838
* ring. At each slot in the ring is a linked-list of all entries at
3939
* that time index. Because the ring can wrap, not everything at a given
4040
* entry will be the same timestamp. Therefore, when doing the timeout
@@ -70,8 +70,8 @@ timeouts_create(uint64_t timestamp)
7070
/*
7171
* Allocate memory and initialize it to zero
7272
*/
73-
timeouts = CALLOC(1, sizeof(*timeouts));
74-
73+
timeouts = (struct Timeouts *) CALLOC(1, sizeof(*timeouts));
74+
7575
/*
7676
* We just mask off the low order bits to determine wrap. I'm using
7777
* a variable here because one of these days I'm going to make
@@ -107,7 +107,7 @@ timeouts_add(struct Timeouts *timeouts, struct TimeoutEntry *entry,
107107
timeout_unlink(entry);
108108

109109
if (entry->prev) {
110-
LOG(1, "***CHANGE %d-seconds\n",
110+
LOG(1, "***CHANGE %d-seconds\n",
111111
(int)((timestamp-entry->timestamp)/TICKS_PER_SECOND));
112112
}
113113

src/in-binary.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ parse_status(struct Output *out,
6464
case 53:
6565
case 123:
6666
case 137:
67-
case 161:
67+
case 161:
6868
record.ip_proto = 17;
6969
break;
7070
case 36422:
@@ -166,7 +166,7 @@ _get_integer(const unsigned char *buf, size_t length, size_t *r_offset)
166166
unsigned result;
167167
size_t offset = *r_offset;
168168
(*r_offset) += 4;
169-
169+
170170
if (offset + 4 <= length) {
171171
result = buf[offset+0]<<24
172172
| buf[offset+1]<<16
@@ -183,7 +183,7 @@ _get_short(const unsigned char *buf, size_t length, size_t *r_offset)
183183
unsigned short result;
184184
size_t offset = *r_offset;
185185
(*r_offset) += 2;
186-
186+
187187
if (offset + 2 <= length) {
188188
result = buf[offset+0]<<8
189189
| buf[offset+1]<<0;
@@ -199,7 +199,7 @@ _get_long(const unsigned char *buf, size_t length, size_t *r_offset)
199199
unsigned long long result;
200200
size_t offset = *r_offset;
201201
(*r_offset) += 8;
202-
202+
203203
if (offset + 8 <= length) {
204204
result =
205205
(unsigned long long)buf[offset+0]<<56ULL
@@ -286,7 +286,7 @@ parse_banner6(struct Output *out, unsigned char *buf, size_t length,
286286
record.timestamp = _get_integer(buf, length, &offset);
287287
record.ip_proto = _get_byte(buf, length, &offset);
288288
record.port = _get_short(buf, length, &offset);
289-
record.app_proto = _get_short(buf, length, &offset);
289+
record.app_proto = (enum ApplicationProtocol) _get_short(buf, length, &offset);
290290
record.ttl = _get_byte(buf, length, &offset);
291291
record.ip.version= _get_byte(buf, length, &offset);
292292
if (record.ip.version != 6) {
@@ -295,18 +295,18 @@ parse_banner6(struct Output *out, unsigned char *buf, size_t length,
295295
}
296296
record.ip.ipv6.hi = _get_long(buf, length, &offset);
297297
record.ip.ipv6.lo = _get_long(buf, length, &offset);
298-
298+
299299
if (out->when_scan_started == 0)
300300
out->when_scan_started = record.timestamp;
301301

302-
302+
303303
/*
304304
* Filter out records if requested
305305
*/
306306
if (!readscan_filter_pass(record.ip, record.port, record.app_proto,
307307
filter, btypes))
308308
return;
309-
309+
310310
/*
311311
* Now print the output
312312
*/
@@ -343,7 +343,7 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length)
343343
record.ip.ipv4 = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7];
344344
record.ip.version = 4;
345345
record.port = buf[8]<<8 | buf[9];
346-
record.app_proto = buf[10]<<8 | buf[11];
346+
record.app_proto = (enum ApplicationProtocol) (buf[10]<<8 | buf[11]);
347347

348348
if (out->when_scan_started == 0)
349349
out->when_scan_started = record.timestamp;
@@ -383,7 +383,7 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
383383
record.ip.version = 4;
384384
record.ip_proto = buf[8];
385385
record.port = buf[9]<<8 | buf[10];
386-
record.app_proto = buf[11]<<8 | buf[12];
386+
record.app_proto = (enum ApplicationProtocol) (buf[11]<<8 | buf[12]);
387387

388388
if (out->when_scan_started == 0)
389389
out->when_scan_started = record.timestamp;
@@ -426,7 +426,7 @@ parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length,
426426
record.ip.version = 4;
427427
record.ip_proto = buf[8];
428428
record.port = buf[9]<<8 | buf[10];
429-
record.app_proto = buf[11]<<8 | buf[12];
429+
record.app_proto = (enum ApplicationProtocol) (buf[11]<<8 | buf[12]);
430430
record.ttl = buf[13];
431431

432432
if (out->when_scan_started == 0)
@@ -445,7 +445,7 @@ parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length,
445445
if (!readscan_filter_pass(record.ip, record.port, record.app_proto,
446446
filter, btypes))
447447
return;
448-
448+
449449
/*
450450
* Now print the output
451451
*/
@@ -476,7 +476,7 @@ _binaryfile_parse(struct Output *out, const char *filename,
476476
int x;
477477

478478
/* Allocate a buffer of up to one megabyte per record */
479-
buf = MALLOC(BUF_MAX);
479+
buf = (unsigned char *) MALLOC(BUF_MAX);
480480

481481
/* Open the file */
482482
x = fopen_s(&fp, filename, "rb");
@@ -642,7 +642,7 @@ _binaryfile_parse(struct Output *out, const char *filename,
642642
*****************************************************************************/
643643
void
644644
read_binary_scanfile(struct Masscan *masscan,
645-
int arg_first, int arg_max, char *argv[])
645+
int arg_first, int arg_max, const char *argv[])
646646
{
647647
struct Output *out;
648648
int i;
@@ -651,7 +651,7 @@ read_binary_scanfile(struct Masscan *masscan,
651651

652652

653653
out = output_create(masscan, 0);
654-
654+
655655
/*
656656
* Set the start time to zero. We'll read it from the first file
657657
* that we parse

src/in-binary.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct Masscan;
99
* JSON or XML.
1010
*/
1111
void
12-
read_binary_scanfile(struct Masscan *masscan,
13-
int arg_first, int arg_max, char *argv[]);
12+
read_binary_scanfile(struct Masscan *masscan,
13+
int arg_first, int arg_max, const char *argv[]);
1414

1515
#endif
1616

src/in-report.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static const char *
3030
cndb_lookup(unsigned ip)
3131
{
3232
const struct CNDB_Entry *entry;
33-
33+
3434
if (db == NULL)
3535
return 0;
3636

@@ -53,14 +53,14 @@ cndb_add(unsigned ip, const unsigned char *name, size_t name_length)
5353

5454
if (name_length == 0)
5555
return;
56-
56+
5757
if (db == NULL) {
58-
db = CALLOC(1, sizeof(*db));
58+
db = (struct CNDB_Database *) CALLOC(1, sizeof(*db));
5959
}
60-
61-
entry = MALLOC(sizeof(*entry));
60+
61+
entry = (struct CNDB_Entry *) MALLOC(sizeof(*entry));
6262
entry->ip =ip;
63-
entry->name = MALLOC(name_length+1);
63+
entry->name = (char *) MALLOC(name_length+1);
6464
memcpy(entry->name, name, name_length+1);
6565
entry->name[name_length] = '\0';
6666
entry->next = db->entries[ip&0xFFFF];
@@ -77,15 +77,15 @@ cndb_add_cn(unsigned ip, const unsigned char *data, size_t length)
7777
size_t offset = 0;
7878
size_t name_offset;
7979
size_t name_length;
80-
80+
8181
if (length < 7)
8282
return;
83-
83+
8484
/*cipher:0x39 , safe-we1.dyndns.org*/
8585
if (memcmp(data+offset, "cipher:", 7) != 0)
8686
return;
8787
offset += 7;
88-
88+
8989
/* skip to name */
9090
while (offset < length && data[offset] != ',')
9191
offset++;
@@ -97,13 +97,13 @@ cndb_add_cn(unsigned ip, const unsigned char *data, size_t length)
9797
offset++;
9898
if (offset >= length)
9999
return;
100-
100+
101101
/* we should have a good name */
102102
name_offset = offset;
103103
while (offset < length && data[offset] != ',')
104104
offset++;
105105
name_length = offset - name_offset;
106-
106+
107107
/* now insert into database */
108108
cndb_add(ip, data+name_offset, name_length);
109109
}
@@ -116,7 +116,7 @@ static unsigned
116116
found(const char *str, size_t str_len, const unsigned char *p, size_t length)
117117
{
118118
size_t i;
119-
119+
120120
if (str_len > length)
121121
return 0;
122122

@@ -181,9 +181,9 @@ struct Names {
181181
/* raspberry pi */
182182
/* issuer[Debian */
183183

184-
185-
186-
184+
185+
186+
187187

188188

189189
{XNas, 9, "nasend~~]"},
@@ -198,14 +198,14 @@ struct Names {
198198
{Xav, 16, "issuer[Kaspersky"},
199199
{XFW, 17, "subject[Fortinet]"},
200200
{XFW, 17, "issuer[ICC-FW CA]"},
201-
{XCam, 17, "issuer[HIKVISION]"},
201+
{XCam, 17, "issuer[HIKVISION]"},
202202
{Xprint,17, "subject[SHARP MX-"},
203203
{X509, 18, "issuer[GANDI SAS]"},
204204
{XFW, 18, "subject[FortiGate]"},
205205
{XFW, 18, "issuer[watchguard]"},
206-
{XVM, 18, "issuer[VMware Inc]"},
206+
{XVM, 18, "issuer[VMware Inc]"},
207207
{Xbox, 19, "issuer[eBox Server]"},
208-
{XFW, 19, "subject[WatchGuard]"},
208+
{XFW, 19, "subject[WatchGuard]"},
209209
{X509, 19, "issuer[RapidSSL CA]"},
210210
{X509, 19, "issuer[AddTrust AB]"},
211211
{XCom, 19, "issuer[Cisco SSCA2]"},
@@ -217,7 +217,7 @@ struct Names {
217217
{XMail, 20, "issuer[EQ-MT-RAPTOR]"},
218218
{X509, 20, "issuer[DigiCert Inc]"},
219219
{X509, 21, "issuer[TERENA SSL CA]"},
220-
{XFW, 21, "issuer[WatchGuard CA]"},
220+
{XFW, 21, "issuer[WatchGuard CA]"},
221221
{XVPN, 21, "issuer[OpenVPN Web CA"},
222222
{X509, 21, "issuer[GeoTrust Inc.]"},
223223
{XNas, 21, "issuer[TS Series NAS]"},
@@ -227,9 +227,9 @@ struct Names {
227227
{Xdefault,21,"issuer[XX] issuer[XX]"},
228228
{XWiFi, 21, "2Wire]Gateway Device]"},
229229
{X509, 21, "subject[DigiCert Inc]"},
230-
{XCam, 22, "issuer[SamsungTechwin]"},
230+
{XCam, 22, "issuer[SamsungTechwin]"},
231231
{X509, 22, "issuer[TAIWAN-CA INC.]"},
232-
{X509, 22, "issuer[GeoTrust, Inc.]"},
232+
{X509, 22, "issuer[GeoTrust, Inc.]"},
233233
{X509, 22, "issuer[ValiCert, Inc.]"},
234234
{0, 22, "issuer[Apache Friends]"},
235235
{X509, 22, "issuer[VeriSign, Inc.]"},
@@ -242,7 +242,7 @@ struct Names {
242242
{X509, 24, "issuer[GlobalSign nv-sa]"},
243243
{XVPN, 24, "SonicWALL, Inc.]SSL-VPN]"},
244244
{X509, 25, "issuer[Comodo CA Limited]"},
245-
{X509, 25, "issuer[COMODO CA Limited]"},
245+
{X509, 25, "issuer[COMODO CA Limited]"},
246246
{X509, 25, "issuer[GoDaddy.com, Inc.]"},
247247
{Xbox, 26, "subject[Barracuda Networks]"},
248248
{X509, 26, "issuer[Equifax Secure Inc.]"},
@@ -266,7 +266,7 @@ struct Names {
266266
{XVPN, 35, "SonicWALL, Inc.]Secure Remote Access]"},
267267
{X509, 40, "issuer[Secure Digital Certificate Signing]"},
268268
{X509, 40, "issuer[Equifax Secure Certificate Authority]"},
269-
{XVM, 40, "subject[VMware ESX Server Default Certificate]"},
269+
{XVM, 40, "subject[VMware ESX Server Default Certificate]"},
270270
{XCam, 40, "issuer[Cisco Systems] issuer[Cisco Manufacturing CA]"},
271271
{0,0, 0}
272272
};
@@ -318,7 +318,7 @@ found_type(const unsigned char *banner, size_t banner_length)
318318
(unsigned)banner_length);
319319
if (id == SMACK_NOT_FOUND)
320320
return 0;
321-
321+
322322
counts[id]++;
323323

324324
return 1;
@@ -335,7 +335,7 @@ readscan_report( unsigned ip,
335335

336336

337337
if (app_proto == PROTO_X509_CERT) {
338-
unsigned char *der = MALLOC(data_length);
338+
unsigned char *der = (unsigned char *) MALLOC(data_length);
339339
struct CertDecode x;
340340
size_t der_length;
341341
struct BannerOutput banout[1];
@@ -345,7 +345,7 @@ readscan_report( unsigned ip,
345345
banout_init(banout);
346346

347347
der_length = base64_decode(der, data_length, data, data_length);
348-
348+
349349
x509_decode_init(&x, data_length);
350350
x.is_capture_issuer = 1;
351351
x.is_capture_subject = 1;
@@ -364,7 +364,7 @@ readscan_report( unsigned ip,
364364
cndb_add(ip, data, data_length);*/
365365
} else if (app_proto == PROTO_VULN) {
366366
const char *name = cndb_lookup(ip);
367-
367+
368368
if (data_length == 15 && memcmp(data, "SSL[heartbeat] ", 15) == 0)
369369
return;
370370

0 commit comments

Comments
 (0)