projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix potential crash during failing PMTU discovery.
[tinc]
/
src
/
tincctl.c
diff --git
a/src/tincctl.c
b/src/tincctl.c
index
14faf64
..
b6c4fc8
100644
(file)
--- a/
src/tincctl.c
+++ b/
src/tincctl.c
@@
-48,7
+48,6
@@
#endif
static char **orig_argv;
#endif
static char **orig_argv;
-static int orig_argc;
/* If nonzero, display usage information and exit. */
static bool show_help = false;
/* If nonzero, display usage information and exit. */
static bool show_help = false;
@@
-72,7
+71,6
@@
static int result;
bool force = false;
bool tty = true;
bool confbasegiven = false;
bool force = false;
bool tty = true;
bool confbasegiven = false;
-bool netnamegiven = false;
char *scriptinterpreter = NULL;
char *scriptextension = "";
static char *prompt;
char *scriptinterpreter = NULL;
char *scriptextension = "";
static char *prompt;
@@
-465,15
+463,15
@@
bool recvline(int fd, char *line, size_t len) {
}
while(!(newline = memchr(buffer, '\n', blen))) {
}
while(!(newline = memchr(buffer, '\n', blen))) {
-
int result
= recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
+
ssize_t nrecv
= recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
- if(
result
== -1 && sockerrno == EINTR) {
+ if(
nrecv
== -1 && sockerrno == EINTR) {
continue;
continue;
- } else if(
result
<= 0) {
+ } else if(
nrecv
<= 0) {
return false;
}
return false;
}
- blen +=
result
;
+ blen +=
nrecv
;
}
if((size_t)(newline - buffer) >= len) {
}
if((size_t)(newline - buffer) >= len) {
@@
-492,15
+490,15
@@
bool recvline(int fd, char *line, size_t len) {
static bool recvdata(int fd, char *data, size_t len) {
while(blen < len) {
static bool recvdata(int fd, char *data, size_t len) {
while(blen < len) {
-
int result
= recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
+
ssize_t nrecv
= recv(fd, buffer + blen, sizeof(buffer) - blen, 0);
- if(
result
== -1 && sockerrno == EINTR) {
+ if(
nrecv
== -1 && sockerrno == EINTR) {
continue;
continue;
- } else if(
result
<= 0) {
+ } else if(
nrecv
<= 0) {
return false;
}
return false;
}
- blen +=
result
;
+ blen +=
nrecv
;
}
memcpy(data, buffer, len);
}
memcpy(data, buffer, len);
@@
-513,7
+511,7
@@
static bool recvdata(int fd, char *data, size_t len) {
bool sendline(int fd, char *format, ...) {
static char buffer[4096];
char *p = buffer;
bool sendline(int fd, char *format, ...) {
static char buffer[4096];
char *p = buffer;
-
in
t blen;
+
ssize_
t blen;
va_list ap;
va_start(ap, format);
va_list ap;
va_start(ap, format);
@@
-529,16
+527,16
@@
bool sendline(int fd, char *format, ...) {
blen++;
while(blen) {
blen++;
while(blen) {
-
int result
= send(fd, p, blen, MSG_NOSIGNAL);
+
ssize_t nsend
= send(fd, p, blen, MSG_NOSIGNAL);
- if(
result
== -1 && sockerrno == EINTR) {
+ if(
nsend
== -1 && sockerrno == EINTR) {
continue;
continue;
- } else if(
result
<= 0) {
+ } else if(
nsend
<= 0) {
return false;
}
return false;
}
- p +=
result
;
- blen -=
result
;
+ p +=
nsend
;
+ blen -=
nsend
;
}
return true;
}
return true;
@@
-579,11
+577,12
@@
static void pcap(int fd, FILE *out, uint32_t snaplen) {
char line[32];
while(recvline(fd, line, sizeof(line))) {
char line[32];
while(recvline(fd, line, sizeof(line))) {
- int code, req, len;
- int n = sscanf(line, "%d %d %d", &code, &req, &len);
+ int code, req;
+ size_t len;
+ int n = sscanf(line, "%d %d %zd", &code, &req, &len);
gettimeofday(&tv, NULL);
gettimeofday(&tv, NULL);
- if(n != 3 || code != CONTROL || req != REQ_PCAP || len
< 0 || (size_t)len
> sizeof(data)) {
+ if(n != 3 || code != CONTROL || req != REQ_PCAP || len > sizeof(data)) {
break;
}
break;
}
@@
-972,7
+971,6
@@
static int cmd_start(int argc, char *argv[]) {
free(nargv);
free(nargv);
- int status = -1, result;
#ifdef SIGINT
signal(SIGINT, SIG_IGN);
#endif
#ifdef SIGINT
signal(SIGINT, SIG_IGN);
#endif
@@
-980,7
+978,7
@@
static int cmd_start(int argc, char *argv[]) {
// Pass all log messages from the umbilical to stderr.
// A nul-byte right before closure means tincd started successfully.
bool failure = true;
// Pass all log messages from the umbilical to stderr.
// A nul-byte right before closure means tincd started successfully.
bool failure = true;
-
char
buf[1024];
+
uint8_t
buf[1024];
ssize_t len;
while((len = read(pfd[0], buf, sizeof(buf))) > 0) {
ssize_t len;
while((len = read(pfd[0], buf, sizeof(buf))) > 0) {
@@
-1000,7
+998,8
@@
static int cmd_start(int argc, char *argv[]) {
close(pfd[0]);
// Make sure the child process is really gone.
close(pfd[0]);
// Make sure the child process is really gone.
- result = waitpid(pid, &status, 0);
+ int status = -1;
+ pid_t result = waitpid(pid, &status, 0);
#ifdef SIGINT
signal(SIGINT, SIG_DFL);
#ifdef SIGINT
signal(SIGINT, SIG_DFL);
@@
-1101,7
+1100,7
@@
static int dump_invitations(void) {
while((ent = readdir(dir))) {
char buf[MAX_STRING_SIZE];
while((ent = readdir(dir))) {
char buf[MAX_STRING_SIZE];
- if(b64decode(ent->d_name, buf, 24) != 18) {
+ if(b64decode
_tinc
(ent->d_name, buf, 24) != 18) {
continue;
}
continue;
}
@@
-1304,7
+1303,7
@@
static int cmd_dump(int argc, char *argv[]) {
}
if(do_graph) {
}
if(do_graph) {
- float w = 1
+ 65536.0 /
weight;
+ float w = 1
.0f + 65536.0f / (float)
weight;
if(do_graph == 1 && strcmp(node1, node2) > 0) {
printf(" \"%s\" -- \"%s\" [w = %f, weight = %f];\n", node1, node2, w, w);
if(do_graph == 1 && strcmp(node1, node2) > 0) {
printf(" \"%s\" -- \"%s\" [w = %f, weight = %f];\n", node1, node2, w, w);
@@
-1555,8
+1554,8
@@
static int cmd_pid(int argc, char *argv[]) {
return 0;
}
return 0;
}
-
in
t rstrip(char *value) {
-
in
t len = strlen(value);
+
size_
t rstrip(char *value) {
+
size_
t len = strlen(value);
while(len && strchr("\t\r\n ", value[len - 1])) {
value[--len] = 0;
while(len && strchr("\t\r\n ", value[len - 1])) {
value[--len] = 0;
@@
-1580,7
+1579,7
@@
char *get_my_name(bool verbose) {
char *value;
while(fgets(buf, sizeof(buf), f)) {
char *value;
while(fgets(buf, sizeof(buf), f)) {
-
in
t len = strcspn(buf, "\t =");
+
size_
t len = strcspn(buf, "\t =");
value = buf + len;
value += strspn(value, "\t ");
value = buf + len;
value += strspn(value, "\t ");
@@
-1619,7
+1618,7
@@
ecdsa_t *get_pubkey(FILE *f) {
char *value;
while(fgets(buf, sizeof(buf), f)) {
char *value;
while(fgets(buf, sizeof(buf), f)) {
-
in
t len = strcspn(buf, "\t =");
+
size_
t len = strcspn(buf, "\t =");
value = buf + len;
value += strspn(value, "\t ");
value = buf + len;
value += strspn(value, "\t ");
@@
-1946,9
+1945,8
@@
static int cmd_config(int argc, char *argv[]) {
// Parse line in a simple way
char *bvalue;
// Parse line in a simple way
char *bvalue;
- int len;
- len = strcspn(buf2, "\t =");
+
size_t
len = strcspn(buf2, "\t =");
bvalue = buf2 + len;
bvalue += strspn(bvalue, "\t ");
bvalue = buf2 + len;
bvalue += strspn(bvalue, "\t ");
@@
-2129,7
+2127,7
@@
int check_port(const char *name) {
fprintf(stderr, "Warning: could not bind to port 655. ");
for(int i = 0; i < 100; i++) {
fprintf(stderr, "Warning: could not bind to port 655. ");
for(int i = 0; i < 100; i++) {
-
int port = 0x1000 + (rand() & 0x7fff
);
+
uint16_t port = 0x1000 + prng(0x8000
);
if(try_bind(port)) {
char filename[PATH_MAX];
if(try_bind(port)) {
char filename[PATH_MAX];
@@
-2172,7
+2170,7
@@
static int cmd_init(int argc, char *argv[]) {
return 1;
}
return 1;
}
-
in
t len = rstrip(buf);
+
size_
t len = rstrip(buf);
if(!len) {
fprintf(stderr, "No name given!\n");
if(!len) {
fprintf(stderr, "No name given!\n");
@@
-2789,7
+2787,7
@@
static int cmd_sign(int argc, char *argv[]) {
long t = time(NULL);
char *trailer;
xasprintf(&trailer, " %s %ld", name, t);
long t = time(NULL);
char *trailer;
xasprintf(&trailer, " %s %ld", name, t);
-
in
t trailer_len = strlen(trailer);
+
size_
t trailer_len = strlen(trailer);
data = xrealloc(data, len + trailer_len);
memcpy(data + len, trailer, trailer_len);
data = xrealloc(data, len + trailer_len);
memcpy(data + len, trailer, trailer_len);
@@
-2804,7
+2802,7
@@
static int cmd_sign(int argc, char *argv[]) {
return 1;
}
return 1;
}
- b64encode(sig, sig, 64);
+ b64encode
_tinc
(sig, sig, 64);
ecdsa_free(key);
fprintf(stdout, "Signature = %s %ld %s\n", name, t, sig);
ecdsa_free(key);
fprintf(stdout, "Signature = %s %ld %s\n", name, t, sig);
@@
-2904,7
+2902,7
@@
static int cmd_verify(int argc, char *argv[]) {
char *trailer;
xasprintf(&trailer, " %s %ld", signer, t);
char *trailer;
xasprintf(&trailer, " %s %ld", signer, t);
-
in
t trailer_len = strlen(trailer);
+
size_
t trailer_len = strlen(trailer);
data = xrealloc(data, len + trailer_len);
memcpy(data + len, trailer, trailer_len);
data = xrealloc(data, len + trailer_len);
memcpy(data + len, trailer, trailer_len);
@@
-2938,7
+2936,7
@@
static int cmd_verify(int argc, char *argv[]) {
fclose(fp);
fclose(fp);
- if(b64decode(sig, sig, 86) != 64 || !ecdsa_verify(key, newline, len + trailer_len - (newline - data), sig)) {
+ if(b64decode
_tinc
(sig, sig, 86) != 64 || !ecdsa_verify(key, newline, len + trailer_len - (newline - data), sig)) {
fprintf(stderr, "Invalid signature\n");
free(data);
ecdsa_free(key);
fprintf(stderr, "Invalid signature\n");
free(data);
ecdsa_free(key);
@@
-3272,7
+3270,6
@@
static void cleanup() {
int main(int argc, char *argv[]) {
program_name = argv[0];
orig_argv = argv;
int main(int argc, char *argv[]) {
program_name = argv[0];
orig_argv = argv;
- orig_argc = argc;
tty = isatty(0) && isatty(1);
if(!parse_options(argc, argv)) {
tty = isatty(0) && isatty(1);
if(!parse_options(argc, argv)) {
@@
-3305,8
+3302,8
@@
int main(int argc, char *argv[]) {
#endif
gettimeofday(&now, NULL);
#endif
gettimeofday(&now, NULL);
- srand(now.tv_sec + now.tv_usec);
crypto_init();
crypto_init();
+ prng_init();
if(optind >= argc) {
return cmd_shell(argc, argv);
if(optind >= argc) {
return cmd_shell(argc, argv);