From e534df86f83d59aa3383170b8c3e468c37685dd8 Mon Sep 17 00:00:00 2001 From: Marvin Scholz Date: Tue, 21 Apr 2020 20:39:20 +0200 Subject: [PATCH] Fix: YP: Improve error handling In case the url written by client_get_baseurl exceeds the length and the realloc failed, previously the truncated URL would have been used. The error case (ret < 0) was not handled at all before. --- src/yp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/yp.c b/src/yp.c index 9d8b8685..77701f37 100644 --- a/src/yp.c +++ b/src/yp.c @@ -600,9 +600,16 @@ static ypdata_t *create_yp_entry (const char *mount) if (ret >= len) { // Buffer was too small, allocate a big enough one s = realloc (url, ret + 1); - if (s) url = s; - client_get_baseurl(NULL, NULL, url, len, NULL, NULL, NULL, mount, NULL); + if (!s) { + free(url); + break; + } + url = s; + + ret = client_get_baseurl(NULL, NULL, url, len, NULL, NULL, NULL, mount, NULL); } + if (ret < 0 || ret >= len) + break; config = config_get_config(); mountproxy = config_find_mount (config, mount, MOUNT_TYPE_NORMAL);