mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-06 05:10:36 +00:00
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,
|
||||
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
|
||||
* file in the directory into store.
|
||||
* 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);
|
||||
if (dir)
|
||||
{
|
||||
size_t bufsize = strlen(path) + 1 + PATH_MAX + 1;
|
||||
char *filebuf = CryptMemAlloc(bufsize);
|
||||
size_t path_len = strlen(path), bufsize = 0;
|
||||
char *filebuf = NULL;
|
||||
|
||||
if (filebuf)
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(dir)))
|
||||
{
|
||||
struct dirent *entry;
|
||||
while ((entry = readdir(dir)))
|
||||
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
|
||||
{
|
||||
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);
|
||||
if (import_certs_from_path(filebuf, store, FALSE) && !ret)
|
||||
ret = TRUE;
|
||||
ERR("Path buffer (re)allocation failed with out of memory condition\n");
|
||||
break;
|
||||
}
|
||||
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);
|
||||
}
|
||||
return ret;
|
||||
|
|
Loading…
Reference in a new issue