From d5db16d434b4de378e6fe2179d621b586de67b6a Mon Sep 17 00:00:00 2001 From: Packit Service Date: Apr 16 2021 22:13:58 +0000 Subject: Apply patch autofs-5.1.7-dont-use-realloc-in-host-exports-list-processing.patch patch_name: autofs-5.1.7-dont-use-realloc-in-host-exports-list-processing.patch present_in_specfile: true --- diff --git a/CHANGELOG b/CHANGELOG index b0c45d8..ff3e195 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ - add xdr_exports(). - remove mount.x and rpcgen dependencies. +- dont use realloc in host exports list processing. xx/xx/2018 autofs-5.1.5 - fix flag file permission. diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c index 9e7e252..4b55a88 100644 --- a/modules/lookup_hosts.c +++ b/modules/lookup_hosts.c @@ -89,44 +89,40 @@ static char *get_exports(struct autofs_point *ap, const char *host) char buf[MAX_ERR_BUF]; char *mapent; struct exportinfo *exp, *this; + size_t hostlen = strlen(host); + size_t mapent_len; debug(ap->logopt, MODPREFIX "fetchng export list for %s", host); exp = rpc_get_exports(host, 10, 0, RPC_CLOSE_NOLINGER); - mapent = NULL; this = exp; + mapent_len = 0; while (this) { - if (mapent) { - int len = strlen(mapent) + 1; - - len += strlen(host) + 2*(strlen(this->dir) + 2) + 3; - mapent = realloc(mapent, len); - if (!mapent) { - char *estr; - estr = strerror_r(errno, buf, MAX_ERR_BUF); - error(ap->logopt, MODPREFIX "malloc: %s", estr); - rpc_exports_free(exp); - return NULL; - } - strcat(mapent, " \""); - strcat(mapent, this->dir); - strcat(mapent, "\""); - } else { - int len = 2*(strlen(this->dir) + 2) + strlen(host) + 3; - - mapent = malloc(len); - if (!mapent) { - char *estr; - estr = strerror_r(errno, buf, MAX_ERR_BUF); - error(ap->logopt, MODPREFIX "malloc: %s", estr); - rpc_exports_free(exp); - return NULL; - } + mapent_len += hostlen + 2*(strlen(this->dir) + 2) + 3; + this = this->next; + } + + mapent = malloc(mapent_len + 1); + if (!mapent) { + char *estr; + estr = strerror_r(errno, buf, MAX_ERR_BUF); + error(ap->logopt, MODPREFIX "malloc: %s", estr); + error(ap->logopt, MODPREFIX "exports lookup failed for %s", host); + rpc_exports_free(exp); + return NULL; + } + *mapent = 0; + + this = exp; + while (this) { + if (!*mapent) strcpy(mapent, "\""); - strcat(mapent, this->dir); - strcat(mapent, "\""); - } + else + strcat(mapent, " \""); + strcat(mapent, this->dir); + strcat(mapent, "\""); + strcat(mapent, " \""); strcat(mapent, host); strcat(mapent, ":"); @@ -137,9 +133,6 @@ static char *get_exports(struct autofs_point *ap, const char *host) } rpc_exports_free(exp); - if (!mapent) - error(ap->logopt, MODPREFIX "exports lookup failed for %s", host); - return mapent; }