Index: lib/ipmi_dcmi.c
===================================================================
RCS file: /cvsroot/ipmitool/ipmitool/lib/ipmi_dcmi.c,v
retrieving revision 1.15
diff -u -r1.15 ipmi_dcmi.c
--- lib/ipmi_dcmi.c	22 Jul 2013 08:34:09 -0000	1.15
+++ lib/ipmi_dcmi.c	25 Jul 2013 04:32:49 -0000
@@ -1477,9 +1477,14 @@
 	struct ipmi_rq req; /* ipmi request (to send) */
 	struct power_limit val;
 	uint8_t msg_data[15]; /* number of request data bytes */
-	uint32_t lvalue = strtol(value, NULL, 10);
+	uint32_t lvalue = 0;
 	int i;
 
+	if (str2uint(value, &lvalue) != 0) {
+		lprintf(LOG_ERR, "Given %s '%s' is invalid.", value);
+		return (-1);
+	}
+
 	rsp = ipmi_dcmi_pwr_glimit(intf); /* get the power limit settings */
 # if 0
 	{
@@ -1693,7 +1698,10 @@
 			if ( argc == 10) {
 				/* Let`s initialize dcmi power parameters */
 				struct ipmi_rq req;
-				uint8_t data[256];
+				uint8_t data[256] = {0};
+				uint16_t sample = 0;
+				uint16_t limit = 0;
+				uint32_t correction = 0;
 
 				memset(data, 0, sizeof(data));
 				memset(&req, 0, sizeof(req));
@@ -1724,13 +1732,36 @@
 					return -1;
 				}
 				/* limit */
-				*(uint16_t*)(&data[5]) = strtol(argv[4], NULL, 10);
+				if (str2ushort(argv[4], &limit) != 0) {
+					lprintf(LOG_ERR,
+							"Given Limit '%s' is invalid.",
+							argv[4]);
+					return (-1);
+				}
+				data[5] = limit >> 0;
+				data[6] = limit >> 8;
 				/* correction */
-				*(uint32_t*)(&data[7]) = strtol(argv[6], NULL, 10);
+				if (str2uint(argv[6], &correction) != 0) {
+					lprintf(LOG_ERR,
+							"Given Correction '%s' is invalid.",
+							argv[6]);
+					return (-1);
+				}
+				data[7] = correction >> 0;
+				data[8] = correction >> 8;
+				data[9] = correction >> 16;
+				data[10] = correction >> 24;
 				data[11] = 0x00;  /* reserved */
 				data[12] = 0x00;  /* reserved */
 				/* sample */
-				*(uint16_t*)(&data[13]) = strtol(argv[8], NULL, 10);
+				if (str2ushort(argv[8], &sample) != 0) {
+					lprintf(LOG_ERR,
+							"Given Sample '%s' is invalid.",
+							argv[8]);
+					return (-1);
+				}
+				data[13] = sample >> 0;
+				data[14] = sample >> 8;
 
 				rsp = intf->sendrecv(intf, &req);
 				if (chk_rsp(rsp)) {
@@ -1836,14 +1867,15 @@
 	/* end set management controller identifier string */
 	case 0x07:
 	{
-		uint8_t entityID, entityInst;
+		uint8_t entityID = 0;
+		uint8_t entityInst = 0;
 		uint8_t persistanceFlag;
 		uint8_t actionHardPowerOff;
 		uint8_t actionLogToSEL;
-		uint8_t tempLimit;
-		uint16_t samplingTime;
+		uint8_t tempLimit = 0;
 		uint8_t samplingTimeLSB;
 		uint8_t samplingTimeMSB;
+		uint16_t samplingTime = 0;
 		/* Thermal policy get/set */
 		/* dcmitool dcmi thermalpolicy get */
 		switch (str2val2(argv[1], dcmi_thermalpolicy_vals)) {
@@ -1852,8 +1884,18 @@
 				lprintf(LOG_NOTICE, "Get <entityID> <instanceID>");
 				return -1;
 			}
-			entityID = (uint8_t)strtol(argv[2], NULL,0);
-			entityInst  = (uint8_t)strtol(argv[3], NULL, 0);
+			if (str2uchar(argv[2], &entityID) != 0) {
+				lprintf(LOG_ERR,
+						"Given Entity ID '%s' is invalid.",
+						argv[2]);
+				return (-1);
+			}
+			if (str2uchar(argv[3], &entityInst) != 0) {
+				lprintf(LOG_ERR,
+						"Given Instance ID '%s' is invalid.",
+						argv[3]);
+				return (-1);
+			}
 			rc = ipmi_dcmi_getthermalpolicy(intf,  entityID, entityInst);
 			break;
 		case 0x01:
@@ -1869,14 +1911,33 @@
 						-1, 0);
 				return -1;
 			}
-			entityID = (uint8_t)strtol(argv[2],NULL, 0);
-			entityInst = (uint8_t)strtol(argv[3], NULL, 0);
-
+			if (str2uchar(argv[2], &entityID) != 0) {
+				lprintf(LOG_ERR,
+						"Given Entity ID '%s' is invalid.",
+						argv[2]);
+				return (-1);
+			}
+			if (str2uchar(argv[3], &entityInst) != 0) {
+				lprintf(LOG_ERR,
+						"Given Instance ID '%s' is invalid.",
+						argv[3]);
+				return (-1);
+			}
 			persistanceFlag = (uint8_t) str2val2(argv[4], dcmi_thermalpolicy_set_parameters_vals);
 			actionHardPowerOff = (uint8_t) str2val2(argv[5], dcmi_thermalpolicy_set_parameters_vals);
 			actionLogToSEL = (uint8_t) str2val2(argv[6], dcmi_thermalpolicy_set_parameters_vals);
-			tempLimit = (uint8_t) strtol(argv[7], NULL, 0);
-			samplingTime = (uint16_t) strtol(argv[8], NULL, 0);
+			if (str2uchar(argv[7], &tempLimit) != 0) {
+				lprintf(LOG_ERR,
+						"Given Temp Limit '%s' is invalid.",
+						argv[7]);
+				return (-1);
+			}
+			if (str2ushort(argv[8], &samplingTime) != 0) {
+				lprintf(LOG_ERR,
+						"Given Sampling Time '%s' is invalid.",
+						argv[8]);
+				return (-1);
+			}
 			samplingTimeLSB =  (samplingTime & 0xFF);
 			samplingTimeMSB = ((samplingTime & 0xFF00) >> 8);
 
@@ -1933,9 +1994,16 @@
 		if (strncmp(argv[1], "activate_dhcp", 13) == 0) {
 			rsp = ipmi_dcmi_setconfparam(intf, 1, 1);
 		} else {
+			uint16_t tmp_val = 0;
+			if (str2ushort(argv[2], &tmp_val) != 0) {
+				lprintf(LOG_ERR,
+						"Given %s '%s' is invalid.",
+						argv[1], argv[2]);
+				return (-1);
+			}
 			rsp = ipmi_dcmi_setconfparam(intf,
 					str2val2(argv[1], dcmi_conf_param_vals),
-					(uint16_t)strtol(argv[2], NULL, 0));
+					tmp_val);
 		}
 		if (chk_rsp(rsp)) {
 			lprintf(LOG_ERR,
