The port being parsed must be given as unsigned int so that the comparison
of *tcp_port >= 65536 also filters out negative numbers passed via the
command line. Previously one could pass -1 and swtpm_ioctl would try to
connect to port 65535.
Resolves: https://github.com/stefanberger/swtpm/issues/679
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
return fd;
}
-static int parse_tcp_optarg(char *optarg, char **tcp_hostname, int *tcp_port)
+static int parse_tcp_optarg(char *optarg, char **tcp_hostname,
+ unsigned int *tcp_port)
{
char *pos = strrchr(optarg, ':');
int n;
char *tcp_hostname = NULL;
unsigned int locality = 0;
unsigned int tpmbuffersize = 0;
- int tcp_port = -1;
+ unsigned int tcp_port = 0;
bool is_chardev;
unsigned long int info_flags = 0;
char *endptr = NULL;