Skip to content

Commit

Permalink
temp fix for count_cidr4_bits()
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdavidgraham committed Nov 1, 2023
1 parent b1abb7a commit f3d0bd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
36 changes: 27 additions & 9 deletions src/main-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ print_nmap_help(void)
"\n");
}

/***************************************************************************
***************************************************************************/
static unsigned
count_cidr4_bits(struct Range range) {
unsigned i;
for (i=0; i<32; i++) {
unsigned mask = 0xFFFFFFFF >> i;

if ((range.begin & ~mask) == (range.end & ~mask)) {
if ((range.begin & mask) == 0 && (range.end & mask) == mask)
return i;
}
}
return 0;
}

/***************************************************************************
***************************************************************************/
static unsigned
Expand Down Expand Up @@ -3455,8 +3471,9 @@ mainconf_selftest()
char test[] = " test 1 ";

trim(test, sizeof(test));
if (strcmp(test, "test 1") != 0)
return 1; /* failure */
if (strcmp(test, "test 1") != 0) {
goto failure;
}

{
struct Range range;
Expand All @@ -3465,14 +3482,12 @@ mainconf_selftest()
range.end = 32-1;
bool exact = false;
if (count_cidr_bits(&range, &exact) != 28 || !exact)
return 1;
goto failure;

exact = true;
range.begin = 1;
range.end = 13;
if (count_cidr_bits(&range, &exact) != 0 || !exact)
return 1;

if (count_cidr4_bits(range) != 0)
goto failure;

}

Expand All @@ -3482,12 +3497,15 @@ mainconf_selftest()
char *argv[] = { "foo", "bar", "-ddd", "--readscan", "xxx", "--something" };

if (masscan_conf_contains("--nothing", argc, argv))
return 1;
goto failure;

if (!masscan_conf_contains("--readscan", argc, argv))
return 1;
goto failure;
}

return 0;
failure:
fprintf(stderr, "[+] selftest failure: config subsystem\n");
return 1;
}

5 changes: 3 additions & 2 deletions src/massip-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ massip_parse_file(struct MassIP *massip, const char *filename)
struct massip_parser p[1];
char buf[65536];
FILE *fp = NULL;
int err;
bool is_error = false;
unsigned addr_count = 0;
unsigned long long line_number, char_number;
Expand All @@ -837,8 +836,8 @@ massip_parse_file(struct MassIP *massip, const char *filename)
*/
if (strcmp(filename, "-") == 0) {
fp = stdin;
err = 0;
} else {
int err;
err = fopen_s(&fp, filename, "rb");
if (err || fp == NULL) {
perror(filename);
Expand Down Expand Up @@ -867,6 +866,7 @@ massip_parse_file(struct MassIP *massip, const char *filename)
offset = 0;
while (offset < count) {
unsigned begin, end;
int err;

err = _parser_next(p, buf, &offset, count, &begin, &end);
switch (err) {
Expand Down Expand Up @@ -909,6 +909,7 @@ massip_parse_file(struct MassIP *massip, const char *filename)
if (!is_error) {
size_t offset = 0;
unsigned begin, end;
int err;
err = _parser_next(p, "\n", &offset, 1, &begin, &end);
switch (err) {
case Still_Working:
Expand Down
6 changes: 6 additions & 0 deletions xcode4/masscan.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
11420DE019A90CB300DB5BFE /* proto-interactive.c in Sources */ = {isa = PBXBuildFile; fileRef = 11420DDF19A90CB300DB5BFE /* proto-interactive.c */; };
11420DE319A9363B00DB5BFE /* proto-imap4.c in Sources */ = {isa = PBXBuildFile; fileRef = 11420DE219A9363A00DB5BFE /* proto-imap4.c */; };
11469CA22295D80A00FA76BE /* misc-rstfilter.c in Sources */ = {isa = PBXBuildFile; fileRef = 11469CA12295D80A00FA76BE /* misc-rstfilter.c */; };
1155CF102AF2FE12001B235A /* proto-mc.c in Sources */ = {isa = PBXBuildFile; fileRef = 1155CF0F2AF2FE12001B235A /* proto-mc.c */; };
115C0CAB18035BC5004E6CD7 /* proto-netbios.c in Sources */ = {isa = PBXBuildFile; fileRef = 115C0CA518035BC5004E6CD7 /* proto-netbios.c */; };
115C0CAC18035BC5004E6CD7 /* proto-ssl.c in Sources */ = {isa = PBXBuildFile; fileRef = 115C0CA718035BC5004E6CD7 /* proto-ssl.c */; };
11623F6A191E0DB00075EEE6 /* out-certs.c in Sources */ = {isa = PBXBuildFile; fileRef = 11623F69191E0DB00075EEE6 /* out-certs.c */; };
Expand Down Expand Up @@ -158,6 +159,8 @@
11420DE219A9363A00DB5BFE /* proto-imap4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "proto-imap4.c"; sourceTree = "<group>"; };
11469CA02295D80A00FA76BE /* misc-rstfilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "misc-rstfilter.h"; sourceTree = "<group>"; };
11469CA12295D80A00FA76BE /* misc-rstfilter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "misc-rstfilter.c"; sourceTree = "<group>"; };
1155CF0E2AF2FE12001B235A /* proto-mc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "proto-mc.h"; sourceTree = "<group>"; };
1155CF0F2AF2FE12001B235A /* proto-mc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "proto-mc.c"; sourceTree = "<group>"; };
115C0CA318035BC5004E6CD7 /* out-record.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "out-record.h"; sourceTree = "<group>"; };
115C0CA418035BC5004E6CD7 /* proto-dns-parse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "proto-dns-parse.h"; sourceTree = "<group>"; };
115C0CA518035BC5004E6CD7 /* proto-netbios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "proto-netbios.c"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -524,6 +527,8 @@
11B360CA1F9016C00020F3A3 /* proto */ = {
isa = PBXGroup;
children = (
1155CF0F2AF2FE12001B235A /* proto-mc.c */,
1155CF0E2AF2FE12001B235A /* proto-mc.h */,
11A921AC17DBCC7E00DDFD32 /* proto-arp.c */,
11A921AD17DBCC7E00DDFD32 /* proto-arp.h */,
11A921AE17DBCC7E00DDFD32 /* proto-banner1.c */,
Expand Down Expand Up @@ -786,6 +791,7 @@
119AB2062051FFED008E4DDD /* proto-memcached.c in Sources */,
11DD36462107EB8700CBE1DE /* scripting-masscan.c in Sources */,
118B9B3525A00FA900F5FB0B /* massip.c in Sources */,
1155CF102AF2FE12001B235A /* proto-mc.c in Sources */,
11BE533625A6441100451F95 /* massip-addr.c in Sources */,
11B039C117E506B400925E7E /* main-listscan.c in Sources */,
11B039C717E7834000925E7E /* proto-dns.c in Sources */,
Expand Down

0 comments on commit f3d0bd9

Please sign in to comment.