Quellcode durchsuchen

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 vor 12 Jahren
Ursprung
Commit
715493e16e
1 geänderte Dateien mit 4 neuen und 2 gelöschten Zeilen
  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;
 	nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL;
 	name_format_t address_format = ADDRESS_FORMAT_NAME;
 	name_format_t address_format = ADDRESS_FORMAT_NAME;
 	command_t command_opt = CMD_SHOWSTATUS;
 	command_t command_opt = CMD_SHOWSTATUS;
+	long int l;
 
 
 	if (init_all()) {
 	if (init_all()) {
 		close_all();
 		close_all();
@@ -763,11 +764,12 @@ int main (int argc, char *argv[]) {
 			}
 			}
 			break;
 			break;
 		case 'n':
 		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");
 				fprintf(stderr, "The nodeid was not valid, try a positive number\n");
 				exit(2);
 				exit(2);
 			}
 			}
+			nodeid = l;
 			nodeid_set = 1;
 			nodeid_set = 1;
 			break;
 			break;
 		case 'v':
 		case 'v':