Skip to content

Commit 32fae28

Browse files
committed
use strnXXX functions: rootless-containers#259
1 parent e7e38a6 commit 32fae28

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

main.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -1062,26 +1062,32 @@ static int slirp4netns_config_from_cidr6(struct slirp4netns_config *cfg,
10621062
return -1;
10631063
}
10641064

1065-
strcpy(tmp, net);
1066-
strcat(tmp, DEFAULT_VHOST_OFFSET6);
1065+
#define MAX(a,b) (((a)>(b))?(a):(b))
1066+
1067+
strncpy(tmp, net, sizeof(tmp));
1068+
strncat(tmp, DEFAULT_VHOST_OFFSET6,
1069+
MAX(0, INET6_ADDRSTRLEN - strlen(tmp) - strlen(DEFAULT_VHOST_OFFSET6)));
10671070
if (inet_pton(AF_INET6, tmp, &cfg->vhost6) != 1) {
10681071
return -1;
10691072
}
10701073

1071-
strcpy(tmp, net);
1072-
strcat(tmp, DEFAULT_VDHCPSTART_OFFSET6);
1074+
strncpy(tmp, net, sizeof(tmp));
1075+
strncat(tmp, DEFAULT_VDHCPSTART_OFFSET6,
1076+
MAX(0, INET6_ADDRSTRLEN - strlen(tmp) - strlen(DEFAULT_VDHCPSTART_OFFSET6)));
10731077
if (inet_pton(AF_INET6, tmp, &cfg->vdhcp_start6) != 1) {
10741078
return -1;
10751079
}
10761080

1077-
strcpy(tmp, net);
1078-
strcat(tmp, DEFAULT_VNAMESERVER_OFFSET6);
1081+
strncpy(tmp, net, sizeof(tmp));
1082+
strncat(tmp, DEFAULT_VNAMESERVER_OFFSET6,
1083+
MAX(0, INET6_ADDRSTRLEN - strlen(tmp) - strlen(DEFAULT_VNAMESERVER_OFFSET6)));
10791084
if (inet_pton(AF_INET6, tmp, &cfg->vnameserver6) != 1) {
10801085
return -1;
10811086
}
10821087

1083-
strcpy(tmp, net);
1084-
strcat(tmp, DEFAULT_RECOMMENDED_VGUEST_OFFSET6);
1088+
strncpy(tmp, net, sizeof(tmp));
1089+
strncat(tmp, DEFAULT_RECOMMENDED_VGUEST_OFFSET6,
1090+
MAX(0, INET6_ADDRSTRLEN - strlen(tmp) - strlen(DEFAULT_RECOMMENDED_VGUEST_OFFSET6)));
10851091
if (inet_pton(AF_INET6, tmp, &cfg->recommended_vguest6) != 1) {
10861092
return -1;
10871093
}

0 commit comments

Comments
 (0)