Skip to content

Commit eecc240

Browse files
authored
Merge pull request #567 from igaw/fix-strchomp
fabrics: Avoid buffer overrun in strchomp
2 parents 662799b + c4a91b6 commit eecc240

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/nvme/fabrics.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ const char *nvmf_dev = "/dev/nvme-fabrics";
4747

4848
/**
4949
* strchomp() - Strip trailing white space
50-
* @s: String to strip
51-
* @l: Maximum length of string
50+
* @str: String to strip
51+
* @max: Maximum length of string
5252
*/
53-
static void strchomp(char *s, int l)
53+
static void strchomp(char *str, int max)
5454
{
55-
while (l && (s[l] == '\0' || s[l] == ' '))
56-
s[l--] = '\0';
55+
int i;
56+
57+
for (i = max - 1; i >= 0; i--) {
58+
if (str[i] != '\0' && str[i] != ' ')
59+
return;
60+
else
61+
str[i] = '\0';
62+
}
5763
}
5864

5965
const char *arg_str(const char * const *strings,

0 commit comments

Comments
 (0)