]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm_ioctl: Use unsigned int tcp_port to filter out negative port numbers
authorStefan Berger <stefanb@linux.ibm.com>
Sat, 26 Mar 2022 02:41:00 +0000 (22:41 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Mon, 28 Mar 2022 13:21:38 +0000 (09:21 -0400)
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>
src/swtpm_ioctl/tpm_ioctl.c

index 1ac133580d7a9d655fb9a9e765a68f036267d1c7..2db2291f52ac467ecd70db1e8b5750901bfc2839 100644 (file)
@@ -799,7 +799,8 @@ static int open_connection(const char *devname, char *tcp_hostname,
     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;
@@ -949,7 +950,7 @@ int main(int argc, char *argv[])
     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;