Przeglądaj źródła

quorumtool: Properly check nodeid cli param

Return value of strtol can be negative, but result was assigned to
unsigned integer. To make check correct, result is first assigned to
signed variable, checked, and then assigned to unsigned variable.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Jan Friesse 12 lat temu
rodzic
commit
715493e16e
1 zmienionych plików z 4 dodań i 2 usunięć
  1. 4 2
      tools/corosync-quorumtool.c

+ 4 - 2
tools/corosync-quorumtool.c

@@ -715,6 +715,7 @@ int main (int argc, char *argv[]) {
 	nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL;
 	name_format_t address_format = ADDRESS_FORMAT_NAME;
 	command_t command_opt = CMD_SHOWSTATUS;
+	long int l;
 
 	if (init_all()) {
 		close_all();
@@ -763,11 +764,12 @@ int main (int argc, char *argv[]) {
 			}
 			break;
 		case 'n':
-			nodeid = strtol(optarg, &endptr, 0);
-			if ((nodeid == 0 && endptr == optarg) || nodeid < 0) {
+			l = strtol(optarg, &endptr, 0);
+			if ((l == 0 && endptr == optarg) || l < 0) {
 				fprintf(stderr, "The nodeid was not valid, try a positive number\n");
 				exit(2);
 			}
+			nodeid = l;
 			nodeid_set = 1;
 			break;
 		case 'v':