Commit 093cbc91 authored by Robert David Graham's avatar Robert David Graham
Browse files

cleanup

parent 3d6e9847
Loading
Loading
Loading
Loading
+91 −23
Original line number Diff line number Diff line
@@ -3,11 +3,13 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>

/****************************************************************************
 ****************************************************************************/
/*****************************************************************************
 *****************************************************************************/
size_t
base64_encode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src)
base64_encode(void *vdst, size_t sizeof_dst, 
              const void *vsrc, size_t sizeof_src)
{
    static const char *b64 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -19,6 +21,7 @@ base64_encode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src
    unsigned char *dst = (unsigned char *)vdst;
    const unsigned char *src = (const unsigned char *)vsrc;

    /* encode every 3 bytes of source into 4 bytes of destination text */
    while (i + 3 <= sizeof_src) {
        unsigned n;
        
@@ -26,7 +29,7 @@ base64_encode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src
        if (d + 4 > sizeof_dst)
            return d;

        /* conver the chars */
        /* convert the chars */
        n = src[i]<<16 | src[i+1]<<8 | src[i+2];
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
@@ -37,6 +40,8 @@ base64_encode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src
        d += 4;
    }

    /* If the source text isn't an even multiple of 3 characters, then we'll
     * have to append a '=' or '==' to the output to compensate */
    if (i + 2 <= sizeof_src && d + 4 <= sizeof_dst) {
        unsigned n = src[i]<<16 | src[i+1]<<8;
        dst[d+0] = b64[ (n>>18) & 0x3F ];
@@ -57,28 +62,45 @@ base64_encode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src
}


/****************************************************************************
 ****************************************************************************/
/*****************************************************************************
 *****************************************************************************/
size_t
base64_decode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src)
base64_decode(void *vdst, size_t sizeof_dst, 
              const void *vsrc, size_t sizeof_src)
{
	static const unsigned char rstr[] = {
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,	62,		0xFF,   0xFF,   0xFF,	63,
		52,		53,		54,		55,		56,		57,		58,		59,		60,		61,		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0,		1,		2,		3,		4,		5,		6,		7,		8,		9,		10,		11,		12,		13,		14,
		15,		16,		17,		18,		19,		20,		21,		22,		23,		24,		25,		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,	26,		27,		28,		29,		30,		31,		32,		33,		34,		35,		36,		37,		38,		39,		40,
		41,		42,		43,		44,		45,		46,		47,		48,		49,		50,		51,		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,	62,		0xFF,   0xFF,   0xFF,	63,
		52,		53,		54,		55,		56,		57,		58,		59,		
        60,		61,		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0,		1,		2,		3,		4,		5,		6,		
        7,		8,		9,		10,		11,		12,		13,		14,
		15,		16,		17,		18,		19,		20,		21,		22,		
        23,		24,		25,		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,	26,		27,		28,		29,		30,		31,		32,		
        33,		34,		35,		36,		37,		38,		39,		40,
		41,		42,		43,		44,		45,		46,		47,		48,		
        49,		50,		51,		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
		0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   
        0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,   0xFF,
	};
    size_t i = 0;
    size_t d = 0;
@@ -137,14 +159,34 @@ base64_decode(void *vdst, size_t sizeof_dst, const void *vsrc, size_t sizeof_src
	return d;
}

/*****************************************************************************
 * Provide my own rand() simply to avoid static-analysis warning me that
 * 'rand()' is unrandom, when in fact we want the non-random properties of
 * rand() for regression testing.
 *****************************************************************************/
static unsigned
r_rand(unsigned *seed)
{
    static const unsigned a = 214013;
    static const unsigned c = 2531011;
    
    *seed = (*seed) * a + c;
    return (*seed)>>16 & 0x7fff;
}

/*****************************************************************************
 *****************************************************************************/
int
base64_selftest(void)
{
    char buf[100];
    char buf2[100];
    char buf3[100];
    size_t buf_len;
    size_t buf2_len;
    size_t buf3_len;
    unsigned i;
    unsigned seed = time(0);

    buf_len = base64_encode(buf, sizeof(buf), "hello", 5);
    buf2_len = base64_decode(buf2, sizeof(buf2), buf, buf_len);
@@ -153,5 +195,31 @@ base64_selftest(void)
        return 1;
    }

    /*
     * Generate a bunch of random strings, encode them, then decode them,
     * making sure the final result matches the original string
     */
    for (i=0; i<100; i++) {
        unsigned j;

        /* create a string of random bytes */
        buf_len = r_rand(&seed) % 50;
        for (j=0; j<buf_len; j++) {
            buf[j] = (char)r_rand(&seed);
        }

        /* encode it */
        buf2_len = base64_encode(buf2, sizeof(buf2), buf, buf_len);

        /* decode it back again */
        buf3_len = base64_decode(buf3, sizeof(buf3), buf2, buf2_len);

        /* now make sure result equals original */
        if (buf3_len != buf_len && memcmp(buf3, buf, buf_len) != 0) {
            fprintf(stderr, "base64: selftest failed\n");
            return 1;
        }
    }

    return 0;
}
+4 −1
Original line number Diff line number Diff line
@@ -127,7 +127,10 @@ http_hello[] = "GET / HTTP/1.0\r\n"

/*****************************************************************************
 *****************************************************************************/
static void
void
field_name(struct BannerOutput *banout, size_t id,
           struct Patterns *xhttp_fields);
void
field_name(struct BannerOutput *banout, size_t id,
           struct Patterns *xhttp_fields)
{
+4 −4
Original line number Diff line number Diff line
@@ -377,16 +377,16 @@ x509_decode(struct CertDecode *x, const unsigned char *px, size_t length, struct
            break;
        case ISSUERNAME_CONTENTS:
            //printf("%c", px[i]);
            if (x->remainings[0] == 0)
                ; //printf("\n");
            //if (x->remainings[0] == 0)
            //    printf("\n");
            break;
        case SUBJECTNAME_CONTENTS:
        case EXT_CONTENTS:
            //printf("%c", px[i]);
            if (x->subject.type == Subject_Common)
                banout_append(banout, PROTO_SSL3, px+i, 1);
            if (x->remainings[0] == 0)
                ; //printf("\n");
            //if (x->remainings[0] == 0)
            //    printf("\n");
            break;
        case VERSION_CONTENTS:
            x->u.num <<= 8;
+3 −0
Original line number Diff line number Diff line
@@ -75,6 +75,9 @@ hexdump(const void *v, size_t len)
#define RTA_BRD         0x80    /* for NEWADDR, broadcast or p-p dest addr */
#endif

void
dump_rt_addresses(struct rt_msghdr *rtm);

void
dump_rt_addresses(struct rt_msghdr *rtm)
{
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ struct PFRING PFRING;
/***************************************************************************
 * This checks whether the "pf_ring" driver is installed.
 ***************************************************************************/
int
PFRING_is_installed(void);

int
PFRING_is_installed(void)
{