From e7b97f2edf17990be192d95ed42b2431b3060249 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Mon, 14 Jun 2021 18:07:37 +0200 Subject: mhash: fix empty input string problem with division by 0 --- service/src/.gitignore | 1 - service/src/util.c | 1 + src/util.c | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 service/src/.gitignore diff --git a/service/src/.gitignore b/service/src/.gitignore deleted file mode 100644 index 378eac2..0000000 --- a/service/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/service/src/util.c b/service/src/util.c index d8b9c98..833c373 100644 --- a/service/src/util.c +++ b/service/src/util.c @@ -49,6 +49,7 @@ mhash(const char *str, int len) int i, k, v; char c, *bp; + if (!str || !*str) str = "."; if (len == -1) len = strlen(str); for (v = 0, i = 0; i < len; i++) v += str[i]; diff --git a/src/util.c b/src/util.c index 8bd8448..7a57d38 100644 --- a/src/util.c +++ b/src/util.c @@ -52,6 +52,7 @@ mhash(const char *str, int len) /* VULN #2: BUFFER OVERFLOW */ /* see documentation/README.md for more details */ + if (!str || !*str) str = "."; if (len == -1) len = strlen(str); for (v = 0, i = 0; i < len; i++) v += str[i]; -- cgit v1.2.3-71-gd317