From: Guus Sliepen Date: Tue, 8 May 2012 14:44:15 +0000 (+0200) Subject: Always pass request strings to other functions as const char *. X-Git-Tag: release-1.1pre3~121 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=58007d7efa3940c863c5a398f8b257a686ce37ba;p=tinc Always pass request strings to other functions as const char *. --- diff --git a/src/control.c b/src/control.c index d074ebba..956d6ee1 100644 --- a/src/control.c +++ b/src/control.c @@ -44,7 +44,7 @@ static bool control_ok(connection_t *c, int type) { return control_return(c, type, 0); } -bool control_h(connection_t *c, char *request) { +bool control_h(connection_t *c, const char *request) { int type; if(!c->status.control || c->allow_request != CONTROL) { diff --git a/src/protocol.c b/src/protocol.c index 52ea6902..2b179a72 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -34,7 +34,7 @@ bool experimental = false; /* Jumptable for the request handlers */ -static bool (*request_handlers[])(connection_t *, char *) = { +static bool (*request_handlers[])(connection_t *, const char *) = { id_h, metakey_h, challenge_h, chal_reply_h, ack_h, status_h, error_h, termreq_h, ping_h, pong_h, @@ -96,16 +96,18 @@ bool send_request(connection_t *c, const char *format, ...) { return send_meta(c, request, len); } -void forward_request(connection_t *from, char *request) { - /* Note: request is not zero terminated anymore after a call to this function! */ +void forward_request(connection_t *from, const char *request) { logger(DEBUG_META, LOG_DEBUG, "Forwarding %s from %s (%s): %s", request_name[atoi(request)], from->name, from->hostname, request); + // Create a temporary newline-terminated copy of the request int len = strlen(request); - request[len++] = '\n'; - broadcast_meta(from, request, len); + char tmp[len + 1]; + memcpy(tmp, request, len); + tmp[len] = '\n'; + broadcast_meta(from, tmp, len); } -bool receive_request(connection_t *c, char *request) { +bool receive_request(connection_t *c, const char *request) { int reqno = atoi(request); if(reqno || *request == '0') { @@ -141,14 +143,14 @@ static int past_request_compare(const past_request_t *a, const past_request_t *b static void free_past_request(past_request_t *r) { if(r->request) - free(r->request); + free((char *)r->request); free(r); } static struct event past_request_event; -bool seen_request(char *request) { +bool seen_request(const char *request) { past_request_t *new, p = {NULL}; p.request = request; diff --git a/src/protocol.h b/src/protocol.h index 2c97641d..540a7c3f 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -48,7 +48,7 @@ typedef enum request_t { } request_t; typedef struct past_request_t { - char *request; + const char *request; time_t firstseen; } past_request_t; @@ -72,13 +72,13 @@ extern bool experimental; /* Basic functions */ extern bool send_request(struct connection_t *, const char *, ...) __attribute__ ((__format__(printf, 2, 3))); -extern void forward_request(struct connection_t *, char *); -extern bool receive_request(struct connection_t *, char *); +extern void forward_request(struct connection_t *, const char *); +extern bool receive_request(struct connection_t *, const char *); extern bool check_id(const char *); extern void init_requests(void); extern void exit_requests(void); -extern bool seen_request(char *); +extern bool seen_request(const char *); /* Requests */ @@ -89,7 +89,7 @@ extern bool send_challenge(struct connection_t *); extern bool send_chal_reply(struct connection_t *); extern bool send_ack(struct connection_t *); extern bool send_status(struct connection_t *, int, const char *); -extern bool send_error(struct connection_t *, int,const char *); +extern bool send_error(struct connection_t *, int, const char *); extern bool send_termreq(struct connection_t *); extern bool send_ping(struct connection_t *); extern bool send_pong(struct connection_t *); @@ -104,24 +104,24 @@ extern bool send_tcppacket(struct connection_t *, const struct vpn_packet_t *); /* Request handlers */ -extern bool id_h(struct connection_t *, char *); -extern bool metakey_h(struct connection_t *, char *); -extern bool challenge_h(struct connection_t *, char *); -extern bool chal_reply_h(struct connection_t *, char *); -extern bool ack_h(struct connection_t *, char *); -extern bool status_h(struct connection_t *, char *); -extern bool error_h(struct connection_t *, char *); -extern bool termreq_h(struct connection_t *, char *); -extern bool ping_h(struct connection_t *, char *); -extern bool pong_h(struct connection_t *, char *); -extern bool add_subnet_h(struct connection_t *, char *); -extern bool del_subnet_h(struct connection_t *, char *); -extern bool add_edge_h(struct connection_t *, char *); -extern bool del_edge_h(struct connection_t *, char *); -extern bool key_changed_h(struct connection_t *, char *); -extern bool req_key_h(struct connection_t *, char *); -extern bool ans_key_h(struct connection_t *, char *); -extern bool tcppacket_h(struct connection_t *, char *); -extern bool control_h(struct connection_t *, char *); +extern bool id_h(struct connection_t *, const char *); +extern bool metakey_h(struct connection_t *, const char *); +extern bool challenge_h(struct connection_t *, const char *); +extern bool chal_reply_h(struct connection_t *, const char *); +extern bool ack_h(struct connection_t *, const char *); +extern bool status_h(struct connection_t *, const char *); +extern bool error_h(struct connection_t *, const char *); +extern bool termreq_h(struct connection_t *, const char *); +extern bool ping_h(struct connection_t *, const char *); +extern bool pong_h(struct connection_t *, const char *); +extern bool add_subnet_h(struct connection_t *, const char *); +extern bool del_subnet_h(struct connection_t *, const char *); +extern bool add_edge_h(struct connection_t *, const char *); +extern bool del_edge_h(struct connection_t *, const char *); +extern bool key_changed_h(struct connection_t *, const char *); +extern bool req_key_h(struct connection_t *, const char *); +extern bool ans_key_h(struct connection_t *, const char *); +extern bool tcppacket_h(struct connection_t *, const char *); +extern bool control_h(struct connection_t *, const char *); #endif /* __TINC_PROTOCOL_H__ */ diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 287681b5..057b88e5 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -57,7 +57,7 @@ bool send_id(connection_t *c) { return send_request(c, "%d %s %d.%d", ID, myself->connection->name, myself->connection->protocol_major, minor); } -bool id_h(connection_t *c, char *request) { +bool id_h(connection_t *c, const char *request) { char name[MAX_STRING_SIZE]; if(sscanf(request, "%*d " MAX_STRING " %d.%d", name, &c->protocol_major, &c->protocol_minor) < 2) { @@ -219,7 +219,7 @@ bool send_metakey(connection_t *c) { return result; } -bool metakey_h(connection_t *c, char *request) { +bool metakey_h(connection_t *c, const char *request) { char hexkey[MAX_STRING_SIZE]; int cipher, digest, maclength, compression; size_t len = rsa_size(&myself->connection->rsa); @@ -293,7 +293,7 @@ bool send_challenge(connection_t *c) { return send_request(c, "%d %s", CHALLENGE, buffer); } -bool challenge_h(connection_t *c, char *request) { +bool challenge_h(connection_t *c, const char *request) { char buffer[MAX_STRING_SIZE]; size_t len = rsa_size(&myself->connection->rsa); size_t digestlen = digest_length(&c->indigest); @@ -330,7 +330,7 @@ bool challenge_h(connection_t *c, char *request) { return send_request(c, "%d %s", CHAL_REPLY, buffer); } -bool chal_reply_h(connection_t *c, char *request) { +bool chal_reply_h(connection_t *c, const char *request) { char hishash[MAX_STRING_SIZE]; if(sscanf(request, "%*d " MAX_STRING, hishash) != 1) { @@ -451,7 +451,7 @@ static void send_everything(connection_t *c) { } } -static bool upgrade_h(connection_t *c, char *request) { +static bool upgrade_h(connection_t *c, const char *request) { char pubkey[MAX_STRING_SIZE]; if(sscanf(request, "%*d " MAX_STRING, pubkey) != 1) { @@ -470,7 +470,7 @@ static bool upgrade_h(connection_t *c, char *request) { return send_termreq(c); } -bool ack_h(connection_t *c, char *request) { +bool ack_h(connection_t *c, const char *request) { if(c->protocol_minor == 1) return upgrade_h(c, request); diff --git a/src/protocol_edge.c b/src/protocol_edge.c index e8b3326b..e1d2051b 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -50,7 +50,7 @@ bool send_add_edge(connection_t *c, const edge_t *e) { return x; } -bool add_edge_h(connection_t *c, char *request) { +bool add_edge_h(connection_t *c, const char *request) { edge_t *e; node_t *from, *to; char from_name[MAX_STRING_SIZE]; @@ -167,7 +167,7 @@ bool send_del_edge(connection_t *c, const edge_t *e) { e->from->name, e->to->name); } -bool del_edge_h(connection_t *c, char *request) { +bool del_edge_h(connection_t *c, const char *request) { edge_t *e; char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; diff --git a/src/protocol_key.c b/src/protocol_key.c index 7e645d48..12dab09b 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -51,7 +51,7 @@ void send_key_changed(void) { } } -bool key_changed_h(connection_t *c, char *request) { +bool key_changed_h(connection_t *c, const char *request) { char name[MAX_STRING_SIZE]; node_t *n; @@ -87,7 +87,7 @@ bool send_req_key(node_t *to) { return send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, experimental ? 1 : 0); } -bool req_key_h(connection_t *c, char *request) { +bool req_key_h(connection_t *c, const char *request) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; node_t *from, *to; @@ -202,7 +202,7 @@ bool send_ans_key(node_t *to) { to->incompression); } -bool ans_key_h(connection_t *c, char *request) { +bool ans_key_h(connection_t *c, const char *request) { char from_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE]; char key[MAX_STRING_SIZE]; diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 0f95b0be..f255a581 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -40,7 +40,7 @@ bool send_status(connection_t *c, int statusno, const char *statusstring) { return send_request(c, "%d %d %s", STATUS, statusno, statusstring); } -bool status_h(connection_t *c, char *request) { +bool status_h(connection_t *c, const char *request) { int statusno; char statusstring[MAX_STRING_SIZE]; @@ -63,7 +63,7 @@ bool send_error(connection_t *c, int err, const char *errstring) { return send_request(c, "%d %d %s", ERROR, err, errstring); } -bool error_h(connection_t *c, char *request) { +bool error_h(connection_t *c, const char *request) { int err; char errorstring[MAX_STRING_SIZE]; @@ -83,7 +83,7 @@ bool send_termreq(connection_t *c) { return send_request(c, "%d", TERMREQ); } -bool termreq_h(connection_t *c, char *request) { +bool termreq_h(connection_t *c, const char *request) { return false; } @@ -94,7 +94,7 @@ bool send_ping(connection_t *c) { return send_request(c, "%d", PING); } -bool ping_h(connection_t *c, char *request) { +bool ping_h(connection_t *c, const char *request) { return send_pong(c); } @@ -102,7 +102,7 @@ bool send_pong(connection_t *c) { return send_request(c, "%d", PONG); } -bool pong_h(connection_t *c, char *request) { +bool pong_h(connection_t *c, const char *request) { c->status.pinged = false; /* Succesful connection, reset timeout if this is an outgoing connection. */ @@ -134,7 +134,7 @@ bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) { return send_meta(c, (char *)packet->data, packet->len); } -bool tcppacket_h(connection_t *c, char *request) { +bool tcppacket_h(connection_t *c, const char *request) { short int len; if(sscanf(request, "%*d %hd", &len) != 1) { diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 26cb5606..64f23425 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -41,7 +41,7 @@ bool send_add_subnet(connection_t *c, const subnet_t *subnet) { return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr); } -bool add_subnet_h(connection_t *c, char *request) { +bool add_subnet_h(connection_t *c, const char *request) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner; @@ -151,7 +151,7 @@ bool send_del_subnet(connection_t *c, const subnet_t *s) { return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr); } -bool del_subnet_h(connection_t *c, char *request) { +bool del_subnet_h(connection_t *c, const char *request) { char subnetstr[MAX_STRING_SIZE]; char name[MAX_STRING_SIZE]; node_t *owner;