]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: ssl: NAME_MAX is not portable, use MAXPATHLEN instead
authorWilly Tarreau <w@1wt.eu>
Thu, 6 Dec 2012 10:36:59 +0000 (11:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 6 Dec 2012 10:36:59 +0000 (11:36 +0100)
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.

src/ssl_sock.c

index 8ee7eb7baf47669e6aefe5277a9c78e9a7dc7ac8..94d66189565298abb1f1cc5400ed77e68e3b767b 100644 (file)
@@ -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;
 }