[PATCH v2 2/6] i2cset: Check number of arguments for block data writes

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

 



Signed-off-by: Guenter Roeck <guenter.roeck@xxxxxxxxxxxx>
---
 tools/i2cset.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/tools/i2cset.c b/tools/i2cset.c
index 8856d71..c59186b 100644
--- a/tools/i2cset.c
+++ b/tools/i2cset.c
@@ -219,11 +219,15 @@ int main(int argc, char *argv[])
 		}
 		if (size == I2C_SMBUS_BLOCK_DATA || size == I2C_SMBUS_I2C_BLOCK_DATA) {
 			pec = argv[argc-1][1] == 'p';
+			if (argc > (int)sizeof(block) + flags + 5) {
+				fprintf(stderr, "Error: Bad number of arguments!\n");
+				help();
+			}
 			if (pec && size == I2C_SMBUS_I2C_BLOCK_DATA) {
 				fprintf(stderr, "Error: PEC not supported for I2C block writes!\n");
 				help();
 			}
-			for (len = 0; len < (int)sizeof(block) && len + flags + 5 < argc; len++) {
+			for (len = 0; len + flags + 5 < argc; len++) {
 				value = strtol(argv[flags + len + 4], &end, 0);
 				if (*end || value < 0 || value > 0xff) {
                                 	fprintf(stderr, "Error: Block data value invalid!\n");
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux