integer arithmetic types: do not use unsigned for lengths
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 12 Jun 2011 21:34:09 +0000 (22:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 26 Jun 2011 11:07:26 +0000 (12:07 +0100)
In C it is not normally a good idea to use an unsigned integer type
for integer values, even if they are known not ever to be zero (for
example, because they are lengths).  This is because C unsigned
arithmetic has unhelpful behaviour when the values would become
negative.

In particular, comparing signed and unsigned integers, and doing
arithmetic (especially subtraction) when unsigned integers are
present, can be dangerous and lead to unexpected results.

So fix the resulting warnings (which are due to -Wsign-compare which
comes from -W) by making all lengths, counts (and iterators over them)
and return values from scanf be of signed types, usually int32_t
instead of uint32_t (but occasionally int).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
24 files changed:
conffile.c
conffile.fl
conffile_internal.h
dh.c
hackypar.c
hackypar.h
ipaddr.c
ipaddr.h
log.c
md5.c
netlink.c
netlink.h
random.c
rsa.c
secnet.c
secnet.h
serpent.c
sha1.c
site.c
slip.c
transform.c
tun.c
util.c
util.h

index 565e37f..5cce211 100644 (file)
@@ -35,7 +35,7 @@ struct dict {
     struct dict *parent;
     struct searchlist *search;
     struct entry *entries;
-    uint32_t size;
+    int32_t size;
 };
 
 static struct atomlist *atoms=NULL;
@@ -173,9 +173,9 @@ static string_t ntype(uint32_t type)
     return "**unknown**";
 }
 
-static void ptree_indent(uint32_t amount)
+static void ptree_indent(int amount)
 {
-    uint32_t i;
+    int i;
     for (i=0; i<amount; i++) printf("  . ");
 }
 
@@ -561,9 +561,9 @@ list_t *list_new(void)
     return NULL;
 }
 
-uint32_t list_length(list_t *a)
+int32_t list_length(list_t *a)
 {
-    uint32_t l=0;
+    int32_t l=0;
     list_t *i;
     for (i=a; i; i=i->next) { assert(l < INT_MAX); l++; }
     return l;
@@ -608,7 +608,7 @@ list_t *list_append(list_t *list, item_t *item)
     return list_append_list(list,l);
 }
 
