On Sun, 13 Feb 2011 12:17:22 -0800, Guenter Roeck wrote:
> Signed-off-by: Guenter Roeck <[email protected]>
> ---
>  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();
>                       }

It would probably be more logical to swap the two blocks above, as you
set pec just before and are reading the arguments just after.

> -                     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");

Other than this, it looks good.

-- 
Jean Delvare
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to