Переглянути джерело

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 13 роки тому
батько
коміт
715493e16e
1 змінених файлів з 4 додано та 2 видалено
  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':