Add field widths to sscanf() calls.

Found by cppcheck.
This commit is contained in:
Guus Sliepen 2017-04-18 20:09:08 +02:00
parent be8e5cbd1c
commit 060ab1cd7c
4 changed files with 16 additions and 16 deletions

View file

@ -69,7 +69,7 @@ static int info_node(int fd, const char *item) {
long int last_state_change; long int last_state_change;
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
int n = sscanf(line, "%d %d %s %s %s port %s %d %d %d %d %x %"PRIx32" %s %s %d %hd %hd %hd %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change); int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
if(n == 2) if(n == 2)
break; break;
@ -91,7 +91,7 @@ static int info_node(int fd, const char *item) {
} }
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
if(sscanf(line, "%d %d %s", &code, &req, node) == 2) if(sscanf(line, "%d %d %4095s", &code, &req, node) == 2)
break; break;
} }
@ -158,7 +158,7 @@ static int info_node(int fd, const char *item) {
printf("Edges: "); printf("Edges: ");
sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item); sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item);
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
int n = sscanf(line, "%d %d %s %s", &code, &req, from, to); int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, from, to);
if(n == 2) if(n == 2)
break; break;
if(n != 4) { if(n != 4) {
@ -174,7 +174,7 @@ static int info_node(int fd, const char *item) {
printf("Subnets: "); printf("Subnets: ");
sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item); sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item);
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
int n = sscanf(line, "%d %d %s %s", &code, &req, subnet, from); int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, subnet, from);
if(n == 2) if(n == 2)
break; break;
if(n != 4) { if(n != 4) {
@ -209,7 +209,7 @@ static int info_subnet(int fd, const char *item) {
sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item); sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_SUBNETS, item);
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
int n = sscanf(line, "%d %d %s %s", &code, &req, netstr, owner); int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, netstr, owner);
if(n == 2) if(n == 2)
break; break;

View file

@ -259,7 +259,7 @@ int cmd_invite(int argc, char *argv[]) {
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
char node[4096]; char node[4096];
int code, req; int code, req;
if(sscanf(line, "%d %d %s", &code, &req, node) != 3) if(sscanf(line, "%d %d %4095s", &code, &req, node) != 3)
break; break;
if(!strcmp(node, argv[1])) if(!strcmp(node, argv[1]))
found = true; found = true;
@ -1044,7 +1044,7 @@ next:
char hisname[4096] = ""; char hisname[4096] = "";
int code, hismajor, hisminor = 0; int code, hismajor, hisminor = 0;
if(!recvline(sock, line, sizeof line) || sscanf(line, "%d %s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof line) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) { if(!recvline(sock, line, sizeof line) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof line) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) {
fprintf(stderr, "Cannot read greeting from peer\n"); fprintf(stderr, "Cannot read greeting from peer\n");
closesocket(sock); closesocket(sock);
goto next; goto next;

View file

@ -803,7 +803,7 @@ bool connect_tincd(bool verbose) {
char data[4096]; char data[4096];
int version; int version;
if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %s %d", &code, data, &version) != 3 || code != 0) { if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %4095s %d", &code, data, &version) != 3 || code != 0) {
if(verbose) if(verbose)
fprintf(stderr, "Cannot read greeting from control socket: %s\n", sockstrerror(sockerrno)); fprintf(stderr, "Cannot read greeting from control socket: %s\n", sockstrerror(sockerrno));
close(fd); close(fd);
@ -1119,7 +1119,7 @@ static int cmd_dump(int argc, char *argv[]) {
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
char node1[4096], node2[4096]; char node1[4096], node2[4096];
int n = sscanf(line, "%d %d %s %s", &code, &req, node1, node2); int n = sscanf(line, "%d %d %4095s %4095s", &code, &req, node1, node2);
if(n == 2) { if(n == 2) {
if(do_graph && req == REQ_DUMP_NODES) if(do_graph && req == REQ_DUMP_NODES)
continue; continue;
@ -1151,7 +1151,7 @@ static int cmd_dump(int argc, char *argv[]) {
switch(req) { switch(req) {
case REQ_DUMP_NODES: { case REQ_DUMP_NODES: {
int n = sscanf(line, "%*d %*d %s %s %s port %s %d %d %d %d %x %x %s %s %d %hd %hd %hd %ld", node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change); int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %x %4095s %4095s %d %hd %hd %hd %ld", node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
if(n != 17) { if(n != 17) {
fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line); fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line);
return 1; return 1;
@ -1181,7 +1181,7 @@ static int cmd_dump(int argc, char *argv[]) {
} break; } break;
case REQ_DUMP_EDGES: { case REQ_DUMP_EDGES: {
int n = sscanf(line, "%*d %*d %s %s %s port %s %s port %s %x %d", from, to, host, port, local_host, local_port, &options, &weight); int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %4095s port %4095s %x %d", from, to, host, port, local_host, local_port, &options, &weight);
if(n != 8) { if(n != 8) {
fprintf(stderr, "Unable to parse edge dump from tincd.\n"); fprintf(stderr, "Unable to parse edge dump from tincd.\n");
return 1; return 1;
@ -1199,7 +1199,7 @@ static int cmd_dump(int argc, char *argv[]) {
} break; } break;
case REQ_DUMP_SUBNETS: { case REQ_DUMP_SUBNETS: {
int n = sscanf(line, "%*d %*d %s %s", subnet, node); int n = sscanf(line, "%*d %*d %4095s %4095s", subnet, node);
if(n != 2) { if(n != 2) {
fprintf(stderr, "Unable to parse subnet dump from tincd.\n"); fprintf(stderr, "Unable to parse subnet dump from tincd.\n");
return 1; return 1;
@ -1208,7 +1208,7 @@ static int cmd_dump(int argc, char *argv[]) {
} break; } break;
case REQ_DUMP_CONNECTIONS: { case REQ_DUMP_CONNECTIONS: {
int n = sscanf(line, "%*d %*d %s %s port %s %x %d %x", node, host, port, &options, &socket, &status_int); int n = sscanf(line, "%*d %*d %4095s %4095s port %4095s %x %d %x", node, host, port, &options, &socket, &status_int);
if(n != 6) { if(n != 6) {
fprintf(stderr, "Unable to parse connection dump from tincd.\n"); fprintf(stderr, "Unable to parse connection dump from tincd.\n");
return 1; return 1;
@ -2233,7 +2233,7 @@ static int cmd_import(int argc, char *argv[]) {
bool firstline = true; bool firstline = true;
while(fgets(buf, sizeof buf, in)) { while(fgets(buf, sizeof buf, in)) {
if(sscanf(buf, "Name = %s", name) == 1) { if(sscanf(buf, "Name = %4095s", name) == 1) {
firstline = false; firstline = false;
if(!check_id(name)) { if(!check_id(name)) {
@ -2725,7 +2725,7 @@ static char *complete_info(const char *text, int state) {
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
char item[4096]; char item[4096];
int n = sscanf(line, "%d %d %s", &code, &req, item); int n = sscanf(line, "%d %d %4095s", &code, &req, item);
if(n == 2) { if(n == 2) {
i++; i++;
if(i >= 2) if(i >= 2)

View file

@ -90,7 +90,7 @@ static bool update(int fd) {
ns->known = false; ns->known = false;
while(recvline(fd, line, sizeof line)) { while(recvline(fd, line, sizeof line)) {
int n = sscanf(line, "%d %d %s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes); int n = sscanf(line, "%d %d %4095s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, name, &in_packets, &in_bytes, &out_packets, &out_bytes);
if(n == 2) if(n == 2)
return true; return true;