-item_t *list_elem(list_t *l, uint32_t index)
+item_t *list_elem(list_t *l, int32_t index)
 {
     if (!l) return NULL;
     if (index==0) return l->item;
index b375f3b..2cfa21b 100644 (file)
@@ -35,7 +35,7 @@ struct include_stack_item {
 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
 int include_stack_ptr=0;
 
-uint32_t config_lineno=0;
+int config_lineno=0;
 cstring_t config_file="xxx";
 
 static struct p_node *leafnode(uint32_t type)
index 4e022b8..073ab26 100644 (file)
@@ -36,7 +36,7 @@ struct p_node {
 };
 
 extern cstring_t config_file;
-extern uint32_t config_lineno;
+extern int config_lineno;
 extern int yynerrs;
 
 /* Keys in dictionaries are 'atoms', which are constructed from strings
diff --git a/dh.c b/dh.c
index fff9b99..2383192 100644 (file)
--- a/dh.c
+++ b/dh.c
@@ -12,7 +12,7 @@ struct dh {
     MP_INT p,g; /* prime modulus and generator */
 };
 
-static string_t dh_makepublic(void *sst, uint8_t *secret, uint32_t secretlen)
+static string_t dh_makepublic(void *sst, uint8_t *secret, int32_t secretlen)
 {
     struct dh *st=sst;
     string_t r;
@@ -33,9 +33,9 @@ static string_t dh_makepublic(void *sst, uint8_t *secret, uint32_t secretlen)
 }
 
 static dh_makeshared_fn dh_makeshared;
-static void dh_makeshared(void *sst, uint8_t *secret, uint32_t secretlen,
+static void dh_makeshared(void *sst, uint8_t *secret, int32_t secretlen,
                          cstring_t rempublic, uint8_t *sharedsecret,
-                         uint32_t buflen)
+                         int32_t buflen)
 {
     struct dh *st=sst;
     MP_INT a, b, c;
index ebab051..5c5cd3d 100644 (file)
@@ -79,7 +79,7 @@ int hacky_par_mid_failnow(void) {
 bool_t (*packy_par_gen)(struct site *st);
 
 void hacky_par_end(int *ok,
-                  uint32_t retries, uint32_t timeout,
+                  int32_t retries, uint32_t timeout,
                   bool_t (*send_msg)(struct site *st), struct site *st) {
   int i;
   
@@ -115,7 +115,7 @@ void hacky_par_end(int *ok,
 int hacky_par_start_failnow(void) { return 0; }
 int hacky_par_mid_failnow(void) { return 0; }
 void hacky_par_end(int *ok,
-                  uint32_t retries, uint32_t timeout,
+                  int32_t retries, uint32_t timeout,
                   bool_t (*send_msg)(struct site *st), struct site *st) { }
 
 #endif /*HACKY_PARALLEL...else*/
index fbbff3c..c22176f 100644 (file)
@@ -11,7 +11,7 @@ struct site;
 int hacky_par_start_failnow(void);
 int hacky_par_mid_failnow(void);
 void hacky_par_end(int *ok,
-                  uint32_t retries, uint32_t timeout,
+                  int32_t retries, uint32_t timeout,
                   bool_t (*send_msg)(struct site *st), struct site *st);
 
 #endif /* hackympzpar_h */
index 8de384b..f8cda00 100644 (file)
--- a/ipaddr.c
+++ b/ipaddr.c
@@ -27,10 +27,10 @@ void subnet_list_free(struct subnet_list *a)
     free(a);
 }
 
-static void subnet_list_set_len(struct subnet_list *a, uint32_t l)
+static void subnet_list_set_len(struct subnet_list *a, int32_t l)
 {
     struct subnet *nd;
-    uint32_t na;
+    int32_t na;
 
     if (l>a->alloc) {
        assert(a->alloc < (int)(INT_MAX/sizeof(*nd))-EXTEND_ALLOC_BY);
@@ -45,7 +45,7 @@ static void subnet_list_set_len(struct subnet_list *a, uint32_t l)
     a->entries=l;
 }
 
-void subnet_list_append(struct subnet_list *a, uint32_t prefix, uint32_t len)
+void subnet_list_append(struct subnet_list *a, uint32_t prefix, int len)
 {
     struct subnet *sn;
     assert(a->entries < INT_MAX);
@@ -75,7 +75,7 @@ void ipset_free(struct ipset *a)
 #ifdef DEBUG
 static void ipset_dump(struct ipset *a, string_t name)
 {
-    uint32_t i;
+    int32_t i;
 
     printf("%s: ",name);
     for (i=0; i<a->l; i++) {
@@ -99,7 +99,7 @@ struct ipset *ipset_from_subnet(struct subnet s)
 struct ipset *ipset_from_subnet_list(struct subnet_list *l)
 {
     struct ipset *r, *a, *b;
-    uint32_t i;
+    int32_t i;
 
     r=ipset_new();
     for (i=0; i<l->entries; i++) {
@@ -112,10 +112,10 @@ struct ipset *ipset_from_subnet_list(struct subnet_list *l)
     return r;
 }
 
-static void ipset_set_len(struct ipset *a, uint32_t l)
+static void ipset_set_len(struct ipset *a, int32_t l)
 {
     struct iprange *nd;
-    uint32_t na;
+    int32_t na;
 
     if (l>a->a) {
        assert(a->a < INT_MAX-EXTEND_ALLOC_BY);
@@ -141,7 +141,7 @@ struct ipset *ipset_union(struct ipset *a, struct ipset *b)
 {
     struct ipset *c;
     struct iprange r;
-    uint32_t ia,ib;
+    int32_t ia,ib;
 
     c=ipset_new();
     ia=0; ib=0;
@@ -172,7 +172,7 @@ struct ipset *ipset_intersection(struct ipset *a, struct ipset *b)
 {
     struct ipset *r;
     struct iprange ra, rb;
-    uint32_t ia,ib;
+    int32_t ia,ib;
 
     r=ipset_new();
     ia=0; ib=0;
@@ -220,7 +220,8 @@ struct ipset *ipset_complement(struct ipset *a)
     struct ipset *r;
     struct iprange n;
     int64_t pre;
-    uint32_t i,lo,hi;
+    int32_t i;
+    uint32_t lo,hi;
 
     r=ipset_new();
     pre=-1;
@@ -259,7 +260,7 @@ bool_t ipset_is_empty(struct ipset *a)
 
 bool_t ipset_contains_addr(struct ipset *a, uint32_t addr)
 {
-    uint32_t i;
+    int32_t i;
     struct iprange r;
 
     for (i=0; i<a->l; i++) {
@@ -290,8 +291,8 @@ struct subnet_list *ipset_to_subnet_list(struct ipset *is)
 {
     struct subnet_list *r;
     int64_t a,b,lobit,himask,lomask;
-    int32_t bits;
-    uint32_t i;
+    int bits;
+    int32_t i;
 
     r=subnet_list_new();
     for (i=0; i<is->l; i++) {
@@ -357,7 +358,7 @@ static struct subnet string_item_to_subnet(item_t *i, cstring_t desc,
 {
     struct subnet s;
     uint32_t a, b, c, d, n;
-    uint32_t match;
+    int match;
     cstring_t in;
 
     *invert=False;
@@ -406,7 +407,7 @@ static struct subnet string_item_to_subnet(item_t *i, cstring_t desc,
 uint32_t string_item_to_ipaddr(item_t *i, cstring_t desc)
 {
     uint32_t a, b, c, d;
-    uint32_t match;
+    int match;
 
     /* i is not guaranteed to be a string */
     if (i->type!=t_string) {
index f481b3e..54f10d4 100644 (file)
--- a/ipaddr.h
+++ b/ipaddr.h
@@ -6,12 +6,12 @@
 struct subnet {
     uint32_t prefix;
     uint32_t mask;
-    uint32_t len;
+    int len;
 };
 
 struct subnet_list {
-    uint32_t entries;
-    uint32_t alloc;
+    int32_t entries;
+    int32_t alloc;
     struct subnet *list;
 };
 
@@ -20,15 +20,14 @@ struct iprange {
 };
 
 struct ipset {
-    uint32_t l; /* Number of entries in list */
-    uint32_t a; /* Allocated space in list */
+    int32_t l; /* Number of entries in list */
+    int32_t a; /* Allocated space in list */
     struct iprange *d;
 };
 
 extern struct subnet_list *subnet_list_new(void);
 extern void subnet_list_free(struct subnet_list *a);
-extern void subnet_list_append(struct subnet_list *a, uint32_t prefix,
-                              uint32_t len);
+extern void subnet_list_append(struct subnet_list *a, uint32_t prefix, int len);
 
 static inline bool_t subnet_match(struct subnet s, uint32_t address)
 {
diff --git a/log.c b/log.c
index 55f1ee1..ab94832 100644 (file)
--- a/log.c
+++ b/log.c
@@ -19,7 +19,7 @@ static void vMessage(uint32_t class, const char *message, va_list args)
     FILE *dest=stdout;
 #define MESSAGE_BUFLEN 1023
     static char buff[MESSAGE_BUFLEN+1]={0,};
-    uint32_t bp;
+    size_t bp;
     char *nlp;
 
     if (secnet_is_daemon) {
diff --git a/md5.c b/md5.c
index 0ce1200..9a4dcc3 100644 (file)
--- a/md5.c
+++ b/md5.c
@@ -26,7 +26,7 @@
 
 #ifdef WORDS_BIGENDIAN
 static void
-byteSwap(uint32_t *buf, unsigned words)
+byteSwap(uint32_t *buf, int words)
 {
        md5byte *p = (md5byte *)buf;
 
@@ -247,7 +247,7 @@ static void *md5_init(void)
     return ctx;
 }
 
-static void md5_update(void *sst, uint8_t const *buf, uint32_t len)
+static void md5_update(void *sst, uint8_t const *buf, int32_t len)
 {
     struct MD5Context *ctx=sst;
 
index 70eb928..5226ad1 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -123,7 +123,7 @@ their use.
 #define ICMP_CODE_TTL_EXCEEDED           0
 
 /* Generic IP checksum routine */
-static inline uint16_t ip_csum(uint8_t *iph,uint32_t count)
+static inline uint16_t ip_csum(uint8_t *iph,int32_t count)
 {
     register uint32_t sum=0;
 
@@ -147,7 +147,7 @@ static inline uint16_t ip_csum(uint8_t *iph,uint32_t count)
  *      By Jorge Cwik <jorge@laser.satlink.net>, adapted for linux by
  *      Arnt Gulbrandsen.
  */
-static inline uint16_t ip_fast_csum(uint8_t *iph, uint32_t ihl) {
+static inline uint16_t ip_fast_csum(uint8_t *iph, int32_t ihl) {
     uint32_t sum;
 
     __asm__ __volatile__(
@@ -177,8 +177,9 @@ static inline uint16_t ip_fast_csum(uint8_t *iph, uint32_t ihl) {
     return sum;
 }
 #else
-static inline uint16_t ip_fast_csum(uint8_t *iph, uint32_t ihl)
+static inline uint16_t ip_fast_csum(uint8_t *iph, int32_t ihl)
 {
+    assert(ihl < INT_MAX/4);
     return ip_csum(iph,ihl*4);
 }
 #endif
@@ -264,7 +265,7 @@ static struct icmphdr *netlink_icmp_tmpl(struct netlink *st,
 /* Fill in the ICMP checksum field correctly */
 static void netlink_icmp_csum(struct icmphdr *h)
 {
-    uint32_t len;
+    int32_t len;
 
     len=ntohs(h->iph.tot_len)-(4*h->iph.ihl);
     h->check=0;
@@ -386,7 +387,7 @@ static void netlink_icmp_simple(struct netlink *st, struct buffer_if *buf,
 static bool_t netlink_check(struct netlink *st, struct buffer_if *buf)
 {
     struct iphdr *iph=(struct iphdr *)buf->start;
-    uint32_t len;
+    int32_t len;
 
     if (iph->ihl < 5 || iph->version != 4) return False;
     if (buf->size < iph->ihl*4) return False;
@@ -695,7 +696,7 @@ static void netlink_set_quality(void *sst, uint32_t quality)
 static void netlink_output_subnets(struct netlink *st, uint32_t loglevel,
                                   struct subnet_list *snets)
 {
-    uint32_t i;
+    int32_t i;
     string_t net;
 
     for (i=0; i<snets->entries; i++) {
@@ -763,7 +764,7 @@ static void netlink_phase_hook(void *sst, uint32_t new_phase)
 {
     struct netlink *st=sst;
     struct netlink_client *c;
-    uint32_t i;
+    int32_t i;
 
     /* All the networks serviced by the various tunnels should now
      * have been registered.  We build a routing table by sorting the
@@ -811,7 +812,7 @@ static bool_t netlink_inst_check_config(void *sst, struct buffer_if *buf)
     return True;
 }
 
-static void netlink_inst_set_mtu(void *sst, uint32_t new_mtu)
+static void netlink_inst_set_mtu(void *sst, int32_t new_mtu)
 {
     struct netlink_client *c=sst;
 
@@ -819,8 +820,8 @@ static void netlink_inst_set_mtu(void *sst, uint32_t new_mtu)
 }
 
 static void netlink_inst_reg(void *sst, netlink_deliver_fn *deliver, 
-                            void *dst, uint32_t max_start_pad,
-                            uint32_t max_end_pad)
+                            void *dst, int32_t max_start_pad,
+                            int32_t max_end_pad)
 {
     struct netlink_client *c=sst;
     struct netlink *st=c->nst;
@@ -847,7 +848,8 @@ static closure_t *netlink_inst_create(struct netlink *st,
     struct netlink_client *c;
     string_t name;
     struct ipset *networks;
-    uint32_t options,priority,mtu;
+    uint32_t options,priority;
+    int32_t mtu;
     list_t *l;
 
     name=dict_read_string(dict, "name", True, st->name, loc);
index c0135a7..ffefd80 100644 (file)
--- a/netlink.h
+++ b/netlink.h
@@ -23,7 +23,7 @@ struct netlink_client {
     void *dst;
     string_t name;
     uint32_t link_quality;
-    uint32_t mtu;
+    int32_t mtu;
     uint32_t options;
     uint32_t outcount;
     bool_t up; /* Should these routes exist in the kernel? */
@@ -41,18 +41,18 @@ struct netlink {
     closure_t cl;
     void *dst; /* Pointer to host interface state */
     cstring_t name;
-    uint32_t max_start_pad;
-    uint32_t max_end_pad;
+    int32_t max_start_pad;
+    int32_t max_end_pad;
     struct ipset *networks; /* Local networks */
     struct subnet_list *subnets; /* Same as networks, for display */
     struct ipset *remote_networks; /* Allowable remote networks */
     uint32_t secnet_address; /* our own address, or the address of the
                                other end of a point-to-point link */
     bool_t ptp;
-    uint32_t mtu;
+    int32_t mtu;
     struct netlink_client *clients; /* Linked list of clients */
     struct netlink_client **routes; /* Array of clients, sorted by priority */
-    uint32_t n_clients;
+    int32_t n_clients;
     netlink_deliver_fn *deliver_to_host; /* Provided by driver */
     netlink_route_fn *set_routes; /* Provided by driver */
     struct buffer_if icmp; /* Buffer for assembly of outgoing ICMP */
index 111f16e..39a9cb0 100644 (file)
--- a/random.c
+++ b/random.c
@@ -14,7 +14,7 @@ struct rgen_data {
 };
 
 static random_fn random_generate;
-static bool_t random_generate(void *data, uint32_t bytes, uint8_t *buff)
+static bool_t random_generate(void *data, int32_t bytes, uint8_t *buff)
 {
     struct rgen_data *st=data;
     int r;
diff --git a/rsa.c b/rsa.c
index 4702fe9..caa030b 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -36,7 +36,7 @@ struct rsapub {
 
 static const char *hexchars="0123456789abcdef";
 
-static string_t rsa_sign(void *sst, uint8_t *data, uint32_t datalen)
+static string_t rsa_sign(void *sst, uint8_t *data, int32_t datalen)
 {
     struct rsapriv *st=sst;
     MP_INT a, b, u, v, tmp, tmp2;
@@ -130,7 +130,7 @@ static string_t rsa_sign(void *sst, uint8_t *data, uint32_t datalen)
 }
 
 static rsa_checksig_fn rsa_sig_check;
-static bool_t rsa_sig_check(void *sst, uint8_t *data, uint32_t datalen,
+static bool_t rsa_sig_check(void *sst, uint8_t *data, int32_t datalen,
                            cstring_t signature)
 {
     struct rsapub *st=sst;
index f6931b5..7869182 100644 (file)
--- a/secnet.c
+++ b/secnet.c
@@ -32,13 +32,13 @@ struct poll_interest {
     beforepoll_fn *before;
     afterpoll_fn *after;
     void *state;
-    uint32_t max_nfds;
-    uint32_t nfds;
+    int32_t max_nfds;
+    int32_t nfds;
     cstring_t desc;
     struct poll_interest *next;
 };
 static struct poll_interest *reg=NULL;
-static uint32_t total_nfds=10;
+static int32_t total_nfds=10;
 
 static bool_t finished=False;
 
@@ -221,7 +221,7 @@ static void setup(dict_t *config)
 }
 
 void register_for_poll(void *st, beforepoll_fn *before,
-                      afterpoll_fn *after, uint32_t max_nfds, cstring_t desc)
+                      afterpoll_fn *after, int32_t max_nfds, cstring_t desc)
 {
     struct poll_interest *i;
 
index 18500c5..3186ac2 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -60,7 +60,7 @@ typedef struct list list_t;        /* A list of items */
 /* Configuration file location, for error-reporting */
 struct cloc {
     cstring_t file;
-    uint32_t line;
+    int line;
 };
 
 /* Modules export closures, which can be invoked from the configuration file.
@@ -107,11 +107,11 @@ extern cstring_t *dict_keys(dict_t *dict);
 
 /* List-manipulation functions */
 extern list_t *list_new(void);
-extern uint32_t list_length(list_t *a);
+extern int32_t list_length(list_t *a);
 extern list_t *list_append(list_t *a, item_t *i);
 extern list_t *list_append_list(list_t *a, list_t *b);
 /* Returns an item from the list (index starts at 0), or NULL */
-extern item_t *list_elem(list_t *l, uint32_t index);
+extern item_t *list_elem(list_t *l, int32_t index);
 
 /* Convenience functions */
 extern list_t *new_closure(closure_t *cl);
@@ -169,7 +169,7 @@ typedef void afterpoll_fn(void *st, struct pollfd *fds, int nfds,
    structures you may require - you can always ask for more in
    *nfds_io. */
 extern void register_for_poll(void *st, beforepoll_fn *before,
-                             afterpoll_fn *after, uint32_t max_nfds,
+                             afterpoll_fn *after, int32_t max_nfds,
                              cstring_t desc);
 
 /***** END of scheduling support */
@@ -270,7 +270,7 @@ struct resolver_if {
 /* RANDOMSRC interface */
 
 /* Return some random data. Returns TRUE for success. */
-typedef bool_t random_fn(void *st, uint32_t bytes, uint8_t *buff);
+typedef bool_t random_fn(void *st, int32_t bytes, uint8_t *buff);
 
 struct random_if {
     void *st;
@@ -280,7 +280,7 @@ struct random_if {
 
 /* RSAPUBKEY interface */
 
-typedef bool_t rsa_checksig_fn(void *st, uint8_t *data, uint32_t datalen,
+typedef bool_t rsa_checksig_fn(void *st, uint8_t *data, int32_t datalen,
                               cstring_t signature);
 struct rsapubkey_if {
     void *st;
@@ -289,7 +289,7 @@ struct rsapubkey_if {
 
 /* RSAPRIVKEY interface */
 
-typedef string_t rsa_makesig_fn(void *st, uint8_t *data, uint32_t datalen);
+typedef string_t rsa_makesig_fn(void *st, uint8_t *data, int32_t datalen);
 struct rsaprivkey_if {
     void *st;
     rsa_makesig_fn *sign;
@@ -309,8 +309,8 @@ typedef bool_t comm_sendmsg_fn(void *commst, struct buffer_if *buf,
                               struct sockaddr_in *dest);
 struct comm_if {
     void *st;
-    uint32_t min_start_pad;
-    uint32_t min_end_pad;
+    int32_t min_start_pad;
+    int32_t min_end_pad;
     comm_request_notify_fn *request_notify;
     comm_release_notify_fn *release_notify;
     comm_sendmsg_fn *sendmsg;
@@ -357,7 +357,7 @@ struct site_if {
    particular key material) have a different C type. */
 
 typedef struct transform_inst_if *transform_createinstance_fn(void *st);
-typedef bool_t transform_setkey_fn(void *st, uint8_t *key, uint32_t keylen);
+typedef bool_t transform_setkey_fn(void *st, uint8_t *key, int32_t keylen);
 typedef void transform_delkey_fn(void *st);
 typedef void transform_destroyinstance_fn(void *st);
 /* Returns 0 for 'all is well', any other value for a problem */
@@ -375,9 +375,9 @@ struct transform_inst_if {
 
 struct transform_if {
     void *st;
-    uint32_t max_start_pad;
-    uint32_t max_end_pad;
-    uint32_t keylen;
+    int32_t max_start_pad; /* these three are all <<< INT_MAX */
+    int32_t max_end_pad;
+    int32_t keylen;
     transform_createinstance_fn *create;
 };
 
@@ -398,11 +398,11 @@ typedef void netlink_deliver_fn(void *st, struct buffer_if *buf);
 #define MAXIMUM_LINK_QUALITY 3
 typedef void netlink_link_quality_fn(void *st, uint32_t quality);
 typedef void netlink_register_fn(void *st, netlink_deliver_fn *deliver,
-                                void *dst, uint32_t max_start_pad,
-                                uint32_t max_end_pad);
+                                void *dst, int32_t max_start_pad,
+                                int32_t max_end_pad);
 typedef void netlink_output_config_fn(void *st, struct buffer_if *buf);
 typedef bool_t netlink_check_config_fn(void *st, struct buffer_if *buf);
-typedef void netlink_set_mtu_fn(void *st, uint32_t new_mtu);
+typedef void netlink_set_mtu_fn(void *st, int32_t new_mtu);
 struct netlink_if {
     void *st;
     netlink_register_fn *reg;
@@ -417,14 +417,14 @@ struct netlink_if {
 
 /* Returns public key as a malloced hex string */
 typedef string_t dh_makepublic_fn(void *st, uint8_t *secret,
-                                 uint32_t secretlen);
+                                 int32_t secretlen);
 /* Fills buffer (up to buflen) with shared secret */
 typedef void dh_makeshared_fn(void *st, uint8_t *secret,
-                             uint32_t secretlen, cstring_t rempublic,
-                             uint8_t *sharedsecret, uint32_t buflen);
+                             int32_t secretlen, cstring_t rempublic,
+                             uint8_t *sharedsecret, int32_t buflen);
 struct dh_if {
     void *st;
-    uint32_t len; /* Approximate size of modulus in bytes */
+    int32_t len; /* Approximate size of modulus in bytes */
     dh_makepublic_fn *makepublic;
     dh_makeshared_fn *makeshared;
 };
@@ -432,10 +432,10 @@ struct dh_if {
 /* HASH interface */
 
 typedef void *hash_init_fn(void);
-typedef void hash_update_fn(void *st, uint8_t const *buf, uint32_t len);
+typedef void hash_update_fn(void *st, uint8_t const *buf, int32_t len);
 typedef void hash_final_fn(void *st, uint8_t *digest);
 struct hash_if {
-    uint32_t len; /* Hash output length in bytes */
+    int32_t len; /* Hash output length in bytes */
     hash_init_fn *init;
     hash_update_fn *update;
     hash_final_fn *final;
@@ -450,8 +450,8 @@ struct buffer_if {
     struct cloc loc; /* Where we were defined */
     uint8_t *base;
     uint8_t *start;
-    uint32_t size; /* Size of buffer contents */
-    uint32_t len; /* Total length allocated at base */
+    int32_t size; /* Size of buffer contents */
+    int32_t len; /* Total length allocated at base */
 };
 
 /***** LOG functions *****/
index e41f3ce..ce91854 100644 (file)
--- a/serpent.c
+++ b/serpent.c
@@ -28,7 +28,8 @@
 void serpent_makekey(struct keyInstance *key, int keyLen,
            uint8_t *keyMaterial)
 {
-    uint32_t i,j;
+    int i;
+    uint32_t j;
     uint32_t w[132],k[132];
 
     for(i=0; i<keyLen/32; i++)
diff --git a/sha1.c b/sha1.c
index 7b09f6e..0bcae87 100644 (file)
--- a/sha1.c
+++ b/sha1.c
@@ -294,7 +294,7 @@ static void *sha1_init(void)
     return ctx;
 }
 
-static void sha1_update(void *sst, uint8_t const *buf, uint32_t len)
+static void sha1_update(void *sst, uint8_t const *buf, int32_t len)
 {
     SHA1_CTX *ctx=sst;
 
diff --git a/site.c b/site.c
index c2a2303..d77716e 100644 (file)
--- a/site.c
+++ b/site.c
@@ -145,7 +145,7 @@ struct site {
     struct dh_if *dh;
     struct hash_if *hash;
 
-    uint32_t setup_retries; /* How many times to send setup packets */
+    int32_t setup_retries; /* How many times to send setup packets */
     uint32_t setup_timeout; /* Initial timeout for setup packets */
     uint32_t wait_timeout; /* How long to wait if setup unsuccessful */
     uint32_t key_lifetime; /* How long a key lasts once set up */
@@ -156,8 +156,8 @@ struct site {
                         implemented) */
 
     uint8_t *setupsig; /* Expected signature of incoming MSG1 packets */
-    uint32_t setupsiglen; /* Allows us to discard packets quickly if
-                            they are not for us */
+    int32_t setupsiglen; /* Allows us to discard packets quickly if
+                           they are not for us */
     bool_t setup_priority; /* Do we have precedence if both sites emit
                              message 1 simultaneously? */
     uint32_t log_events;
@@ -242,16 +242,16 @@ struct msg {
     uint8_t *hashstart;
     uint32_t dest;
     uint32_t source;
-    uint32_t remlen;
+    int32_t remlen;
     uint8_t *remote;
-    uint32_t loclen;
+    int32_t loclen;
     uint8_t *local;
     uint8_t *nR;
     uint8_t *nL;
-    uint32_t pklen;
+    int32_t pklen;
     uint8_t *pk;
-    uint32_t hashlen;
-    uint32_t siglen;
+    int32_t hashlen;
+    int32_t siglen;
     uint8_t *sig;
 };
 
diff --git a/slip.c b/slip.c
index 055caf5..dd2e727 100644 (file)
--- a/slip.c
+++ b/slip.c
@@ -33,7 +33,7 @@ static void slip_stuff(struct slip *st, struct buffer_if *buf, int fd)
 {
     uint8_t txbuf[DEFAULT_BUFSIZE];
     uint8_t *i;
-    uint32_t j=0;
+    int32_t j=0;
 
     BUF_ASSERT_USED(buf);
 
index 000170c..5497711 100644 (file)
@@ -38,7 +38,7 @@ struct transform_inst {
 
 #define PKCS5_MASK 15
 
-static bool_t transform_setkey(void *sst, uint8_t *key, uint32_t keylen)
+static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen)
 {
     struct transform_inst *ti=sst;
 
@@ -157,7 +157,7 @@ static uint32_t transform_reverse(void *sst, struct buffer_if *buf,
 {
     struct transform_inst *ti=sst;
     uint8_t *padp;
-    unsigned padlen;
+    int padlen;
     int i;
     uint32_t seqnum, skew;
     uint8_t iv[16];
diff --git a/tun.c b/tun.c
index 04ac08b..8060623 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -149,7 +149,7 @@ static bool_t tun_set_route(void *sst, struct netlink_client *routes)
     struct tun *st=sst;
     string_t network, mask, secnetaddr;
     struct subnet_list *nets;
-    uint32_t i;
+    int32_t i;
     int fd=-1;
 
     if (routes->up == routes->kup) return False;
diff --git a/util.c b/util.c
index 44a45e5..fff5b6d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -139,7 +139,7 @@ static uint8_t hexval(uint8_t c)
 }
 
 /* Convert a MP_INT into a buffer; return length; truncate if necessary */
-uint32_t write_mpbin(MP_INT *a, uint8_t *buffer, uint32_t buflen)
+int32_t write_mpbin(MP_INT *a, uint8_t *buffer, int32_t buflen)
 {
     char *hb;
     int i,j,l;
@@ -224,7 +224,7 @@ struct buffer {
 };
 
 void buffer_assert_free(struct buffer_if *buffer, cstring_t file,
-                       uint32_t line)
+                       int line)
 {
     if (!buffer->free) {
        fatal("BUF_ASSERT_FREE, %s line %d, owned by %s",
@@ -233,7 +233,7 @@ void buffer_assert_free(struct buffer_if *buffer, cstring_t file,
 }
 
 void buffer_assert_used(struct buffer_if *buffer, cstring_t file,
-                       uint32_t line)
+                       int line)
 {
     if (buffer->free) {
        fatal("BUF_ASSERT_USED, %s line %d, last owned by %s",
@@ -241,13 +241,13 @@ void buffer_assert_used(struct buffer_if *buffer, cstring_t file,
     }
 }
 
-void buffer_init(struct buffer_if *buffer, uint32_t max_start_pad)
+void buffer_init(struct buffer_if *buffer, int32_t max_start_pad)
 {
     buffer->start=buffer->base+max_start_pad;
     buffer->size=0;
 }
 
-void *buf_append(struct buffer_if *buf, uint32_t amount) {
+void *buf_append(struct buffer_if *buf, int32_t amount) {
     void *p;
     assert(buf->size <= buf->len - amount);
     p=buf->start + buf->size;
@@ -255,18 +255,18 @@ void *buf_append(struct buffer_if *buf, uint32_t amount) {
     return p;
 }
 
-void *buf_prepend(struct buffer_if *buf, uint32_t amount) {
+void *buf_prepend(struct buffer_if *buf, int32_t amount) {
     assert(amount <= buf->start - buf->base);
     buf->size+=amount;
     return buf->start-=amount;
 }
 
-void *buf_unappend(struct buffer_if *buf, uint32_t amount) {
+void *buf_unappend(struct buffer_if *buf, int32_t amount) {
     if (buf->size < amount) return 0;
     return buf->start+(buf->size-=amount);
 }
 
-void *buf_unprepend(struct buffer_if *buf, uint32_t amount) {
+void *buf_unprepend(struct buffer_if *buf, int32_t amount) {
     void *p;
     p=buf->start;
     buf->start+=amount;
@@ -278,7 +278,7 @@ void *buf_unprepend(struct buffer_if *buf, uint32_t amount) {
    network byte order. */
 void buf_append_string(struct buffer_if *buf, cstring_t s)
 {
-    uint16_t len;
+    size_t len;
 
     len=strlen(s);
     /* fixme: if string is longer than 65535, result is a corrupted packet */
@@ -286,7 +286,7 @@ void buf_append_string(struct buffer_if *buf, cstring_t s)
     memcpy(buf_append(buf,len),s,len);
 }
 
-void buffer_new(struct buffer_if *buf, uint32_t len)
+void buffer_new(struct buffer_if *buf, int32_t len)
 {
     buf->free=True;
     buf->owner=NULL;
diff --git a/util.h b/util.h
index f1be586..e40fb54 100644 (file)
--- a/util.h
+++ b/util.h
@@ -18,15 +18,15 @@ while(0)
 #define BUF_FREE(buf) do { (buf)->free=True; } while(0)
 
 extern void buffer_assert_free(struct buffer_if *buffer, cstring_t file,
-                              uint32_t line);
+                              int line);
 extern void buffer_assert_used(struct buffer_if *buffer, cstring_t file,
-                              uint32_t line);
-extern void buffer_new(struct buffer_if *buffer, uint32_t len);
-extern void buffer_init(struct buffer_if *buffer, uint32_t max_start_pad);
-extern void *buf_append(struct buffer_if *buf, uint32_t amount);
-extern void *buf_prepend(struct buffer_if *buf, uint32_t amount);
-extern void *buf_unappend(struct buffer_if *buf, uint32_t amount);
-extern void *buf_unprepend(struct buffer_if *buf, uint32_t amount);
+                              int line);
+extern void buffer_new(struct buffer_if *buffer, int32_t len);
+extern void buffer_init(struct buffer_if *buffer, int32_t max_start_pad);
+extern void *buf_append(struct buffer_if *buf, int32_t amount);
+extern void *buf_prepend(struct buffer_if *buf, int32_t amount);
+extern void *buf_unappend(struct buffer_if *buf, int32_t amount);
+extern void *buf_unprepend(struct buffer_if *buf, int32_t amount);
 
 extern void buf_append_string(struct buffer_if *buf, cstring_t s);
 
@@ -34,7 +34,7 @@ extern void read_mpbin(MP_INT *a, uint8_t *bin, int binsize);
 
 extern char *write_mpstring(MP_INT *a);
 
-extern uint32_t write_mpbin(MP_INT *a, uint8_t *buffer, uint32_t buflen);
+extern int32_t write_mpbin(MP_INT *a, uint8_t *buffer, int32_t buflen);
 
 extern struct log_if *init_log(list_t *loglist);