[PATCH 22/28] quorumtool: Properly check nodeid cli param

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tools/corosync-quorumtool.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c
index 5cf043e..11124b3 100644
--- a/tools/corosync-quorumtool.c
+++ b/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':
-- 
1.7.1

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss




[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux