From: Willy Tarreau Date: Thu, 6 Dec 2012 10:36:59 +0000 (+0100) Subject: BUILD: ssl: NAME_MAX is not portable, use MAXPATHLEN instead X-Git-Tag: v1.5-dev15~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee2663b1cd59a82d2f2eeb4cca6a943e43ea645e;p=thirdparty%2Fhaproxy.git BUILD: ssl: NAME_MAX is not portable, use MAXPATHLEN instead At least Solaris doesn't know about NAME_MAX, so let's use the more portable MAXPATHLEN instead. This issue was reported by Benjamin Polidore. --- diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 8ee7eb7baf..94d6618956 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -437,8 +437,8 @@ int ssl_sock_load_cert(char *path, struct bind_conf *bind_conf, struct proxy *cu struct dirent *de; DIR *dir; struct stat buf; - int pathlen = 0; - char *end, *fp; + char *end; + char fp[MAXPATHLEN+1]; int cfgerr = 0; if (!(dir = opendir(path))) @@ -448,12 +448,8 @@ int ssl_sock_load_cert(char *path, struct bind_conf *bind_conf, struct proxy *cu for (end = path + strlen(path) - 1; end >= path && *end == '/'; end--) *end = 0; - if (end >= path) - pathlen = end + 1 - path; - fp = malloc(pathlen + 1 + NAME_MAX + 1); - while ((de = readdir(dir))) { - snprintf(fp, pathlen + 1 + NAME_MAX + 1, "%s/%s", path, de->d_name); + snprintf(fp, sizeof(fp), "%s/%s", path, de->d_name); if (stat(fp, &buf) != 0) { memprintf(err, "%sunable to stat SSL certificate from file '%s' : %s.\n", err && *err ? *err : "", fp, strerror(errno)); @@ -464,7 +460,6 @@ int ssl_sock_load_cert(char *path, struct bind_conf *bind_conf, struct proxy *cu continue; cfgerr += ssl_sock_load_cert_file(fp, bind_conf, curproxy, err); } - free(fp); closedir(dir); return cfgerr; }