From 46fe1bece3a2eb2045eb704de90377f83bf59c3a Mon Sep 17 00:00:00 2001 From: memnoth Date: Fri, 9 Mar 2018 14:46:49 +0900 Subject: [PATCH] Fix infinite loop bug. If the parameter, old is an empty string for some reason, conditions of both for loops will be never finished. To fix the bug, added one more condition that if oldlen is 0, loops never run. from: (q = strstr(p, old)) != NULL to : (oldlen != 0) && (q = strstr(p, old)) != NULL Edited: src/as-utils.c --- src/as-utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/as-utils.c b/src/as-utils.c index 92f8b568..fdfbd1f0 100644 --- a/src/as-utils.c +++ b/src/as-utils.c @@ -456,7 +456,7 @@ as_str_replace (const gchar *str, const gchar *old, const gchar *new) size_t count, retlen, newlen = strlen(new); if (oldlen != newlen) { - for (count = 0, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) + for (count = 0, p = str; (oldlen != 0) && (q = strstr(p, old)) != NULL; p = q + oldlen) count++; /* this is undefined if p - str > PTRDIFF_MAX */ retlen = p - str + strlen(p) + count * (newlen - oldlen); @@ -466,7 +466,7 @@ as_str_replace (const gchar *str, const gchar *old, const gchar *new) if ((ret = malloc(retlen + 1)) == NULL) return NULL; - for (r = ret, p = str; (q = strstr(p, old)) != NULL; p = q + oldlen) { + for (r = ret, p = str; (oldlen != 0) && (q = strstr(p, old)) != NULL; p = q + oldlen) { /* this is undefined if q - p > PTRDIFF_MAX */ ptrdiff_t l = q - p; memcpy(r, p, l);