mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-20 10:12:15 +01:00
more int to size_t conversions, fixing one or more amd64 bugs
plus a whitespace patch on config.c from vicman svn:r2482
This commit is contained in:
parent
92bb360ad7
commit
aebc3a03ba
@ -237,12 +237,12 @@ int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf) {
|
||||
* from the buffer. Return the number of bytes written on success,
|
||||
* -1 on failure. Return 0 if write() would block.
|
||||
*/
|
||||
int flush_buf(int s, buf_t *buf, int *buf_flushlen)
|
||||
int flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
|
||||
{
|
||||
int write_result;
|
||||
|
||||
assert_buf_ok(buf);
|
||||
tor_assert(buf_flushlen && (s>=0) && ((unsigned)*buf_flushlen <= buf->datalen));
|
||||
tor_assert(buf_flushlen && (s>=0) && (*buf_flushlen <= buf->datalen));
|
||||
|
||||
if(*buf_flushlen == 0) /* nothing to flush */
|
||||
return 0;
|
||||
@ -266,7 +266,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
|
||||
|
||||
/** As flush_buf, but writes data to a TLS connection.
|
||||
*/
|
||||
int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen)
|
||||
int flush_buf_tls(tor_tls *tls, buf_t *buf, size_t *buf_flushlen)
|
||||
{
|
||||
int r;
|
||||
assert_buf_ok(buf);
|
||||
@ -290,7 +290,7 @@ int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen)
|
||||
*
|
||||
* Return the new length of the buffer on success, -1 on failure.
|
||||
*/
|
||||
int write_to_buf(const char *string, int string_len, buf_t *buf) {
|
||||
int write_to_buf(const char *string, size_t string_len, buf_t *buf) {
|
||||
|
||||
/* append string to buf (growing as needed, return -1 if "too big")
|
||||
* return total number of bytes on the buf
|
||||
@ -348,10 +348,10 @@ int fetch_from_buf(char *string, size_t string_len, buf_t *buf) {
|
||||
* Else, change nothing and return 0.
|
||||
*/
|
||||
int fetch_from_buf_http(buf_t *buf,
|
||||
char **headers_out, int max_headerlen,
|
||||
char **body_out, int *body_used, int max_bodylen) {
|
||||
char **headers_out, size_t max_headerlen,
|
||||
char **body_out, size_t *body_used, size_t max_bodylen) {
|
||||
char *headers, *body, *p;
|
||||
int headerlen, bodylen, contentlen;
|
||||
size_t headerlen, bodylen, contentlen;
|
||||
|
||||
assert_buf_ok(buf);
|
||||
|
||||
@ -382,11 +382,13 @@ int fetch_from_buf_http(buf_t *buf,
|
||||
#define CONTENT_LENGTH "\r\nContent-Length: "
|
||||
p = strstr(headers, CONTENT_LENGTH);
|
||||
if (p) {
|
||||
contentlen = atoi(p+strlen(CONTENT_LENGTH));
|
||||
if (contentlen < 0) {
|
||||
int i;
|
||||
i = atoi(p+strlen(CONTENT_LENGTH));
|
||||
if (i < 0) {
|
||||
log_fn(LOG_WARN, "Content-Length is less than zero; it looks like someone is trying to crash us.");
|
||||
return -1;
|
||||
}
|
||||
contentlen = i;
|
||||
/* if content-length is malformed, then our body length is 0. fine. */
|
||||
log_fn(LOG_DEBUG,"Got a contentlen of %d.",contentlen);
|
||||
if(bodylen < contentlen) {
|
||||
|
@ -350,7 +350,7 @@ int circuit_send_next_onion_skin(circuit_t *circ) {
|
||||
int r;
|
||||
char payload[2+4+DIGEST_LEN+ONIONSKIN_CHALLENGE_LEN];
|
||||
char *onionskin;
|
||||
int payload_len;
|
||||
size_t payload_len;
|
||||
|
||||
tor_assert(circ && CIRCUIT_IS_ORIGIN(circ));
|
||||
|
||||
|
357
src/or/config.c
357
src/or/config.c
@ -37,23 +37,27 @@ static int config_assign(or_options_t *options, struct config_line_t *list);
|
||||
static int parse_dir_server_line(const char *line);
|
||||
|
||||
/** Helper: Read a list of configuration options from the command line. */
|
||||
static struct config_line_t *config_get_commandlines(int argc, char **argv) {
|
||||
static struct config_line_t *
|
||||
config_get_commandlines(int argc, char **argv)
|
||||
{
|
||||
struct config_line_t *new;
|
||||
struct config_line_t *front = NULL;
|
||||
char *s;
|
||||
int i = 1;
|
||||
|
||||
while(i < argc-1) {
|
||||
if(!strcmp(argv[i],"-f")) {
|
||||
while (i < argc-1) {
|
||||
if (!strcmp(argv[i],"-f")) {
|
||||
// log(LOG_DEBUG,"Commandline: skipping over -f.");
|
||||
i+=2; /* this is the config file option. ignore it. */
|
||||
i += 2; /* this is the config file option. ignore it. */
|
||||
continue;
|
||||
}
|
||||
|
||||
new = tor_malloc(sizeof(struct config_line_t));
|
||||
s = argv[i];
|
||||
|
||||
while(*s == '-')
|
||||
s++;
|
||||
|
||||
new->key = tor_strdup(s);
|
||||
new->value = tor_strdup(argv[i+1]);
|
||||
|
||||
@ -74,6 +78,7 @@ config_line_prepend(struct config_line_t *front,
|
||||
const char *val)
|
||||
{
|
||||
struct config_line_t *newline;
|
||||
|
||||
newline = tor_malloc(sizeof(struct config_line_t));
|
||||
newline->key = tor_strdup(key);
|
||||
newline->value = tor_strdup(val);
|
||||
@ -85,18 +90,19 @@ config_line_prepend(struct config_line_t *front,
|
||||
* strings. Set *result to the list, or NULL if parsing the file
|
||||
* failed. Return 0 on success, -1 on failure. Warn and ignore any
|
||||
* misformatted lines. */
|
||||
static int config_get_lines(FILE *f,
|
||||
struct config_line_t **result) {
|
||||
|
||||
static int
|
||||
config_get_lines(FILE *f, struct config_line_t **result)
|
||||
{
|
||||
struct config_line_t *front = NULL;
|
||||
char line[CONFIG_LINE_T_MAXLEN];
|
||||
int r;
|
||||
char *key, *value;
|
||||
|
||||
while( (r=parse_line_from_file(line,sizeof(line),f,&key,&value)) > 0) {
|
||||
while ((r = parse_line_from_file(line, sizeof(line), f, &key, &value)) > 0) {
|
||||
front = config_line_prepend(front, key, value);
|
||||
}
|
||||
if(r < 0) {
|
||||
|
||||
if (r < 0) {
|
||||
*result = NULL;
|
||||
return -1;
|
||||
} else {
|
||||
@ -108,10 +114,12 @@ static int config_get_lines(FILE *f,
|
||||
/**
|
||||
* Free all the configuration lines on the linked list <b>front</b>.
|
||||
*/
|
||||
static void config_free_lines(struct config_line_t *front) {
|
||||
static void
|
||||
config_free_lines(struct config_line_t *front)
|
||||
{
|
||||
struct config_line_t *tmp;
|
||||
|
||||
while(front) {
|
||||
while (front) {
|
||||
tmp = front;
|
||||
front = tmp->next;
|
||||
|
||||
@ -126,51 +134,61 @@ static void config_free_lines(struct config_line_t *front) {
|
||||
* the result in <b>arg</b>. If the option is misformatted, log a warning and
|
||||
* skip it.
|
||||
*/
|
||||
static int config_compare(struct config_line_t *c, const char *key, config_type_t type, void *arg) {
|
||||
static int
|
||||
config_compare(struct config_line_t *c, const char *key,
|
||||
config_type_t type, void *arg)
|
||||
{
|
||||
int i, ok;
|
||||
|
||||
if(strncasecmp(c->key,key,strlen(c->key)))
|
||||
if (strncasecmp(c->key, key, strlen(c->key)))
|
||||
return 0;
|
||||
|
||||
if(strcasecmp(c->key,key)) {
|
||||
if (strcasecmp(c->key, key)) {
|
||||
tor_free(c->key);
|
||||
c->key = tor_strdup(key);
|
||||
}
|
||||
|
||||
/* it's a match. cast and assign. */
|
||||
log_fn(LOG_DEBUG,"Recognized keyword '%s' as %s, using value '%s'.",c->key,key,c->value);
|
||||
log_fn(LOG_DEBUG, "Recognized keyword '%s' as %s, using value '%s'.",
|
||||
c->key, key, c->value);
|
||||
|
||||
switch(type) {
|
||||
case CONFIG_TYPE_UINT:
|
||||
i = tor_parse_long(c->value,10,0,INT_MAX,&ok,NULL);
|
||||
if(!ok) {
|
||||
i = tor_parse_long(c->value, 10, 0, INT_MAX, &ok, NULL);
|
||||
if (!ok) {
|
||||
log(LOG_WARN, "Int keyword '%s %s' is malformed or out of bounds. Skipping.",
|
||||
c->key,c->value);
|
||||
return 0;
|
||||
}
|
||||
*(int *)arg = i;
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_BOOL:
|
||||
i = tor_parse_long(c->value,10,0,1,&ok,NULL);
|
||||
i = tor_parse_long(c->value, 10, 0, 1, &ok, NULL);
|
||||
if (!ok) {
|
||||
log(LOG_WARN, "Boolean keyword '%s' expects 0 or 1. Skipping.", c->key);
|
||||
return 0;
|
||||
}
|
||||
*(int *)arg = i;
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_STRING:
|
||||
tor_free(*(char **)arg);
|
||||
*(char **)arg = tor_strdup(c->value);
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_DOUBLE:
|
||||
*(double *)arg = atof(c->value);
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_CSV:
|
||||
if(*(smartlist_t**)arg == NULL)
|
||||
if (*(smartlist_t**)arg == NULL)
|
||||
*(smartlist_t**)arg = smartlist_create();
|
||||
|
||||
smartlist_split_string(*(smartlist_t**)arg, c->value, ",",
|
||||
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_LINELIST:
|
||||
/* Note: this reverses the order that the lines appear in. That's
|
||||
* just fine, since we build up the list of lines reversed in the
|
||||
@ -178,10 +196,12 @@ static int config_compare(struct config_line_t *c, const char *key, config_type_
|
||||
*(struct config_line_t**)arg =
|
||||
config_line_prepend(*(struct config_line_t**)arg, c->key, c->value);
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_OBSOLETE:
|
||||
log_fn(LOG_WARN, "Skipping obsolete configuration option '%s'", c->key);
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -189,10 +209,11 @@ static int config_compare(struct config_line_t *c, const char *key, config_type_
|
||||
* For each item, convert as appropriate and assign to <b>options</b>.
|
||||
* If an item is unrecognized, return -1 immediately,
|
||||
* else return 0 for success. */
|
||||
static int config_assign(or_options_t *options, struct config_line_t *list) {
|
||||
|
||||
while(list) {
|
||||
if(
|
||||
static int
|
||||
config_assign(or_options_t *options, struct config_line_t *list)
|
||||
{
|
||||
while (list) {
|
||||
if (
|
||||
|
||||
/* order matters here! abbreviated arguments use the first match. */
|
||||
|
||||
@ -269,7 +290,6 @@ static int config_assign(or_options_t *options, struct config_line_t *list) {
|
||||
|
||||
config_compare(list, "User", CONFIG_TYPE_STRING, &options->User)
|
||||
|
||||
|
||||
) {
|
||||
/* then we're ok. it matched something. */
|
||||
} else {
|
||||
@ -279,10 +299,13 @@ static int config_assign(or_options_t *options, struct config_line_t *list) {
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void add_default_trusted_dirservers(void) {
|
||||
static void
|
||||
add_default_trusted_dirservers(void)
|
||||
{
|
||||
/* moria1 */
|
||||
parse_dir_server_line("18.244.0.188:9031 "
|
||||
"FFCB 46DB 1339 DA84 674C 70D7 CB58 6434 C437 0441");
|
||||
@ -298,8 +321,9 @@ static void add_default_trusted_dirservers(void) {
|
||||
*
|
||||
* Call this function when we can't find any torrc config file.
|
||||
*/
|
||||
static int config_assign_defaults(or_options_t *options) {
|
||||
|
||||
static int
|
||||
config_assign_defaults(or_options_t *options)
|
||||
{
|
||||
/* set them up as a client only */
|
||||
options->SocksPort = 9050;
|
||||
|
||||
@ -314,7 +338,9 @@ static int config_assign_defaults(or_options_t *options) {
|
||||
}
|
||||
|
||||
/** Print a usage message for tor. */
|
||||
static void print_usage(void) {
|
||||
static void
|
||||
print_usage(void)
|
||||
{
|
||||
printf("tor -f <torrc> [args]\n"
|
||||
"See man page for more options. This -h is probably obsolete.\n\n"
|
||||
"-b <bandwidth>\t\tbytes/second rate limiting\n"
|
||||
@ -324,20 +350,20 @@ static void print_usage(void) {
|
||||
"-r <file>\t\tList of known routers\n");
|
||||
printf("\nClient options:\n"
|
||||
"-e \"nick1 nick2 ...\"\t\tExit nodes\n"
|
||||
"-s <IP>\t\t\tPort to bind to for Socks\n"
|
||||
);
|
||||
"-s <IP>\t\t\tPort to bind to for Socks\n");
|
||||
printf("\nServer options:\n"
|
||||
"-n <nick>\t\tNickname of router\n"
|
||||
"-o <port>\t\tOR port to bind to\n"
|
||||
"-p <file>\t\tPID file\n"
|
||||
);
|
||||
"-p <file>\t\tPID file\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on <b>address</b>, guess our public IP address and put it
|
||||
* in <b>addr</b>.
|
||||
*/
|
||||
int resolve_my_address(const char *address, uint32_t *addr) {
|
||||
int
|
||||
resolve_my_address(const char *address, uint32_t *addr)
|
||||
{
|
||||
struct in_addr in;
|
||||
struct hostent *rent;
|
||||
char hostname[256];
|
||||
@ -345,12 +371,12 @@ int resolve_my_address(const char *address, uint32_t *addr) {
|
||||
|
||||
tor_assert(addr);
|
||||
|
||||
if(address) {
|
||||
strlcpy(hostname,address,sizeof(hostname));
|
||||
if (address) {
|
||||
strlcpy(hostname, address, sizeof(hostname));
|
||||
} else { /* then we need to guess our address */
|
||||
explicit_ip = 0; /* it's implicit */
|
||||
|
||||
if(gethostname(hostname,sizeof(hostname)) < 0) {
|
||||
if (gethostname(hostname, sizeof(hostname)) < 0) {
|
||||
log_fn(LOG_WARN,"Error obtaining local hostname");
|
||||
return -1;
|
||||
}
|
||||
@ -359,7 +385,7 @@ int resolve_my_address(const char *address, uint32_t *addr) {
|
||||
|
||||
/* now we know hostname. resolve it and keep only the IP */
|
||||
|
||||
if(tor_inet_aton(hostname, &in) == 0) {
|
||||
if (tor_inet_aton(hostname, &in) == 0) {
|
||||
/* then we have to resolve it */
|
||||
explicit_ip = 0;
|
||||
rent = (struct hostent *)gethostbyname(hostname);
|
||||
@ -368,39 +394,44 @@ int resolve_my_address(const char *address, uint32_t *addr) {
|
||||
return -1;
|
||||
}
|
||||
tor_assert(rent->h_length == 4);
|
||||
memcpy(&in.s_addr, rent->h_addr,rent->h_length);
|
||||
memcpy(&in.s_addr, rent->h_addr, rent->h_length);
|
||||
}
|
||||
if(!explicit_ip && is_internal_IP(htonl(in.s_addr))) {
|
||||
|
||||
if (!explicit_ip && is_internal_IP(htonl(in.s_addr))) {
|
||||
log_fn(LOG_WARN,"Address '%s' resolves to private IP '%s'. "
|
||||
"Please set the Address config option to be the IP you want to use.",
|
||||
hostname, inet_ntoa(in));
|
||||
return -1;
|
||||
}
|
||||
log_fn(LOG_DEBUG,"Resolved Address to %s.", inet_ntoa(in));
|
||||
|
||||
log_fn(LOG_DEBUG, "Resolved Address to %s.", inet_ntoa(in));
|
||||
*addr = ntohl(in.s_addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *get_default_nickname(void)
|
||||
static char *
|
||||
get_default_nickname(void)
|
||||
{
|
||||
char localhostname[256];
|
||||
char *cp, *out, *outp;
|
||||
|
||||
if(gethostname(localhostname,sizeof(localhostname)) < 0) {
|
||||
if (gethostname(localhostname, sizeof(localhostname)) < 0) {
|
||||
log_fn(LOG_WARN,"Error obtaining local hostname");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Put it in lowercase; stop at the first dot. */
|
||||
for(cp = localhostname; *cp; ++cp) {
|
||||
for (cp = localhostname; *cp; ++cp) {
|
||||
if (*cp == '.') {
|
||||
*cp = '\0';
|
||||
break;
|
||||
}
|
||||
*cp = tolower(*cp);
|
||||
}
|
||||
|
||||
/* Strip invalid characters. */
|
||||
cp = localhostname;
|
||||
out = outp = tor_malloc(strlen(localhostname)+1);
|
||||
out = outp = tor_malloc(strlen(localhostname) + 1);
|
||||
while (*cp) {
|
||||
if (strchr(LEGAL_NICKNAME_CHARACTERS, *cp))
|
||||
*outp++ = *cp++;
|
||||
@ -408,6 +439,7 @@ static char *get_default_nickname(void)
|
||||
cp++;
|
||||
}
|
||||
*outp = '\0';
|
||||
|
||||
/* Enforce length. */
|
||||
if (strlen(out) > MAX_NICKNAME_LEN)
|
||||
out[MAX_NICKNAME_LEN]='\0';
|
||||
@ -416,7 +448,9 @@ static char *get_default_nickname(void)
|
||||
}
|
||||
|
||||
/** Release storage held by <b>options</b> */
|
||||
static void free_options(or_options_t *options) {
|
||||
static void
|
||||
free_options(or_options_t *options)
|
||||
{
|
||||
config_free_lines(options->LogOptions);
|
||||
tor_free(options->ContactInfo);
|
||||
tor_free(options->DebugLogFile);
|
||||
@ -449,9 +483,11 @@ static void free_options(or_options_t *options) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Set <b>options</b> to hold reasonable defaults for most options. */
|
||||
static void init_options(or_options_t *options) {
|
||||
/* give reasonable values for each option. Defaults to zero. */
|
||||
/** Set <b>options</b> to hold reasonable defaults for most options.
|
||||
* Each option defaults to zero. */
|
||||
static void
|
||||
init_options(or_options_t *options)
|
||||
{
|
||||
memset(options,0,sizeof(or_options_t));
|
||||
options->LogOptions = NULL;
|
||||
options->ExitNodes = tor_strdup("");
|
||||
@ -483,7 +519,8 @@ static void init_options(or_options_t *options) {
|
||||
options->DirServers = NULL;
|
||||
}
|
||||
|
||||
static char *get_default_conf_file(void)
|
||||
static char *
|
||||
get_default_conf_file(void)
|
||||
{
|
||||
#ifdef MS_WINDOWS
|
||||
LPITEMIDLIST idl;
|
||||
@ -520,7 +557,9 @@ static char *get_default_conf_file(void)
|
||||
/** Read a configuration file into <b>options</b>, finding the configuration
|
||||
* file location based on the command line. After loading the options,
|
||||
* validate them for consistency. Return 0 if success, <0 if failure. */
|
||||
int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
int
|
||||
getconfig(int argc, char **argv, or_options_t *options)
|
||||
{
|
||||
struct config_line_t *cl;
|
||||
FILE *cf;
|
||||
char *fname;
|
||||
@ -534,7 +573,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
int previous_orport = -1;
|
||||
int using_default_torrc;
|
||||
|
||||
if(first_load) { /* first time we're called. save commandline args */
|
||||
if (first_load) { /* first time we're called. save commandline args */
|
||||
backup_argv = argv;
|
||||
backup_argc = argc;
|
||||
first_load = 0;
|
||||
@ -543,7 +582,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
argc = backup_argc;
|
||||
|
||||
/* record some previous values, so we can fail if they change */
|
||||
if(options->PidFile)
|
||||
if (options->PidFile)
|
||||
previous_pidfile = tor_strdup(options->PidFile);
|
||||
previous_runasdaemon = options->RunAsDaemon;
|
||||
previous_orport = options->ORPort;
|
||||
@ -551,22 +590,23 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
}
|
||||
init_options(options);
|
||||
|
||||
if(argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) {
|
||||
if (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1],"--help"))) {
|
||||
print_usage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if(argc > 1 && (!strcmp(argv[1],"--version"))) {
|
||||
if (argc > 1 && (!strcmp(argv[1],"--version"))) {
|
||||
printf("Tor version %s.\n",VERSION);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* learn config file name, get config lines, assign them */
|
||||
i = 1;
|
||||
while(i < argc-1 && strcmp(argv[i],"-f")) {
|
||||
while (i < argc-1 && strcmp(argv[i],"-f")) {
|
||||
i++;
|
||||
}
|
||||
if(i < argc-1) { /* we found one */
|
||||
|
||||
if (i < argc-1) { /* we found one */
|
||||
fname = tor_strdup(argv[i+1]);
|
||||
using_default_torrc = 0;
|
||||
} else {
|
||||
@ -574,12 +614,12 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
char *fn;
|
||||
using_default_torrc = 1;
|
||||
fn = get_default_conf_file();
|
||||
if (fn && file_status(fn)==FN_FILE) {
|
||||
if (fn && file_status(fn) == FN_FILE) {
|
||||
fname = fn;
|
||||
} else {
|
||||
tor_free(fn);
|
||||
fn = expand_filename("~/.torrc");
|
||||
if (fn && file_status(fn)==FN_FILE) {
|
||||
if (fn && file_status(fn) == FN_FILE) {
|
||||
fname = fn;
|
||||
} else {
|
||||
tor_free(fn);
|
||||
@ -588,18 +628,20 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
}
|
||||
}
|
||||
tor_assert(fname);
|
||||
log(LOG_DEBUG,"Opening config file '%s'",fname);
|
||||
log(LOG_DEBUG, "Opening config file '%s'", fname);
|
||||
|
||||
if(config_assign_defaults(options) < 0) {
|
||||
if (config_assign_defaults(options) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cf = fopen(fname, "r");
|
||||
if(!cf) {
|
||||
if(using_default_torrc == 1) {
|
||||
log(LOG_NOTICE, "Configuration file '%s' not present, using reasonable defaults.",fname);
|
||||
if (!cf) {
|
||||
if (using_default_torrc == 1) {
|
||||
log(LOG_NOTICE, "Configuration file '%s' not present, "
|
||||
"using reasonable defaults.", fname);
|
||||
tor_free(fname);
|
||||
} else {
|
||||
log(LOG_WARN, "Unable to open configuration file '%s'.",fname);
|
||||
log(LOG_WARN, "Unable to open configuration file '%s'.", fname);
|
||||
tor_free(fname);
|
||||
return -1;
|
||||
}
|
||||
@ -607,7 +649,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
tor_free(fname);
|
||||
if (config_get_lines(cf, &cl)<0)
|
||||
return -1;
|
||||
if(config_assign(options,cl) < 0)
|
||||
if (config_assign(options,cl) < 0)
|
||||
return -1;
|
||||
config_free_lines(cl);
|
||||
fclose(cf);
|
||||
@ -615,37 +657,37 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
|
||||
/* go through command-line variables too */
|
||||
cl = config_get_commandlines(argc,argv);
|
||||
if(config_assign(options,cl) < 0)
|
||||
if (config_assign(options,cl) < 0)
|
||||
return -1;
|
||||
config_free_lines(cl);
|
||||
|
||||
/* Validate options */
|
||||
|
||||
/* first check if any of the previous options have changed but aren't allowed to */
|
||||
if(previous_pidfile && strcmp(previous_pidfile,options->PidFile)) {
|
||||
if (previous_pidfile && strcmp(previous_pidfile,options->PidFile)) {
|
||||
log_fn(LOG_WARN,"During reload, PidFile changed from %s to %s. Failing.",
|
||||
previous_pidfile, options->PidFile);
|
||||
return -1;
|
||||
}
|
||||
tor_free(previous_pidfile);
|
||||
|
||||
if(previous_runasdaemon && !options->RunAsDaemon) {
|
||||
if (previous_runasdaemon && !options->RunAsDaemon) {
|
||||
log_fn(LOG_WARN,"During reload, change from RunAsDaemon=1 to =0 not allowed. Failing.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(previous_orport == 0 && options->ORPort > 0) {
|
||||
if (previous_orport == 0 && options->ORPort > 0) {
|
||||
log_fn(LOG_WARN,"During reload, change from ORPort=0 to >0 not allowed. Failing.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(options->ORPort < 0 || options->ORPort > 65535) {
|
||||
log(LOG_WARN,"ORPort option out of bounds.");
|
||||
if (options->ORPort < 0 || options->ORPort > 65535) {
|
||||
log(LOG_WARN, "ORPort option out of bounds.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if (options->Nickname == NULL) {
|
||||
if(server_mode()) {
|
||||
if (server_mode()) {
|
||||
if (!(options->Nickname = get_default_nickname()))
|
||||
return -1;
|
||||
log_fn(LOG_NOTICE, "Choosing default nickname %s", options->Nickname);
|
||||
@ -667,64 +709,65 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
}
|
||||
}
|
||||
|
||||
if(server_mode()) {
|
||||
if (server_mode()) {
|
||||
/* confirm that our address isn't broken, so we can complain now */
|
||||
uint32_t tmp;
|
||||
if(resolve_my_address(options->Address, &tmp) < 0)
|
||||
if (resolve_my_address(options->Address, &tmp) < 0)
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->SocksPort < 0 || options->SocksPort > 65535) {
|
||||
log(LOG_WARN,"SocksPort option out of bounds.");
|
||||
if (options->SocksPort < 0 || options->SocksPort > 65535) {
|
||||
log(LOG_WARN, "SocksPort option out of bounds.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->SocksPort == 0 && options->ORPort == 0) {
|
||||
log(LOG_WARN,"SocksPort and ORPort are both undefined? Quitting.");
|
||||
if (options->SocksPort == 0 && options->ORPort == 0) {
|
||||
log(LOG_WARN, "SocksPort and ORPort are both undefined? Quitting.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->DirPort < 0 || options->DirPort > 65535) {
|
||||
log(LOG_WARN,"DirPort option out of bounds.");
|
||||
if (options->DirPort < 0 || options->DirPort > 65535) {
|
||||
log(LOG_WARN, "DirPort option out of bounds.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->StrictExitNodes && !strlen(options->ExitNodes)) {
|
||||
log(LOG_WARN,"StrictExitNodes set, but no ExitNodes listed.");
|
||||
if (options->StrictExitNodes && !strlen(options->ExitNodes)) {
|
||||
log(LOG_WARN, "StrictExitNodes set, but no ExitNodes listed.");
|
||||
}
|
||||
|
||||
if(options->StrictEntryNodes && !strlen(options->EntryNodes)) {
|
||||
log(LOG_WARN,"StrictEntryNodes set, but no EntryNodes listed.");
|
||||
if (options->StrictEntryNodes && !strlen(options->EntryNodes)) {
|
||||
log(LOG_WARN, "StrictEntryNodes set, but no EntryNodes listed.");
|
||||
}
|
||||
|
||||
if(options->AuthoritativeDir && options->RecommendedVersions == NULL) {
|
||||
log(LOG_WARN,"Directory servers must configure RecommendedVersions.");
|
||||
if (options->AuthoritativeDir && options->RecommendedVersions == NULL) {
|
||||
log(LOG_WARN, "Directory servers must configure RecommendedVersions.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->AuthoritativeDir && !options->DirPort) {
|
||||
log(LOG_WARN,"Running as authoritative directory, but no DirPort set.");
|
||||
if (options->AuthoritativeDir && !options->DirPort) {
|
||||
log(LOG_WARN, "Running as authoritative directory, but no DirPort set.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->AuthoritativeDir && !options->ORPort) {
|
||||
log(LOG_WARN,"Running as authoritative directory, but no ORPort set.");
|
||||
if (options->AuthoritativeDir && !options->ORPort) {
|
||||
log(LOG_WARN, "Running as authoritative directory, but no ORPort set.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->AuthoritativeDir && options->ClientOnly) {
|
||||
log(LOG_WARN,"Running as authoritative directory, but ClientOnly also set.");
|
||||
if (options->AuthoritativeDir && options->ClientOnly) {
|
||||
log(LOG_WARN, "Running as authoritative directory, but ClientOnly also set.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->FascistFirewall && !options->FirewallPorts) {
|
||||
if (options->FascistFirewall && !options->FirewallPorts) {
|
||||
options->FirewallPorts = smartlist_create();
|
||||
smartlist_add(options->FirewallPorts, tor_strdup("80"));
|
||||
smartlist_add(options->FirewallPorts, tor_strdup("443"));
|
||||
}
|
||||
if(options->FirewallPorts) {
|
||||
if (options->FirewallPorts) {
|
||||
SMARTLIST_FOREACH(options->FirewallPorts, const char *, cp,
|
||||
{ i = atoi(cp);
|
||||
{
|
||||
i = atoi(cp);
|
||||
if (i < 1 || i > 65535) {
|
||||
log(LOG_WARN, "Port '%s' out of range in FirewallPorts", cp);
|
||||
result=-1;
|
||||
@ -732,9 +775,9 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
});
|
||||
}
|
||||
options->_AllowUnverified = 0;
|
||||
if(options->AllowUnverifiedNodes) {
|
||||
SMARTLIST_FOREACH(options->AllowUnverifiedNodes, const char *, cp,
|
||||
{ if (!strcasecmp(cp, "entry"))
|
||||
if (options->AllowUnverifiedNodes) {
|
||||
SMARTLIST_FOREACH(options->AllowUnverifiedNodes, const char *, cp, {
|
||||
if (!strcasecmp(cp, "entry"))
|
||||
options->_AllowUnverified |= ALLOW_UNVERIFIED_ENTRY;
|
||||
else if (!strcasecmp(cp, "exit"))
|
||||
options->_AllowUnverified |= ALLOW_UNVERIFIED_EXIT;
|
||||
@ -752,45 +795,45 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
});
|
||||
}
|
||||
|
||||
if(options->SocksPort >= 1 &&
|
||||
if (options->SocksPort >= 1 &&
|
||||
(options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0)) {
|
||||
log(LOG_WARN,"PathlenCoinWeight option must be >=0.0 and <1.0.");
|
||||
log(LOG_WARN, "PathlenCoinWeight option must be >=0.0 and <1.0.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->MaxConn < 1) {
|
||||
log(LOG_WARN,"MaxConn option must be a non-zero positive integer.");
|
||||
if (options->MaxConn < 1) {
|
||||
log(LOG_WARN, "MaxConn option must be a non-zero positive integer.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->MaxConn >= MAXCONNECTIONS) {
|
||||
log(LOG_WARN,"MaxConn option must be less than %d.", MAXCONNECTIONS);
|
||||
if (options->MaxConn >= MAXCONNECTIONS) {
|
||||
log(LOG_WARN, "MaxConn option must be less than %d.", MAXCONNECTIONS);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
#define MIN_DIRFETCHPOSTPERIOD 60
|
||||
if(options->DirFetchPostPeriod < MIN_DIRFETCHPOSTPERIOD) {
|
||||
log(LOG_WARN,"DirFetchPostPeriod option must be at least %d.", MIN_DIRFETCHPOSTPERIOD);
|
||||
if (options->DirFetchPostPeriod < MIN_DIRFETCHPOSTPERIOD) {
|
||||
log(LOG_WARN, "DirFetchPostPeriod option must be at least %d.", MIN_DIRFETCHPOSTPERIOD);
|
||||
result = -1;
|
||||
}
|
||||
if(options->DirFetchPostPeriod > MIN_ONION_KEY_LIFETIME/2) {
|
||||
log(LOG_WARN,"DirFetchPostPeriod is too large; clipping.");
|
||||
options->DirFetchPostPeriod = MIN_ONION_KEY_LIFETIME/2;
|
||||
if (options->DirFetchPostPeriod > MIN_ONION_KEY_LIFETIME / 2) {
|
||||
log(LOG_WARN, "DirFetchPostPeriod is too large; clipping.");
|
||||
options->DirFetchPostPeriod = MIN_ONION_KEY_LIFETIME / 2;
|
||||
}
|
||||
|
||||
if(options->KeepalivePeriod < 1) {
|
||||
if (options->KeepalivePeriod < 1) {
|
||||
log(LOG_WARN,"KeepalivePeriod option must be positive.");
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if(options->HttpProxy) { /* parse it now */
|
||||
if(parse_addr_port(options->HttpProxy, NULL,
|
||||
if (options->HttpProxy) { /* parse it now */
|
||||
if (parse_addr_port(options->HttpProxy, NULL,
|
||||
&options->HttpProxyAddr, &options->HttpProxyPort) < 0) {
|
||||
log(LOG_WARN,"HttpProxy failed to parse or resolve. Please fix.");
|
||||
result = -1;
|
||||
}
|
||||
options->HttpProxyAddr = ntohl(options->HttpProxyAddr); /* switch to host-order */
|
||||
if(options->HttpProxyPort == 0) { /* give it a default */
|
||||
if (options->HttpProxyPort == 0) { /* give it a default */
|
||||
options->HttpProxyPort = 80;
|
||||
}
|
||||
}
|
||||
@ -816,11 +859,11 @@ int getconfig(int argc, char **argv, or_options_t *options) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static int add_single_log(struct config_line_t *level_opt,
|
||||
struct config_line_t *file_opt,
|
||||
int isDaemon)
|
||||
static int
|
||||
add_single_log(struct config_line_t *level_opt,
|
||||
struct config_line_t *file_opt, int isDaemon)
|
||||
{
|
||||
int levelMin=-1, levelMax=-1;
|
||||
int levelMin = -1, levelMax = -1;
|
||||
char *cp, *tmp_sev;
|
||||
|
||||
if (level_opt) {
|
||||
@ -828,20 +871,23 @@ static int add_single_log(struct config_line_t *level_opt,
|
||||
if (cp) {
|
||||
tmp_sev = tor_strndup(level_opt->value, cp - level_opt->value);
|
||||
levelMin = parse_log_level(tmp_sev);
|
||||
if (levelMin<0) {
|
||||
log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of err|warn|notice|info|debug", tmp_sev);
|
||||
if (levelMin < 0) {
|
||||
log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of "
|
||||
"err|warn|notice|info|debug", tmp_sev);
|
||||
return -1;
|
||||
}
|
||||
tor_free(tmp_sev);
|
||||
levelMax = parse_log_level(cp+1);
|
||||
if (levelMax<0) {
|
||||
log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of err|warn|notice|info|debug", cp+1);
|
||||
if (levelMax < 0) {
|
||||
log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of "
|
||||
"err|warn|notice|info|debug", cp+1);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
levelMin = parse_log_level(level_opt->value);
|
||||
if (levelMin<0) {
|
||||
log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of err|warn|notice|info|debug", level_opt->value);
|
||||
if (levelMin < 0) {
|
||||
log_fn(LOG_WARN, "Unrecognized log severity '%s': must be one of "
|
||||
"err|warn|notice|info|debug", level_opt->value);
|
||||
return -1;
|
||||
|
||||
}
|
||||
@ -873,7 +919,8 @@ static int add_single_log(struct config_line_t *level_opt,
|
||||
/**
|
||||
* Initialize the logs based on the configuration file.
|
||||
*/
|
||||
int config_init_logs(or_options_t *options)
|
||||
int
|
||||
config_init_logs(or_options_t *options)
|
||||
{
|
||||
/* The order of options is: Level? (File Level?)+
|
||||
*/
|
||||
@ -889,11 +936,11 @@ int config_init_logs(or_options_t *options)
|
||||
/* Special case for if first option is LogLevel. */
|
||||
if (opt && !strcasecmp(opt->key, "LogLevel")) {
|
||||
if (opt->next && !strcasecmp(opt->next->key, "LogFile")) {
|
||||
if (add_single_log(opt, opt->next, options->RunAsDaemon)<0)
|
||||
if (add_single_log(opt, opt->next, options->RunAsDaemon) < 0)
|
||||
return -1;
|
||||
opt = opt->next->next;
|
||||
} else if (!opt->next) {
|
||||
if (add_single_log(opt, NULL, options->RunAsDaemon)<0)
|
||||
if (add_single_log(opt, NULL, options->RunAsDaemon) < 0)
|
||||
return -1;
|
||||
opt = opt->next;
|
||||
} else {
|
||||
@ -909,12 +956,12 @@ int config_init_logs(or_options_t *options)
|
||||
tor_assert(!strcasecmp(opt->key, "LogFile"));
|
||||
if (opt->next && !strcasecmp(opt->next->key, "LogLevel")) {
|
||||
/* LogFile followed by LogLevel */
|
||||
if (add_single_log(opt->next, opt, options->RunAsDaemon)<0)
|
||||
if (add_single_log(opt->next, opt, options->RunAsDaemon) < 0)
|
||||
return -1;
|
||||
opt = opt->next->next;
|
||||
} else {
|
||||
/* LogFile followed by LogFile or end of list. */
|
||||
if (add_single_log(NULL, opt, options->RunAsDaemon)<0)
|
||||
if (add_single_log(NULL, opt, options->RunAsDaemon) < 0)
|
||||
return -1;
|
||||
opt = opt->next;
|
||||
}
|
||||
@ -923,9 +970,10 @@ int config_init_logs(or_options_t *options)
|
||||
|
||||
if (options->DebugLogFile) {
|
||||
log_fn(LOG_WARN, "DebugLogFile is deprecated; use LogFile and LogLevel instead");
|
||||
if (add_file_log(LOG_DEBUG, LOG_ERR, options->DebugLogFile)<0)
|
||||
if (add_file_log(LOG_DEBUG, LOG_ERR, options->DebugLogFile) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -942,17 +990,20 @@ config_parse_exit_policy(struct config_line_t *cfg,
|
||||
|
||||
if (!cfg)
|
||||
return;
|
||||
|
||||
nextp = dest;
|
||||
|
||||
while (*nextp)
|
||||
nextp = &((*nextp)->next);
|
||||
|
||||
entries = smartlist_create();
|
||||
for (; cfg; cfg = cfg->next) {
|
||||
smartlist_split_string(entries,cfg->value,",",SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK,0);
|
||||
SMARTLIST_FOREACH(entries, const char *, ent, {
|
||||
smartlist_split_string(entries, cfg->value, ",", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
||||
SMARTLIST_FOREACH(entries, const char *, ent,
|
||||
{
|
||||
log_fn(LOG_DEBUG,"Adding new entry '%s'",ent);
|
||||
*nextp = router_parse_exit_policy_from_string(ent);
|
||||
if(*nextp) {
|
||||
if (*nextp) {
|
||||
nextp = &((*nextp)->next);
|
||||
} else {
|
||||
log_fn(LOG_WARN,"Malformed exit policy %s; skipping.", ent);
|
||||
@ -966,6 +1017,7 @@ config_parse_exit_policy(struct config_line_t *cfg,
|
||||
|
||||
void exit_policy_free(struct exit_policy_t *p) {
|
||||
struct exit_policy_t *e;
|
||||
|
||||
while (p) {
|
||||
e = p;
|
||||
p = p->next;
|
||||
@ -981,49 +1033,63 @@ static int parse_dir_server_line(const char *line)
|
||||
char *addrport, *address=NULL;
|
||||
uint16_t port;
|
||||
char digest[DIGEST_LEN];
|
||||
|
||||
items = smartlist_create();
|
||||
smartlist_split_string(items, line, " ",
|
||||
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
|
||||
if (smartlist_len(items) < 2) {
|
||||
log_fn(LOG_WARN, "Too few arguments to DirServer line."); goto err;
|
||||
log_fn(LOG_WARN, "Too few arguments to DirServer line.");
|
||||
goto err;
|
||||
}
|
||||
addrport = smartlist_get(items, 0);
|
||||
if (parse_addr_port(addrport, &address, NULL, &port)<0) {
|
||||
log_fn(LOG_WARN, "Error parsing DirServer address '%s'", addrport);goto err;
|
||||
log_fn(LOG_WARN, "Error parsing DirServer address '%s'", addrport);
|
||||
goto err;
|
||||
}
|
||||
if (!port) {
|
||||
log_fn(LOG_WARN, "Missing port in DirServe address '%s'",addrport);goto err;
|
||||
log_fn(LOG_WARN, "Missing port in DirServe address '%s'",addrport);
|
||||
goto err;
|
||||
}
|
||||
|
||||
tor_strstrip(smartlist_get(items, 1), " ");
|
||||
if (strlen(smartlist_get(items, 1)) != HEX_DIGEST_LEN) {
|
||||
log_fn(LOG_WARN, "Key digest for DirServer is wrong length."); goto err;
|
||||
log_fn(LOG_WARN, "Key digest for DirServer is wrong length.");
|
||||
goto err;
|
||||
}
|
||||
if (base16_decode(digest, DIGEST_LEN,
|
||||
smartlist_get(items,1), HEX_DIGEST_LEN)<0) {
|
||||
log_fn(LOG_WARN, "Unable to decode DirServer key digest."); goto err;
|
||||
log_fn(LOG_WARN, "Unable to decode DirServer key digest.");
|
||||
goto err;
|
||||
}
|
||||
|
||||
log_fn(LOG_DEBUG, "Trusted dirserver at %s:%d (%s)", address,(int)port,
|
||||
log_fn(LOG_DEBUG, "Trusted dirserver at %s:%d (%s)", address, (int)port,
|
||||
(char*)smartlist_get(items,1));
|
||||
add_trusted_dir_server(address, port, digest);
|
||||
|
||||
r = 0;
|
||||
goto done;
|
||||
|
||||
err:
|
||||
r = -1;
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(items, char*, s, tor_free(s));
|
||||
smartlist_free(items);
|
||||
if (address) tor_free(address);
|
||||
|
||||
if (address)
|
||||
tor_free(address);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
const char *get_data_directory(or_options_t *options) {
|
||||
const char *
|
||||
get_data_directory(or_options_t *options)
|
||||
{
|
||||
const char *d;
|
||||
if (options->DataDirectory)
|
||||
|
||||
if (options->DataDirectory) {
|
||||
d = options->DataDirectory;
|
||||
else {
|
||||
} else {
|
||||
#ifdef MS_WINDOWS
|
||||
char *p;
|
||||
p = tor_malloc(MAX_PATH);
|
||||
@ -1037,10 +1103,11 @@ const char *get_data_directory(or_options_t *options) {
|
||||
d = "~/.tor";
|
||||
#endif
|
||||
}
|
||||
if (d && strncmp(d,"~/",2)==0) {
|
||||
|
||||
if (d && strncmp(d,"~/",2) == 0) {
|
||||
char *fn = expand_filename(d);
|
||||
if(!fn) {
|
||||
log_fn(LOG_ERR,"Failed to expand filename '%s'. Exiting.",d);
|
||||
if (!fn) {
|
||||
log_fn(LOG_ERR,"Failed to expand filename '%s'. Exiting.", d);
|
||||
exit(1);
|
||||
}
|
||||
tor_free(options->DataDirectory);
|
||||
|
@ -376,8 +376,10 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport
|
||||
static int connection_handle_listener_read(connection_t *conn, int new_type) {
|
||||
int news; /* the new socket */
|
||||
connection_t *newconn;
|
||||
struct sockaddr_in remote; /* information about the remote peer when connecting to other routers */
|
||||
int remotelen = sizeof(struct sockaddr_in); /* length of the remote address */
|
||||
/* information about the remote peer when connecting to other routers */
|
||||
struct sockaddr_in remote;
|
||||
/* length of the remote address. Must be an int, since accept() needs that. */
|
||||
int remotelen = sizeof(struct sockaddr_in);
|
||||
|
||||
news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
|
||||
if (news == -1) { /* accept() error */
|
||||
@ -811,7 +813,7 @@ static int connection_read_to_buf(connection_t *conn) {
|
||||
}
|
||||
|
||||
/** A pass-through to fetch_from_buf. */
|
||||
int connection_fetch_from_buf(char *string, int len, connection_t *conn) {
|
||||
int connection_fetch_from_buf(char *string, size_t len, connection_t *conn) {
|
||||
return fetch_from_buf(string, len, conn->inbuf);
|
||||
}
|
||||
|
||||
@ -953,7 +955,7 @@ int connection_handle_write(connection_t *conn) {
|
||||
/** Append <b>len</b> bytes of <b>string</b> onto <b>conn</b>'s
|
||||
* outbuf, and ask it to start writing.
|
||||
*/
|
||||
void connection_write_to_buf(const char *string, int len, connection_t *conn) {
|
||||
void connection_write_to_buf(const char *string, size_t len, connection_t *conn) {
|
||||
|
||||
if(!len || conn->marked_for_close)
|
||||
return;
|
||||
|
@ -129,7 +129,7 @@ int
|
||||
connection_edge_end(connection_t *conn, char reason, crypt_path_t *cpath_layer)
|
||||
{
|
||||
char payload[5];
|
||||
int payload_len=1;
|
||||
size_t payload_len=1;
|
||||
circuit_t *circ;
|
||||
|
||||
if(conn->has_sent_end) {
|
||||
@ -625,11 +625,11 @@ int connection_ap_make_bridge(char *address, uint16_t port) {
|
||||
|
||||
void connection_ap_handshake_socks_resolved(connection_t *conn,
|
||||
int answer_type,
|
||||
int answer_len,
|
||||
size_t answer_len,
|
||||
const char *answer)
|
||||
{
|
||||
char buf[256];
|
||||
int replylen;
|
||||
size_t replylen;
|
||||
|
||||
if (answer_type == RESOLVED_TYPE_IPV4) {
|
||||
uint32_t a = get_uint32(answer);
|
||||
@ -686,7 +686,7 @@ void connection_ap_handshake_socks_resolved(connection_t *conn,
|
||||
* Otherwise, send back a reply based on whether <b>success</b> is 1 or 0.
|
||||
*/
|
||||
void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
|
||||
int replylen, int success) {
|
||||
size_t replylen, int success) {
|
||||
char buf[256];
|
||||
|
||||
if(replylen) { /* we already have a reply in mind */
|
||||
|
@ -28,21 +28,21 @@
|
||||
|
||||
static void
|
||||
directory_initiate_command_router(routerinfo_t *router, uint8_t purpose,
|
||||
const char *payload, int payload_len);
|
||||
const char *payload, size_t payload_len);
|
||||
static void
|
||||
directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
|
||||
uint8_t purpose, const char *payload, int payload_len);
|
||||
uint8_t purpose, const char *payload, size_t payload_len);
|
||||
|
||||
static void
|
||||
directory_initiate_command(const char *address, uint32_t addr, uint16_t port,
|
||||
const char *platform,
|
||||
const char *digest, uint8_t purpose,
|
||||
const char *payload, int payload_len);
|
||||
const char *payload, size_t payload_len);
|
||||
|
||||
static void
|
||||
directory_send_command(connection_t *conn, const char *platform,
|
||||
uint16_t dir_port, int purpose,
|
||||
const char *payload, int payload_len);
|
||||
const char *payload, size_t payload_len);
|
||||
static int directory_handle_command(connection_t *conn);
|
||||
|
||||
/********* START VARIABLES **********/
|
||||
@ -71,7 +71,7 @@ char rend_fetch_url[] = "/tor/rendezvous/";
|
||||
*/
|
||||
void
|
||||
directory_post_to_dirservers(uint8_t purpose, const char *payload,
|
||||
int payload_len)
|
||||
size_t payload_len)
|
||||
{
|
||||
int i;
|
||||
routerinfo_t *router;
|
||||
@ -97,7 +97,7 @@ directory_post_to_dirservers(uint8_t purpose, const char *payload,
|
||||
*/
|
||||
void
|
||||
directory_get_from_dirserver(uint8_t purpose, const char *payload,
|
||||
int payload_len)
|
||||
size_t payload_len)
|
||||
{
|
||||
routerinfo_t *r = NULL;
|
||||
trusted_dir_server_t *ds = NULL;
|
||||
@ -139,7 +139,7 @@ directory_get_from_dirserver(uint8_t purpose, const char *payload,
|
||||
*/
|
||||
static void
|
||||
directory_initiate_command_router(routerinfo_t *router, uint8_t purpose,
|
||||
const char *payload, int payload_len)
|
||||
const char *payload, size_t payload_len)
|
||||
{
|
||||
directory_initiate_command(router->address, router->addr, router->dir_port,
|
||||
router->platform, router->identity_digest,
|
||||
@ -148,7 +148,7 @@ directory_initiate_command_router(routerinfo_t *router, uint8_t purpose,
|
||||
|
||||
static void
|
||||
directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
|
||||
uint8_t purpose, const char *payload, int payload_len)
|
||||
uint8_t purpose, const char *payload, size_t payload_len)
|
||||
{
|
||||
directory_initiate_command(dirserv->address, dirserv->addr,dirserv->dir_port,
|
||||
NULL, dirserv->digest, purpose, payload, payload_len);
|
||||
@ -158,7 +158,7 @@ static void
|
||||
directory_initiate_command(const char *address, uint32_t addr,
|
||||
uint16_t dir_port, const char *platform,
|
||||
const char *digest, uint8_t purpose,
|
||||
const char *payload, int payload_len)
|
||||
const char *payload, size_t payload_len)
|
||||
{
|
||||
connection_t *conn;
|
||||
|
||||
@ -257,7 +257,7 @@ directory_initiate_command(const char *address, uint32_t addr,
|
||||
static void
|
||||
directory_send_command(connection_t *conn, const char *platform,
|
||||
uint16_t dir_port, int purpose,
|
||||
const char *payload, int payload_len) {
|
||||
const char *payload, size_t payload_len) {
|
||||
char tmp[8192];
|
||||
char proxystring[128];
|
||||
char hoststring[128];
|
||||
@ -466,7 +466,7 @@ connection_dir_client_reached_eof(connection_t *conn)
|
||||
{
|
||||
char *body;
|
||||
char *headers;
|
||||
int body_len=0;
|
||||
size_t body_len=0;
|
||||
int status_code;
|
||||
time_t now, date_header=0;
|
||||
int delta;
|
||||
@ -512,7 +512,7 @@ connection_dir_client_reached_eof(connection_t *conn)
|
||||
}
|
||||
tor_free(body);
|
||||
body = new_body;
|
||||
body_len = (int)new_len;
|
||||
body_len = new_len;
|
||||
}
|
||||
|
||||
if(conn->purpose == DIR_PURPOSE_FETCH_DIR) {
|
||||
@ -671,7 +671,7 @@ static char answer503[] = "HTTP/1.0 503 Directory unavailable\r\n\r\n";
|
||||
* Always return 0. */
|
||||
static int
|
||||
directory_handle_command_get(connection_t *conn, char *headers,
|
||||
char *body, int body_len)
|
||||
char *body, size_t body_len)
|
||||
{
|
||||
size_t dlen;
|
||||
const char *cp;
|
||||
@ -738,7 +738,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
|
||||
if(!strcmpstart(url,"/tor/rendezvous/")) {
|
||||
/* rendezvous descriptor fetch */
|
||||
const char *descp;
|
||||
int desc_len;
|
||||
size_t desc_len;
|
||||
|
||||
if(!authdir_mode()) {
|
||||
/* We don't hand out rend descs. In fact, it could be a security
|
||||
@ -755,7 +755,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
|
||||
format_rfc1123_time(date, time(NULL));
|
||||
snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n",
|
||||
date,
|
||||
desc_len); /* can't include descp here, because it's got nuls */
|
||||
(int)desc_len); /* can't include descp here, because it's got nuls */
|
||||
connection_write_to_buf(tmp, strlen(tmp), conn);
|
||||
connection_write_to_buf(descp, desc_len, conn);
|
||||
break;
|
||||
@ -783,7 +783,7 @@ directory_handle_command_get(connection_t *conn, char *headers,
|
||||
* 400. Always return 0. */
|
||||
static int
|
||||
directory_handle_command_post(connection_t *conn, char *headers,
|
||||
char *body, int body_len)
|
||||
char *body, size_t body_len)
|
||||
{
|
||||
const char *cp;
|
||||
char *url;
|
||||
@ -848,7 +848,7 @@ directory_handle_command_post(connection_t *conn, char *headers,
|
||||
*/
|
||||
static int directory_handle_command(connection_t *conn) {
|
||||
char *headers=NULL, *body=NULL;
|
||||
int body_len=0;
|
||||
size_t body_len=0;
|
||||
int r;
|
||||
|
||||
tor_assert(conn && conn->type == CONN_TYPE_DIR);
|
||||
@ -858,6 +858,7 @@ static int directory_handle_command(connection_t *conn) {
|
||||
&body, &body_len, MAX_BODY_SIZE)) {
|
||||
case -1: /* overflow */
|
||||
log_fn(LOG_WARN,"input too large. Failing.");
|
||||
/*XXX009 needs a better warn message */
|
||||
return -1;
|
||||
case 0:
|
||||
log_fn(LOG_DEBUG,"command not all here yet.");
|
||||
|
@ -468,7 +468,7 @@ list_running_servers(char **nicknames_out)
|
||||
connection_t *conn;
|
||||
char *cp;
|
||||
int i;
|
||||
int length;
|
||||
size_t length;
|
||||
smartlist_t *nicknames_up, *nicknames_down;
|
||||
char *name;
|
||||
const char *s;
|
||||
@ -554,7 +554,7 @@ dirserv_remove_old_servers(int age)
|
||||
* failure.
|
||||
*/
|
||||
int
|
||||
dirserv_dump_directory_to_string(char *s, unsigned int maxlen,
|
||||
dirserv_dump_directory_to_string(char *s, size_t maxlen,
|
||||
crypto_pk_env_t *private_key)
|
||||
{
|
||||
char *cp, *eos;
|
||||
|
@ -145,7 +145,7 @@ static void purge_expired_resolves(uint32_t now) {
|
||||
static void send_resolved_cell(connection_t *conn, uint8_t answer_type)
|
||||
{
|
||||
char buf[RELAY_PAYLOAD_SIZE];
|
||||
int buflen;
|
||||
size_t buflen;
|
||||
|
||||
buf[0] = answer_type;
|
||||
|
||||
|
@ -55,7 +55,6 @@ int onion_pending_add(circuit_t *circ) {
|
||||
ol_tail->next = tmp;
|
||||
ol_tail = tmp;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/** Remove the first item from ol_list and return it, or return
|
||||
@ -192,7 +191,7 @@ onion_skin_server_handshake(char *onion_skin, /* ONIONSKIN_CHALLENGE_LEN bytes *
|
||||
crypto_pk_env_t *prev_private_key,
|
||||
char *handshake_reply_out, /* ONIONSKIN_REPLY_LEN bytes */
|
||||
char *key_out,
|
||||
int key_out_len)
|
||||
size_t key_out_len)
|
||||
{
|
||||
char challenge[ONIONSKIN_CHALLENGE_LEN];
|
||||
crypto_dh_env_t *dh = NULL;
|
||||
@ -277,7 +276,7 @@ int
|
||||
onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
|
||||
char *handshake_reply, /* Must be ONIONSKIN_REPLY_LEN bytes */
|
||||
char *key_out,
|
||||
int key_out_len)
|
||||
size_t key_out_len)
|
||||
{
|
||||
int len;
|
||||
char *key_material=NULL;
|
||||
|
62
src/or/or.h
62
src/or/or.h
@ -913,7 +913,7 @@ typedef struct {
|
||||
struct socks_request_t {
|
||||
char socks_version; /**< Which version of SOCKS did the client use? */
|
||||
int command; /**< What has the user requested? One of CONNECT or RESOLVE. */
|
||||
int replylen; /**< Length of <b>reply</b>. */
|
||||
size_t replylen; /**< Length of <b>reply</b>. */
|
||||
char reply[MAX_SOCKS_REPLY_LEN]; /**< Write an entry into this string if
|
||||
* we want to specify our own socks reply,
|
||||
* rather than using the default socks4 or
|
||||
@ -941,14 +941,14 @@ const char *_buf_peek_raw_buffer(const buf_t *buf);
|
||||
int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof);
|
||||
int read_to_buf_tls(tor_tls *tls, size_t at_most, buf_t *buf);
|
||||
|
||||
int flush_buf(int s, buf_t *buf, int *buf_flushlen);
|
||||
int flush_buf_tls(tor_tls *tls, buf_t *buf, int *buf_flushlen);
|
||||
int flush_buf(int s, buf_t *buf, size_t *buf_flushlen);
|
||||
int flush_buf_tls(tor_tls *tls, buf_t *buf, size_t *buf_flushlen);
|
||||
|
||||
int write_to_buf(const char *string, int string_len, buf_t *buf);
|
||||
int write_to_buf(const char *string, size_t string_len, buf_t *buf);
|
||||
int fetch_from_buf(char *string, size_t string_len, buf_t *buf);
|
||||
int fetch_from_buf_http(buf_t *buf,
|
||||
char **headers_out, int max_headerlen,
|
||||
char **body_out, int *body_used, int max_bodylen);
|
||||
char **headers_out, size_t max_headerlen,
|
||||
char **body_out, size_t *body_used, size_t max_bodylen);
|
||||
int fetch_from_buf_socks(buf_t *buf, socks_request_t *req);
|
||||
|
||||
void assert_buf_ok(buf_t *buf);
|
||||
@ -1083,12 +1083,12 @@ void connection_bucket_refill(struct timeval *now);
|
||||
|
||||
int connection_handle_read(connection_t *conn);
|
||||
|
||||
int connection_fetch_from_buf(char *string, int len, connection_t *conn);
|
||||
int connection_fetch_from_buf(char *string, size_t len, connection_t *conn);
|
||||
|
||||
int connection_wants_to_flush(connection_t *conn);
|
||||
int connection_outbuf_too_full(connection_t *conn);
|
||||
int connection_handle_write(connection_t *conn);
|
||||
void connection_write_to_buf(const char *string, int len, connection_t *conn);
|
||||
void connection_write_to_buf(const char *string, size_t len, connection_t *conn);
|
||||
|
||||
connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
|
||||
connection_t *connection_get_by_identity_digest(const char *digest, int type);
|
||||
@ -1125,10 +1125,10 @@ int connection_ap_handshake_send_resolve(connection_t *ap_conn, circuit_t *circ)
|
||||
|
||||
int connection_ap_make_bridge(char *address, uint16_t port);
|
||||
void connection_ap_handshake_socks_reply(connection_t *conn, char *reply,
|
||||
int replylen, int success);
|
||||
size_t replylen, int success);
|
||||
void connection_ap_handshake_socks_resolved(connection_t *conn,
|
||||
int answer_type,
|
||||
int answer_len,
|
||||
size_t answer_len,
|
||||
const char *answer);
|
||||
|
||||
int connection_exit_begin_conn(cell_t *cell, circuit_t *circ);
|
||||
@ -1175,9 +1175,9 @@ int assign_to_cpuworker(connection_t *cpuworker, unsigned char question_type,
|
||||
/********************************* directory.c ***************************/
|
||||
|
||||
void directory_post_to_dirservers(uint8_t purpose, const char *payload,
|
||||
int payload_len);
|
||||
size_t payload_len);
|
||||
void directory_get_from_dirserver(uint8_t purpose, const char *payload,
|
||||
int payload_len);
|
||||
size_t payload_len);
|
||||
int connection_dir_process_inbuf(connection_t *conn);
|
||||
int connection_dir_finished_flushing(connection_t *conn);
|
||||
int connection_dir_finished_connecting(connection_t *conn);
|
||||
@ -1254,12 +1254,12 @@ int onion_skin_server_handshake(char *onion_skin,
|
||||
crypto_pk_env_t *prev_private_key,
|
||||
char *handshake_reply_out,
|
||||
char *key_out,
|
||||
int key_out_len);
|
||||
size_t key_out_len);
|
||||
|
||||
int onion_skin_client_handshake(crypto_dh_env_t *handshake_state,
|
||||
char *handshake_reply,
|
||||
char *key_out,
|
||||
int key_out_len);
|
||||
size_t key_out_len);
|
||||
|
||||
/********************************* relay.c ***************************/
|
||||
|
||||
@ -1273,7 +1273,7 @@ void relay_header_pack(char *dest, const relay_header_t *src);
|
||||
void relay_header_unpack(relay_header_t *dest, const char *src);
|
||||
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
|
||||
int relay_command, const char *payload,
|
||||
int payload_len, crypt_path_t *cpath_layer);
|
||||
size_t payload_len, crypt_path_t *cpath_layer);
|
||||
int connection_edge_package_raw_inbuf(connection_t *conn);
|
||||
void connection_edge_consider_sending_sendme(connection_t *conn);
|
||||
|
||||
@ -1302,11 +1302,11 @@ char *rep_hist_get_bandwidth_lines(void);
|
||||
|
||||
void rend_client_introcirc_has_opened(circuit_t *circ);
|
||||
void rend_client_rendcirc_has_opened(circuit_t *circ);
|
||||
int rend_client_introduction_acked(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_client_introduction_acked(circuit_t *circ, const char *request, size_t request_len);
|
||||
void rend_client_refetch_renddesc(const char *query);
|
||||
int rend_client_remove_intro_point(char *failed_intro, const char *query);
|
||||
int rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t request_len);
|
||||
int rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t request_len);
|
||||
void rend_client_desc_fetched(char *query, int success);
|
||||
|
||||
char *rend_client_get_random_intro(char *query);
|
||||
@ -1325,19 +1325,19 @@ typedef struct rend_service_descriptor_t {
|
||||
|
||||
int rend_cmp_service_ids(const char *one, const char *two);
|
||||
|
||||
void rend_process_relay_cell(circuit_t *circ, int command, int length,
|
||||
void rend_process_relay_cell(circuit_t *circ, int command, size_t length,
|
||||
const char *payload);
|
||||
|
||||
void rend_service_descriptor_free(rend_service_descriptor_t *desc);
|
||||
int rend_encode_service_descriptor(rend_service_descriptor_t *desc,
|
||||
crypto_pk_env_t *key,
|
||||
char **str_out,
|
||||
int *len_out);
|
||||
rend_service_descriptor_t *rend_parse_service_descriptor(const char *str, int len);
|
||||
size_t *len_out);
|
||||
rend_service_descriptor_t *rend_parse_service_descriptor(const char *str, size_t len);
|
||||
int rend_get_service_id(crypto_pk_env_t *pk, char *out);
|
||||
|
||||
typedef struct rend_cache_entry_t {
|
||||
int len; /* Length of desc */
|
||||
size_t len; /* Length of desc */
|
||||
time_t received; /* When did we get the descriptor? */
|
||||
char *desc; /* Service descriptor */
|
||||
rend_service_descriptor_t *parsed; /* Parsed value of 'desc' */
|
||||
@ -1346,9 +1346,9 @@ typedef struct rend_cache_entry_t {
|
||||
void rend_cache_init(void);
|
||||
void rend_cache_clean(void);
|
||||
int rend_valid_service_id(const char *query);
|
||||
int rend_cache_lookup_desc(const char *query, const char **desc, int *desc_len);
|
||||
int rend_cache_lookup_desc(const char *query, const char **desc, size_t *desc_len);
|
||||
int rend_cache_lookup_entry(const char *query, rend_cache_entry_t **entry_out);
|
||||
int rend_cache_store(const char *desc, int desc_len);
|
||||
int rend_cache_store(const char *desc, size_t desc_len);
|
||||
|
||||
/********************************* rendservice.c ***************************/
|
||||
|
||||
@ -1359,18 +1359,18 @@ void rend_services_introduce(void);
|
||||
void rend_services_upload(int force);
|
||||
|
||||
void rend_service_intro_has_opened(circuit_t *circuit);
|
||||
int rend_service_intro_established(circuit_t *circuit, const char *request, int request_len);
|
||||
int rend_service_intro_established(circuit_t *circuit, const char *request, size_t request_len);
|
||||
void rend_service_rendezvous_has_opened(circuit_t *circuit);
|
||||
int rend_service_introduce(circuit_t *circuit, const char *request, int request_len);
|
||||
int rend_service_introduce(circuit_t *circuit, const char *request, size_t request_len);
|
||||
void rend_service_relaunch_rendezvous(circuit_t *oldcirc);
|
||||
int rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ);
|
||||
void rend_service_dump_stats(int severity);
|
||||
|
||||
/********************************* rendmid.c *******************************/
|
||||
int rend_mid_establish_intro(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_mid_introduce(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_mid_establish_rendezvous(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_mid_rendezvous(circuit_t *circ, const char *request, int request_len);
|
||||
int rend_mid_establish_intro(circuit_t *circ, const char *request, size_t request_len);
|
||||
int rend_mid_introduce(circuit_t *circ, const char *request, size_t request_len);
|
||||
int rend_mid_establish_rendezvous(circuit_t *circ, const char *request, size_t request_len);
|
||||
int rend_mid_rendezvous(circuit_t *circ, const char *request, size_t request_len);
|
||||
|
||||
/********************************* router.c ***************************/
|
||||
|
||||
@ -1395,7 +1395,7 @@ routerinfo_t *router_get_my_routerinfo(void);
|
||||
const char *router_get_my_descriptor(void);
|
||||
int router_is_me(routerinfo_t *router);
|
||||
int router_rebuild_descriptor(void);
|
||||
int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
|
||||
crypto_pk_env_t *ident_key);
|
||||
int is_legal_nickname(const char *s);
|
||||
int is_legal_nickname_or_hexdigest(const char *s);
|
||||
|
@ -404,7 +404,7 @@ void relay_header_unpack(relay_header_t *dest, const char *src) {
|
||||
*/
|
||||
int connection_edge_send_command(connection_t *fromconn, circuit_t *circ,
|
||||
int relay_command, const char *payload,
|
||||
int payload_len, crypt_path_t *cpath_layer) {
|
||||
size_t payload_len, crypt_path_t *cpath_layer) {
|
||||
cell_t cell;
|
||||
relay_header_t rh;
|
||||
int cell_direction;
|
||||
@ -853,7 +853,7 @@ uint64_t stats_n_data_bytes_received = 0;
|
||||
* Return -1 if conn should be marked for close, else return 0.
|
||||
*/
|
||||
int connection_edge_package_raw_inbuf(connection_t *conn) {
|
||||
int amount_to_process, length;
|
||||
size_t amount_to_process, length;
|
||||
char payload[CELL_PAYLOAD_SIZE];
|
||||
circuit_t *circ;
|
||||
|
||||
|
@ -52,7 +52,8 @@ rend_client_send_establish_rendezvous(circuit_t *circ)
|
||||
*/
|
||||
int
|
||||
rend_client_send_introduction(circuit_t *introcirc, circuit_t *rendcirc) {
|
||||
int payload_len, r;
|
||||
size_t payload_len;
|
||||
int r;
|
||||
char payload[RELAY_PAYLOAD_SIZE];
|
||||
char tmp[(MAX_NICKNAME_LEN+1)+REND_COOKIE_LEN+DH_KEY_LEN];
|
||||
rend_cache_entry_t *entry;
|
||||
@ -152,7 +153,7 @@ rend_client_rendcirc_has_opened(circuit_t *circ)
|
||||
*/
|
||||
int
|
||||
rend_client_introduction_acked(circuit_t *circ,
|
||||
const char *request, int request_len)
|
||||
const char *request, size_t request_len)
|
||||
{
|
||||
char *nickname;
|
||||
circuit_t *rendcirc;
|
||||
@ -280,7 +281,7 @@ rend_client_remove_intro_point(char *failed_intro, const char *query)
|
||||
* the circuit to C_REND_READY.
|
||||
*/
|
||||
int
|
||||
rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_len)
|
||||
rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t request_len)
|
||||
{
|
||||
/* we just got an ack for our establish-rendezvous. switch purposes. */
|
||||
if(circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
|
||||
@ -295,7 +296,7 @@ rend_client_rendezvous_acked(circuit_t *circ, const char *request, int request_l
|
||||
|
||||
/** Bob sent us a rendezvous cell; join the circuits. */
|
||||
int
|
||||
rend_client_receive_rendezvous(circuit_t *circ, const char *request, int request_len)
|
||||
rend_client_receive_rendezvous(circuit_t *circ, const char *request, size_t request_len)
|
||||
{
|
||||
crypt_path_t *hop;
|
||||
char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN];
|
||||
|
@ -39,17 +39,19 @@ void rend_service_descriptor_free(rend_service_descriptor_t *desc)
|
||||
int
|
||||
rend_encode_service_descriptor(rend_service_descriptor_t *desc,
|
||||
crypto_pk_env_t *key,
|
||||
char **str_out, int *len_out)
|
||||
char **str_out, size_t *len_out)
|
||||
{
|
||||
char *buf, *cp, *ipoint;
|
||||
int i, keylen, asn1len;
|
||||
int i;
|
||||
size_t keylen, asn1len;
|
||||
keylen = crypto_pk_keysize(desc->pk);
|
||||
buf = tor_malloc(keylen*2); /* Too long, but that's okay. */
|
||||
asn1len = crypto_pk_asn1_encode(desc->pk, buf, keylen*2);
|
||||
if (asn1len<0) {
|
||||
i = crypto_pk_asn1_encode(desc->pk, buf, keylen*2);
|
||||
if (i<0) {
|
||||
tor_free(buf);
|
||||
return -1;
|
||||
}
|
||||
asn1len = i;
|
||||
*len_out = 2 + asn1len + 4 + 2 + keylen;
|
||||
for (i = 0; i < desc->n_intro_points; ++i) {
|
||||
*len_out += strlen(desc->intro_points[i]) + 1;
|
||||
@ -75,7 +77,7 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc,
|
||||
return -1;
|
||||
}
|
||||
cp += i;
|
||||
tor_assert(*len_out == (cp-*str_out));
|
||||
tor_assert(*len_out == (size_t)(cp-*str_out));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -84,10 +86,11 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc,
|
||||
* return NULL.
|
||||
*/
|
||||
rend_service_descriptor_t *rend_parse_service_descriptor(
|
||||
const char *str, int len)
|
||||
const char *str, size_t len)
|
||||
{
|
||||
rend_service_descriptor_t *result = NULL;
|
||||
int keylen, asn1len, i;
|
||||
int i;
|
||||
size_t keylen, asn1len;
|
||||
const char *end, *cp, *eos;
|
||||
|
||||
result = tor_malloc_zero(sizeof(rend_service_descriptor_t));
|
||||
@ -96,7 +99,7 @@ rend_service_descriptor_t *rend_parse_service_descriptor(
|
||||
if (end-cp < 2) goto truncated;
|
||||
asn1len = ntohs(get_uint16(cp));
|
||||
cp += 2;
|
||||
if (end-cp < asn1len) goto truncated;
|
||||
if ((size_t)(end-cp) < asn1len) goto truncated;
|
||||
result->pk = crypto_pk_asn1_decode(cp, asn1len);
|
||||
if (!result->pk) goto truncated;
|
||||
cp += asn1len;
|
||||
@ -115,8 +118,9 @@ rend_service_descriptor_t *rend_parse_service_descriptor(
|
||||
cp = eos+1;
|
||||
}
|
||||
keylen = crypto_pk_keysize(result->pk);
|
||||
if (end-cp < keylen) goto truncated;
|
||||
if (end-cp > keylen) {
|
||||
tor_assert(end-cp >= 0);
|
||||
if ((size_t)(end-cp) < keylen) goto truncated;
|
||||
if ((size_t)(end-cp) > keylen) {
|
||||
log_fn(LOG_WARN, "Signature too long on service descriptor");
|
||||
goto error;
|
||||
}
|
||||
@ -224,7 +228,7 @@ int rend_cache_lookup_entry(const char *query, rend_cache_entry_t **e)
|
||||
* Note: calls to rend_cache_clean or rend_cache_store may invalidate
|
||||
* *desc.
|
||||
*/
|
||||
int rend_cache_lookup_desc(const char *query, const char **desc, int *desc_len)
|
||||
int rend_cache_lookup_desc(const char *query, const char **desc, size_t *desc_len)
|
||||
{
|
||||
rend_cache_entry_t *e;
|
||||
int r;
|
||||
@ -240,7 +244,7 @@ int rend_cache_lookup_desc(const char *query, const char **desc, int *desc_len)
|
||||
* If we have an older descriptor with the same ID, replace it.
|
||||
* Returns -1 if it's malformed or otherwise rejected, else return 0.
|
||||
*/
|
||||
int rend_cache_store(const char *desc, int desc_len)
|
||||
int rend_cache_store(const char *desc, size_t desc_len)
|
||||
{
|
||||
rend_cache_entry_t *e;
|
||||
rend_service_descriptor_t *parsed;
|
||||
@ -299,7 +303,7 @@ int rend_cache_store(const char *desc, int desc_len)
|
||||
|
||||
/** Called when we get a rendezvous-related relay cell on circuit
|
||||
* <b>circ</b>. Dispatch on rendezvous relay command. */
|
||||
void rend_process_relay_cell(circuit_t *circ, int command, int length,
|
||||
void rend_process_relay_cell(circuit_t *circ, int command, size_t length,
|
||||
const char *payload)
|
||||
{
|
||||
int r;
|
||||
|
@ -13,13 +13,13 @@
|
||||
* setting the circuit's purpose and service pk digest.
|
||||
*/
|
||||
int
|
||||
rend_mid_establish_intro(circuit_t *circ, const char *request, int request_len)
|
||||
rend_mid_establish_intro(circuit_t *circ, const char *request, size_t request_len)
|
||||
{
|
||||
crypto_pk_env_t *pk = NULL;
|
||||
char buf[DIGEST_LEN+9];
|
||||
char expected_digest[DIGEST_LEN];
|
||||
char pk_digest[DIGEST_LEN];
|
||||
int asn1len;
|
||||
size_t asn1len;
|
||||
circuit_t *c;
|
||||
char serviceid[REND_SERVICE_ID_LEN+1];
|
||||
|
||||
@ -110,7 +110,7 @@ rend_mid_establish_intro(circuit_t *circ, const char *request, int request_len)
|
||||
* INTRODUCE2 cell.
|
||||
*/
|
||||
int
|
||||
rend_mid_introduce(circuit_t *circ, const char *request, int request_len)
|
||||
rend_mid_introduce(circuit_t *circ, const char *request, size_t request_len)
|
||||
{
|
||||
circuit_t *intro_circ;
|
||||
char serviceid[REND_SERVICE_ID_LEN+1];
|
||||
@ -177,7 +177,7 @@ rend_mid_introduce(circuit_t *circ, const char *request, int request_len)
|
||||
* rendezvous cookie.
|
||||
*/
|
||||
int
|
||||
rend_mid_establish_rendezvous(circuit_t *circ, const char *request, int request_len)
|
||||
rend_mid_establish_rendezvous(circuit_t *circ, const char *request, size_t request_len)
|
||||
{
|
||||
char hexid[9];
|
||||
|
||||
@ -224,7 +224,7 @@ rend_mid_establish_rendezvous(circuit_t *circ, const char *request, int request_
|
||||
* connecting the two circuits.
|
||||
*/
|
||||
int
|
||||
rend_mid_rendezvous(circuit_t *circ, const char *request, int request_len)
|
||||
rend_mid_rendezvous(circuit_t *circ, const char *request, size_t request_len)
|
||||
{
|
||||
circuit_t *rend_circ;
|
||||
char hexid[9];
|
||||
|
@ -335,20 +335,21 @@ rend_service_get_by_pk_digest(const char* digest)
|
||||
* rendezvous points.
|
||||
*/
|
||||
int
|
||||
rend_service_introduce(circuit_t *circuit, const char *request, int request_len)
|
||||
rend_service_introduce(circuit_t *circuit, const char *request, size_t request_len)
|
||||
{
|
||||
char *ptr, *rp_nickname, *r_cookie;
|
||||
char buf[RELAY_PAYLOAD_SIZE];
|
||||
char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN]; /* Holds KH, Df, Db, Kf, Kb */
|
||||
rend_service_t *service;
|
||||
int len, keylen;
|
||||
int r;
|
||||
size_t len, keylen;
|
||||
crypto_dh_env_t *dh = NULL;
|
||||
circuit_t *launched = NULL;
|
||||
crypt_path_t *cpath = NULL;
|
||||
char serviceid[REND_SERVICE_ID_LEN+1];
|
||||
char hexcookie[9];
|
||||
int version;
|
||||
int nickname_field_len;
|
||||
size_t nickname_field_len;
|
||||
|
||||
base32_encode(serviceid, REND_SERVICE_ID_LEN+1,
|
||||
circuit->rend_pk_digest,10);
|
||||
@ -389,13 +390,14 @@ rend_service_introduce(circuit_t *circuit, const char *request, int request_len)
|
||||
return -1;
|
||||
}
|
||||
/* Next N bytes is encrypted with service key */
|
||||
len = crypto_pk_private_hybrid_decrypt(
|
||||
r = crypto_pk_private_hybrid_decrypt(
|
||||
service->private_key,request+DIGEST_LEN,request_len-DIGEST_LEN,buf,
|
||||
PK_PKCS1_OAEP_PADDING,1);
|
||||
if (len<0) {
|
||||
if (r<0) {
|
||||
log_fn(LOG_WARN, "Couldn't decrypt INTRODUCE2 cell");
|
||||
return -1;
|
||||
}
|
||||
len = r;
|
||||
if (*buf == 1) {
|
||||
rp_nickname = buf+1;
|
||||
nickname_field_len = HEX_DIGEST_LEN+2;
|
||||
@ -420,7 +422,7 @@ rend_service_introduce(circuit_t *circuit, const char *request, int request_len)
|
||||
ptr = rp_nickname+nickname_field_len;
|
||||
len -= nickname_field_len;
|
||||
if (len != REND_COOKIE_LEN+DH_KEY_LEN) {
|
||||
log_fn(LOG_WARN, "Bad length for INTRODUCE2 cell.");
|
||||
log_fn(LOG_WARN, "Bad length %u for INTRODUCE2 cell.", len);
|
||||
return -1;
|
||||
}
|
||||
r_cookie = ptr;
|
||||
@ -547,7 +549,8 @@ void
|
||||
rend_service_intro_has_opened(circuit_t *circuit)
|
||||
{
|
||||
rend_service_t *service;
|
||||
int len, r;
|
||||
size_t len;
|
||||
int r;
|
||||
char buf[RELAY_PAYLOAD_SIZE];
|
||||
char auth[DIGEST_LEN + 9];
|
||||
char serviceid[REND_SERVICE_ID_LEN+1];
|
||||
@ -603,7 +606,7 @@ rend_service_intro_has_opened(circuit_t *circuit)
|
||||
* live introduction point, and note that the service descriptor is
|
||||
* now out-of-date.*/
|
||||
int
|
||||
rend_service_intro_established(circuit_t *circuit, const char *request, int request_len)
|
||||
rend_service_intro_established(circuit_t *circuit, const char *request, size_t request_len)
|
||||
{
|
||||
rend_service_t *service;
|
||||
|
||||
@ -741,7 +744,7 @@ static void
|
||||
upload_service_descriptor(rend_service_t *service)
|
||||
{
|
||||
char *desc;
|
||||
int desc_len;
|
||||
size_t desc_len;
|
||||
if (!service->desc_is_dirty)
|
||||
return;
|
||||
|
||||
|
@ -236,7 +236,7 @@ void rep_hist_dump_stats(time_t now, int severity)
|
||||
void *or_history_p, *link_history_p;
|
||||
double uptime;
|
||||
char buffer[2048];
|
||||
int len;
|
||||
size_t len;
|
||||
unsigned long upt, downt;
|
||||
routerinfo_t *r;
|
||||
|
||||
@ -279,6 +279,7 @@ void rep_hist_dump_stats(time_t now, int severity)
|
||||
name2 = "(unknown)";
|
||||
|
||||
link_history = (link_history_t*) link_history_p;
|
||||
/* XXX009 snprintf can return -1 for error also. need to detect. */
|
||||
len += snprintf(buffer+len, 2048-len, "%s(%ld/%ld); ", name2,
|
||||
link_history->n_extend_ok,
|
||||
link_history->n_extend_ok+link_history->n_extend_fail);
|
||||
|
@ -13,7 +13,7 @@
|
||||
extern or_options_t options; /* command-line and config-file options */
|
||||
extern long stats_n_seconds_uptime;
|
||||
|
||||
/** Exposed for test.c. */ void get_platform_str(char *platform, int len);
|
||||
/** Exposed for test.c. */ void get_platform_str(char *platform, size_t len);
|
||||
|
||||
/************************************************************/
|
||||
|
||||
@ -571,7 +571,7 @@ int router_rebuild_descriptor(void) {
|
||||
* string describing the version of Tor and the operating system we're
|
||||
* currently running on.
|
||||
*/
|
||||
void get_platform_str(char *platform, int len)
|
||||
void get_platform_str(char *platform, size_t len)
|
||||
{
|
||||
snprintf(platform, len-1, "Tor %s on %s",
|
||||
VERSION, get_uname());
|
||||
@ -590,7 +590,7 @@ void get_platform_str(char *platform, int len)
|
||||
* result into <b>s</b>, using at most <b>maxlen</b> bytes. Return -1 on
|
||||
* failure, and the number of bytes used on success.
|
||||
*/
|
||||
int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
|
||||
crypto_pk_env_t *ident_key) {
|
||||
char *onion_pkey; /* Onion key, PEM-encoded. */
|
||||
char *identity_pkey; /* Identity key, PEM-encoded. */
|
||||
@ -599,8 +599,8 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
char published[32];
|
||||
char fingerprint[FINGERPRINT_LEN+1];
|
||||
struct in_addr in;
|
||||
int onion_pkeylen, identity_pkeylen;
|
||||
int written;
|
||||
size_t onion_pkeylen, identity_pkeylen;
|
||||
size_t written;
|
||||
int result=0;
|
||||
struct exit_policy_t *tmpe;
|
||||
char *bandwidth_usage;
|
||||
@ -675,7 +675,7 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
tor_free(identity_pkey);
|
||||
tor_free(bandwidth_usage);
|
||||
|
||||
if(result < 0 || result >= maxlen) {
|
||||
if(result < 0 || (size_t)result >= maxlen) {
|
||||
/* apparently different glibcs do different things on snprintf error.. so check both */
|
||||
return -1;
|
||||
}
|
||||
|
@ -1067,7 +1067,7 @@ int router_update_status_from_smartlist(routerinfo_t *router,
|
||||
const char *name;
|
||||
#if 1
|
||||
char *cp;
|
||||
int n;
|
||||
size_t n;
|
||||
n = 0;
|
||||
for (i=0; i<smartlist_len(running_list); ++i) {
|
||||
name = smartlist_get(running_list, i);
|
||||
|
@ -59,7 +59,7 @@ typedef struct directory_token_t {
|
||||
int n_args; /**< Number of elements in args */
|
||||
char **args; /**< Array of arguments from keyword line. */
|
||||
char *object_type; /**< -----BEGIN [object_type]-----*/
|
||||
int object_size; /**< Bytes in object_body */
|
||||
size_t object_size; /**< Bytes in object_body */
|
||||
char *object_body; /**< Contents of object, base64-decoded. */
|
||||
crypto_pk_env_t *key; /**< For public keys only. */
|
||||
char *error; /**< For _ERR tokens only. */
|
||||
@ -173,7 +173,7 @@ get_recommended_software_from_directory(const char *str)
|
||||
{
|
||||
#define REC "recommended-software "
|
||||
const char *cp = str, *eol;
|
||||
int len = strlen(REC);
|
||||
size_t len = strlen(REC);
|
||||
cp = str;
|
||||
if (strcmpstart(str, REC)==0) {
|
||||
cp += len;
|
||||
@ -612,7 +612,6 @@ static int check_directory_signature(const char *digest,
|
||||
routerinfo_t *r;
|
||||
crypto_pk_env_t *_pkey = NULL;
|
||||
|
||||
|
||||
if (tok->n_args != 1) {
|
||||
log_fn(LOG_WARN, "Too many or too few arguments to directory-signature");
|
||||
return -1;
|
||||
@ -661,7 +660,6 @@ static int check_directory_signature(const char *digest,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/** Given a string *<b>s</b> containing a concatenated sequence of router
|
||||
* descriptors, parses them and stores the result in *<b>dest</b>. If
|
||||
* good_nickname_list is provided, then routers are marked as
|
||||
@ -941,7 +939,8 @@ router_parse_exit_policy_from_string(const char *s)
|
||||
const char *cp;
|
||||
char *tmp;
|
||||
struct exit_policy_t *r;
|
||||
int len, idx;
|
||||
size_t len;
|
||||
int idx;
|
||||
|
||||
/* *s might not end with \n, so we need to extend it with one. */
|
||||
len = strlen(s);
|
||||
@ -1122,7 +1121,6 @@ policy_read_failed:
|
||||
* Low-level tokenizer for router descriptors and directories.
|
||||
*/
|
||||
|
||||
|
||||
/** Free all resources allocated for <b>tok</b> */
|
||||
static void
|
||||
token_free(directory_token_t *tok)
|
||||
|
@ -22,14 +22,15 @@ int have_failed = 0;
|
||||
|
||||
/* These functions are file-local, but are exposed so we can test. */
|
||||
void add_fingerprint_to_dir(const char *nickname, const char *fp);
|
||||
void get_platform_str(char *platform, int len);
|
||||
void get_platform_str(char *platform, size_t len);
|
||||
|
||||
void
|
||||
dump_hex(char *s, int len)
|
||||
dump_hex(char *s, size_t len)
|
||||
{
|
||||
static const char TABLE[] = "0123456789ABCDEF";
|
||||
unsigned char *d = s;
|
||||
int i, j, nyb;
|
||||
size_t i;
|
||||
int j, nyb;
|
||||
for(i=0;i<len;++i) {
|
||||
for (j=1;j>=0;--j) {
|
||||
nyb = (((int) d[i]) >> (j*4)) & 0x0f;
|
||||
@ -263,6 +264,7 @@ test_crypto()
|
||||
crypto_pk_env_t *pk1, *pk2;
|
||||
char *data1, *data2, *data3, *cp;
|
||||
int i, j, p, len;
|
||||
int size;
|
||||
|
||||
data1 = tor_malloc(1024);
|
||||
data2 = tor_malloc(1024);
|
||||
@ -362,8 +364,8 @@ test_crypto()
|
||||
pk2 = crypto_new_pk_env();
|
||||
test_assert(pk1 && pk2);
|
||||
test_assert(! crypto_pk_generate_key(pk1));
|
||||
test_assert(! crypto_pk_write_public_key_to_string(pk1, &cp, &i));
|
||||
test_assert(! crypto_pk_read_public_key_from_string(pk2, cp, i));
|
||||
test_assert(! crypto_pk_write_public_key_to_string(pk1, &cp, &size));
|
||||
test_assert(! crypto_pk_read_public_key_from_string(pk2, cp, size));
|
||||
test_eq(0, crypto_pk_cmp_keys(pk1, pk2));
|
||||
tor_free(cp);
|
||||
|
||||
@ -860,7 +862,7 @@ test_dir_format()
|
||||
char platform[256];
|
||||
char fingerprint[FINGERPRINT_LEN+1];
|
||||
char *pk1_str = NULL, *pk2_str = NULL, *pk3_str = NULL, *cp;
|
||||
int pk1_str_len, pk2_str_len, pk3_str_len;
|
||||
size_t pk1_str_len, pk2_str_len, pk3_str_len;
|
||||
routerinfo_t r1, r2;
|
||||
crypto_pk_env_t *pk1 = NULL, *pk2 = NULL, *pk3 = NULL;
|
||||
routerinfo_t *rp1 = NULL, *rp2 = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user