changeset 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 b5ebed168e59
children 34ada71ff3e5
files pw.c
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
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';