Mercurial > projects > pwm
diff pw.c @ 33:fa93d2ff9c62
Prevent potential division by zero
Add safeguard ensuring that there is at least one possible character to
generate passwords from in order to exclude the possibility of a division by
zero error in rand_uniform.
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Tue, 30 Jul 2019 20:38:08 +0200 |
parents | 8768fbd09bc5 |
children |
line wrap: on
line diff
--- a/pw.c Tue Nov 28 17:16:24 2017 +0100 +++ b/pw.c Tue Jul 30 20:38:08 2019 +0200 @@ -56,6 +56,10 @@ for (i = 0; i < groups_len; i++) { chars_len += strlen(groups[i].chars); } + if (chars_len == 0) { + /* there must be at least one character to choose from */ + return (-1); + } chars = xmalloc(chars_len + 1); chars[0] = '\0';