chiark / gitweb /
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 565e37ff9b8ed608ea867106aaebc17156d3b8f9..5cce211415921556a5c384817d1278d9eb9dc158 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 b375f3b5851c17a45c673ee06396d430b462fae5..2cfa21b10f96202635e8d33431802d136a6ca791 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 4e022b81211d58dae5799f3155334b648571e698..073ab26ba6d51b185ea757bff0d6e29fb6fd7bd0 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 fff9b998c54062eaa473968640f40acc6b6f8a5d..2383192fdc4ea2e807fc353e30b67e9a1a9130cd 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 ebab05147206796f748ce387361c472564f24f26..5c5cd3d013e2022229a7ac3c8a8acaa81f3e5208 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 fbbff3c58745a361f7378a51728319169a3c6bba..c22176ff0536723acff3f977ff8d9e36a96cb310 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 8de384bfa190afadc7da9731a77c1ca9d794eac0..f8cda00eabbc3f6c5dac170c249a9cb8211572b0 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 f481b3e5f55c1f33a65c391d101915db88668aae..54f10d434367988a596f526c6fb1f267b75fe544 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 55f1ee125cbfba848002f1c536e8ad89e3bb3247..ab94832caaa726aaac76c1d3d5ca03a2629d42b2 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 0ce120004490026b46beb0d1966cf00e15632dd5..9a4dcc3795d3c1dfd7b1f58f27368e6ab7bc15c2 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 70eb9283b080104e37131d65170cdd7581988988..5226ad1166af5517a3586d59523dc8422ae0dc75 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 c0135a74cafe9548fcec068fe31acbd335173df4..ffefd8082ef67f2b662f5391b9baf628080c9e16 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 111f16ec787ddae5d347fd7f54be6462831ba378..39a9cb07c78f57183358059b21069743dd6b35e1 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 4702fe97d9292e08d22d2bc6965b2469c26a6414..caa030bd0223656c065a7013775df69523b714f7 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 f6931b5e36fa0fcf291710842664b71165597890..7869182b51ec5a653ea967f4154d746bd163ad88 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 18500c5cf3742421dddeb7d161082dfc4b4871c0..3186ac21de3b432c407a4053e224eb7c66e06e6f 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 e41f3ceb19c6cad35a7286693bbf24be5f7c16c1..ce918547155015ea7981c9ed51b87b345e9e1619 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 7b09f6efb48cbc0c4b99fbd2637e820f51e76ca3..0bcae8798867e8329aa219444970058b3a05faeb 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 c2a230383bc3ad45020091726364f26130d849c2..d77716ee5281ed13882cee9d4216abbdc4c75648 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 055caf5b6ab293d8fbed819bd5153f33a1f21c71..dd2e7274fedff08b56c7ae307cf8dd154a6d5fd6 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 000170c52b727e0a046b5ea5356dced5d20a4f30..5497711c228b7b4b0e2395739c5b00a0b97886e2 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 04ac08b8767ff668c46e8243ccf4153cfe5117e0..80606232d76de4eddff92b15e1c4c7b05f3cdfbf 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 44a45e50d4c22d0c19350e9277e91d93d4ed65c3..fff5b6d13e5e0f74544723ea4ff9e8f9013634f5 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 f1be586bb179a7600e3a32b16d4c667cf7a417e1..e40fb5400c731230b4d571f817dca134b18e2908 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);