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
428431ranges_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
23342335static 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
38663869masscan_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 );
0 commit comments