Commit 8d8956d7 authored by Robert David Graham's avatar Robert David Graham
Browse files

warnings

parent 17a19cfe
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
    translate the binary format into something more easily parsed, such
    as the XML or JSON formats.
*/
#include "in-binary.h"
#include "masscan.h"
#include "masscan-app.h"
#include "main-globals.h"
@@ -92,7 +93,7 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length)
 * Parse the BANNER record, extracting the timestamp, IP addres, and port
 * number. We also convert the banner string into a safer form.
 ***************************************************************************/
void
static void
parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
{
    struct MasscanRecord record;
@@ -123,7 +124,7 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length)
/***************************************************************************
 * Read in the file, one record at a time.
 ***************************************************************************/
uint64_t
static uint64_t
parse_file(struct Output *out, const char *filename)
{
    FILE *fp = 0;
+1 −1
Original line number Diff line number Diff line
#ifndef IN_BINARY_H
#define IN_BINARY_H

struct Masscan;
void
convert_binary_files(struct Masscan *masscan, int arg_first, int arg_max, char *argv[]);

+2 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ void LOG_add_level(int x)

/***************************************************************************
 ***************************************************************************/
void
static void
vLOG(int level, const char *fmt, va_list marker)
{
    if (level <= global_debug_level) {
@@ -46,7 +46,7 @@ LOG(int level, const char *fmt, ...)

/***************************************************************************
 ***************************************************************************/
void
static void
vLOGip(int level, unsigned ip, unsigned port, const char *fmt, va_list marker)
{
    if (level <= global_debug_level) {
+45 −28
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@

/***************************************************************************
 ***************************************************************************/
void masscan_usage(void)
void
masscan_usage(void)
{
    printf("usage:\n");
    printf("masscan -p80,8000-8100 10.0.0.0/8 --rate=10000\n");
@@ -172,7 +173,7 @@ masscan_echo_nic(struct Masscan *masscan, FILE *fp, unsigned i)
 * Use#1: create a template file of all setable parameters.
 * Use#2: make sure your configuration was interpreted correctly.
 ***************************************************************************/
void
static void
masscan_echo(struct Masscan *masscan, FILE *fp)
{
    unsigned i;
@@ -316,9 +317,19 @@ masscan_save_state(struct Masscan *masscan)
}


/***************************************************************************
 ***************************************************************************/
void ranges_from_file(struct RangeList *ranges, const char *filename)
/*****************************************************************************
 * Read in ranges from a file
 *
 * There can be multiple ranges on a line, delimited by spaces. In fact,
 * millions of ranges can be on a line: there is limit to the line length.
 * That makes reading the file a little bit squirrelly. From one perspective
 * this parser doesn't treat the the new-line '\n' any different than other
 * space. But, from another perspective, it has to, because things like
 * comments are terminated by a newline. Also, it has to count the number
 * of lines correctly to print error messages.
 *****************************************************************************/
static void
ranges_from_file(struct RangeList *ranges, const char *filename)
{
    FILE *fp;
    errno_t err;
@@ -327,21 +338,19 @@ void ranges_from_file(struct RangeList *ranges, const char *filename)

    err = fopen_s(&fp, filename, "rt");
    if (err) {
        //char dirname[256];
        perror(filename);
        //fprintf(stderr, "dir = %s\n", getcwd(dirname));
        exit(1); /* HARD EXIT: because if it's an exclusion file, we don't
                  * want to continue. We don't want ANY chance of
                  * accidentally scanning somebody */
    }

    /* for all lines */
    while (!feof(fp)) {
        int c = '\n';

        /* remove leading whitespace */
        while (!feof(fp)) {
            c = getc(fp);
            line_number += (c == '\n');
            if (!isspace(c&0xFF))
                break;
        }
@@ -350,37 +359,43 @@ void ranges_from_file(struct RangeList *ranges, const char *filename)
        if (ispunct(c&0xFF)) {
            while (!feof(fp)) {
                c = getc(fp);
                line_number += (c == '\n');
                if (c == '\n') {
                    line_number++;
                    break;
                }
            }
            /* Loop back to the begining state at the start of a line */
            continue;
        }

        if (c == '\n') {
            line_number++;
            continue;
        }

        /*
         * Read all space delimited entries
         * Read in a single entry
         */
        while (!feof(fp) && c != '\n') {
        if (!feof(fp)) {
            char address[64];
            size_t i;
            struct Range range;
            unsigned offset = 0;


            /* fetch next address range */
            /* Grab all bytes until the next space or comma */
            address[0] = (char)c;
            i = 1;
            while (!feof(fp)) {
                c = getc(fp);
                if (isspace(c&0xFF))
                line_number += (c == '\n');
                if (isspace(c&0xFF) || c == ',') {
                    break;
                if (i+1 < sizeof(address))
                }
                if (i+1 >= sizeof(address)) {
                    LOG(0, "%s:%u:%u: bad address spec: \"%.*s\"\n",
                            filename, line_number, offset, i, address);
                    exit(1);
                } else
                    address[i] = (char)c;
                i++;
            }
@@ -389,14 +404,14 @@ void ranges_from_file(struct RangeList *ranges, const char *filename)
            /* parse the address range */
            range = range_parse_ipv4(address, &offset, (unsigned)i);
            if (range.begin == 0xFFFFFFFF && range.end == 0) {
                fprintf(stderr, "%s:%u:%u: bad range spec: %s\n", 
                        filename, line_number, offset, address);
                LOG(0, "%s:%u:%u: bad range spec: \"%.*s\"\n", 
                        filename, line_number, offset, i, address);
                exit(1);
            } else {
                rangelist_add_range(ranges, range.begin, range.end);
            }
        }

        line_number++;
    }

    fclose(fp);
@@ -582,7 +597,7 @@ ARRAY(const char *rhs)
 * Called either from the "command-line" parser when it sees a --parm,
 * or from the "config-file" parser for normal options.
 ***************************************************************************/
void
static void
masscan_set_parameter(struct Masscan *masscan, 
                      const char *name, const char *value)
{
@@ -821,7 +836,7 @@ masscan_set_parameter(struct Masscan *masscan,
            range = range_parse_ipv4(ranges, &offset, max_offset);
            if (range.begin == 0 && range.end == 0) {
                fprintf(stderr, "CONF: bad range spec: %s\n", ranges);
                break;
                exit(1);
            }

            rangelist_add_range(&masscan->exclude_ip, range.begin, range.end);
@@ -887,7 +902,7 @@ masscan_set_parameter(struct Masscan *masscan,
                masscan->http_user_agent_length+1
                );
    } else if (memcmp("http-header", name, 11) == 0) {
        unsigned index;
        unsigned j;
        unsigned name_length;
        char *newname;
        unsigned value_length = (unsigned)strlen(value);
@@ -910,11 +925,11 @@ masscan_set_parameter(struct Masscan *masscan,
        newname[name_length] = '\0';

        
        for (index=0; index < sizeof(masscan->http_headers)/sizeof(masscan->http_headers[0]); index++) {
            if (masscan->http_headers[index].header_name == 0) {
                masscan->http_headers[index].header_name = newname;
                masscan->http_headers[index].header_value = newvalue;
                masscan->http_headers[index].header_value_length = value_length;
        for (j=0; j < sizeof(masscan->http_headers)/sizeof(masscan->http_headers[0]); j++) {
            if (masscan->http_headers[j].header_name == 0) {
                masscan->http_headers[j].header_name = newname;
                masscan->http_headers[j].header_value = newvalue;
                masscan->http_headers[j].header_value_length = value_length;
                return;
            }
        }
@@ -1203,7 +1218,9 @@ is_singleton(const char *name)
    return 0;
}

void
/*****************************************************************************
 *****************************************************************************/
static void
masscan_help()
{
    printf(
+5 −2
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
    We can mimimize this with a table remembering recent responses. Occassional
    duplicates still leak through, but it'll be less of a problem.
*/
#include "main-dedup.h"
#include <stdlib.h>
#include <string.h>

@@ -29,7 +30,7 @@ struct DedupTable
/***************************************************************************
 ***************************************************************************/
struct DedupTable *
dedup_create()
dedup_create(void)
{
    struct DedupTable *result;

@@ -53,7 +54,9 @@ dedup_destroy(struct DedupTable *table)
/***************************************************************************
 ***************************************************************************/
unsigned
dedup_is_duplicate(struct DedupTable *dedup, unsigned ip_them, unsigned port_them, unsigned ip_me, unsigned port_me)
dedup_is_duplicate(struct DedupTable *dedup, 
                   unsigned ip_them, unsigned port_them, 
                   unsigned ip_me, unsigned port_me)
{
    unsigned hash;
    struct DedupEntry *bucket;
Loading