From 96055f3a30d9643eff5141ed1926468301379c74 Mon Sep 17 00:00:00 2001 From: Douglas Gilbert Date: Fri, 8 Apr 2016 02:46:35 +0000 Subject: [PATCH 016/126] sg_inq: fix potential unbounded loop in --export git-svn-id: svn://localhost/trunk@691 6180dd3e-e324-4e3e-922d-17de1ae2f315 --- src/sg_inq.c | 21 +++++++++++---------- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/sg_inq.c b/src/sg_inq.c index 9dc8838..8aa1970 100644 --- a/src/sg_inq.c +++ b/src/sg_inq.c @@ -43,7 +43,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.57 20160208"; /* SPC-5 rev 08 */ +static const char * version_str = "1.58 20160407"; /* SPC-5 rev 08 */ /* INQUIRY notes: * It is recommended that the initial allocation length given to a @@ -1032,17 +1032,18 @@ static int encode_whitespaces(unsigned char *str, int inlen) { int k, res; - int j = 0; - int valid = 0; + int j; + bool valid = false; int outlen = inlen, zeroes = 0; /* Skip initial whitespaces */ - while (isblank(str[j])) - j++; - /* Skip possible unicode prefix characters */ - while (str[j] < 0x20) - j++; - + for (j = 0; (j < inlen) && isblank(str[j]); ++j) + ; + if (j < inlen) { + /* Skip possible unicode prefix characters */ + for ( ; (j < inlen) && (str[j] < 0x20); ++j) + ; + } k = j; /* Strip trailing whitespaces */ while ((outlen > k) && @@ -1069,7 +1070,7 @@ encode_whitespaces(unsigned char *str, int inlen) zeroes = 0; } else { str[res++] = str[k]; - valid++; + valid = true; zeroes = 0; } } -- 1.8.3.1