Commit a9d51d35 authored by Robert David Graham's avatar Robert David Graham
Browse files

static analysis fixes

parent 4b69e62b
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -1351,12 +1351,15 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
 * remove leading/trailing whitespace
 ***************************************************************************/
static void
trim(char *line)
trim(char *line, size_t sizeof_line)
{
    if (sizeof_line > strlen(line))
        sizeof_line = strlen(line);
    
    while (isspace(*line & 0xFF))
        memmove(line, line+1, strlen(line));
    while (isspace(line[strlen(line)-1] & 0xFF))
        line[strlen(line)-1] = '\0';
        memmove(line, line+1, sizeof_line--);
    while (isspace(line[sizeof_line-1] & 0xFF))
        line[--sizeof_line] = '\0';
}

/***************************************************************************
@@ -1378,7 +1381,7 @@ masscan_read_config_file(struct Masscan *masscan, const char *filename)
        char *name;
        char *value;

        trim(line);
        trim(line, sizeof(line));

        if (ispunct(line[0] & 0xFF) || line[0] == '\0')
            continue;
@@ -1389,11 +1392,26 @@ masscan_read_config_file(struct Masscan *masscan, const char *filename)
            continue;
        *value = '\0';
        value++;
        trim(name);
        trim(value);
        trim(name, sizeof(line));
        trim(value, sizeof(line));

        masscan_set_parameter(masscan, name, value);
    }

    fclose(fp);
}


/***************************************************************************
 ***************************************************************************/
int
mainconf_selftest()
{
    char test[] = " test 1 ";
    
    trim(test, sizeof(test));
    if (strcmp(test, "test 1") != 0)
        return 1; /* failure */
    
    return 0;
}
 No newline at end of file
+24 −2
Original line number Diff line number Diff line
@@ -500,6 +500,10 @@ receive_thread(void *v)
            );
    }

    /*
     * In "offline" mode, we don't have any receive threads, so simply
     * wait until transmitter thread is done then go to the end
     */
    if (masscan->is_offline) {
        while (!control_c_pressed_again)
            pixie_usleep(10000);
@@ -780,6 +784,16 @@ end:
    if (pcapfile)
        pcapfile_close(pcapfile);

    for (;;) {
        void *p;
        int err;
        err = rte_ring_sc_dequeue(parms->packet_buffers, (void**)&p);
        if (err == 0)
            free(p);
        else
            break;
    }
    
    /* Thread is about to exit */
    parms->done_receiving = 1;
}
@@ -959,7 +973,9 @@ main_scan(struct Masscan *masscan)
        {
            unsigned i;
            for (i=0; i<BUFFER_COUNT-1; i++) {
                struct PacketBuffer *p = (struct PacketBuffer *)malloc(sizeof(*p));
                struct PacketBuffer *p;
                
                p = (struct PacketBuffer *)malloc(sizeof(*p));
                if (p == NULL)
                    exit(1);
                err = rte_ring_sp_enqueue(parms->packet_buffers, p);
@@ -1095,7 +1111,12 @@ main_scan(struct Masscan *masscan)
    }    


    /*
     * Now cleanup everything
     */
    status_finish(&status);
    rangelist_pick2_destroy(picker);
    
    return 0;
}

@@ -1234,6 +1255,7 @@ int main(int argc, char *argv[])
            x += rte_ring_selftest();
            x += smack_selftest();
            x += banner1_selftest();
            x += mainconf_selftest();


            if (x != 0) {
+1 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ struct Masscan
};


int mainconf_selftest(void);
void masscan_read_config_file(struct Masscan *masscan, const char *filename);
void masscan_command_line(struct Masscan *masscan, int argc, char *argv[]);
void masscan_usage();
+4 −2
Original line number Diff line number Diff line
@@ -374,7 +374,8 @@ output_do_rotate(struct Output *out)

    err = 0;
again:
    sprintf_s(new_filename, new_filename_size, "%s/%02u%02u%02u-%02u%02u%02u" "-%s",
    sprintf_s(new_filename, new_filename_size, 
              "%s/%02u%02u%02u-%02u%02u%02u" "-%s",
        dir,
        tm.tm_year % 100,
        tm.tm_mon+1,
@@ -403,6 +404,7 @@ again:
    out->next_rotate = next_rotate(time(0), out->period, out->offset);

    LOG(1, "rotated: %s\n", new_filename);
    free(new_filename);
    
    /*
     * Now create a new file
+10 −1
Original line number Diff line number Diff line
@@ -215,7 +215,16 @@ pixie_nanotime()

void pixie_usleep(uint64_t microseconds)
{
    usleep(microseconds);
    struct timespec t;
    t.tv_nsec = microseconds * 1000;
    if (microseconds > 1000000)
        t.tv_sec = microseconds/1000000;
    else {
        t.tv_sec = 0;
    }
    
    nanosleep(&t, 0);
    //usleep(microseconds);
}
void
pixie_mssleep(unsigned milliseconds)
Loading