crypt32: Avoid relying on PATH_MAX in import_certs_from_dir helper.
PATH_MAX is not guaranteed to be available on all platforms, and it is inadequate as a hardcoded buffer size anyway.
This commit is contained in:
parent
1a7c76c7b0
commit
6f2513d39a
|
@ -326,6 +326,32 @@ static BOOL import_certs_from_file(int fd, HCERTSTORE store)
|
||||||
static BOOL import_certs_from_path(LPCSTR path, HCERTSTORE store,
|
static BOOL import_certs_from_path(LPCSTR path, HCERTSTORE store,
|
||||||
BOOL allow_dir);
|
BOOL allow_dir);
|
||||||
|
|
||||||
|
static BOOL check_buffer_resize(char **ptr_buf, size_t *buf_size, size_t check_size)
|
||||||
|
{
|
||||||
|
if (check_size > *buf_size)
|
||||||
|
{
|
||||||
|
*buf_size = check_size;
|
||||||
|
|
||||||
|
if (*ptr_buf)
|
||||||
|
{
|
||||||
|
char *realloc_buf = CryptMemRealloc(*ptr_buf, *buf_size);
|
||||||
|
|
||||||
|
if (!realloc_buf)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
*ptr_buf = realloc_buf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*ptr_buf = CryptMemAlloc(*buf_size);
|
||||||
|
if (!*ptr_buf)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Opens path, which must be a directory, and imports certificates from every
|
/* Opens path, which must be a directory, and imports certificates from every
|
||||||
* file in the directory into store.
|
* file in the directory into store.
|
||||||
* Returns TRUE if any certificates were successfully imported.
|
* Returns TRUE if any certificates were successfully imported.
|
||||||
|
@ -341,23 +367,27 @@ static BOOL import_certs_from_dir(LPCSTR path, HCERTSTORE store)
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (dir)
|
if (dir)
|
||||||
{
|
{
|
||||||
size_t bufsize = strlen(path) + 1 + PATH_MAX + 1;
|
size_t path_len = strlen(path), bufsize = 0;
|
||||||
char *filebuf = CryptMemAlloc(bufsize);
|
char *filebuf = NULL;
|
||||||
|
|
||||||
if (filebuf)
|
struct dirent *entry;
|
||||||
|
while ((entry = readdir(dir)))
|
||||||
{
|
{
|
||||||
struct dirent *entry;
|
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
|
||||||
while ((entry = readdir(dir)))
|
|
||||||
{
|
{
|
||||||
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
|
size_t name_len = strlen(entry->d_name);
|
||||||
|
|
||||||
|
if (!check_buffer_resize(&filebuf, &bufsize, path_len + 1 + name_len + 1))
|
||||||
{
|
{
|
||||||
snprintf(filebuf, bufsize, "%s/%s", path, entry->d_name);
|
ERR("Path buffer (re)allocation failed with out of memory condition\n");
|
||||||
if (import_certs_from_path(filebuf, store, FALSE) && !ret)
|
break;
|
||||||
ret = TRUE;
|
|
||||||
}
|
}
|
||||||
|
snprintf(filebuf, bufsize, "%s/%s", path, entry->d_name);
|
||||||
|
if (import_certs_from_path(filebuf, store, FALSE) && !ret)
|
||||||
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
CryptMemFree(filebuf);
|
|
||||||
}
|
}
|
||||||
|
CryptMemFree(filebuf);
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue