libpkgconf: start to remove PKGCONF_BUFSIZE allocations from the stack. (closes #149)

Patch by Karen Arutyunov.
pull/164/head
William Pitcock 2017-10-16 12:56:19 -05:00
parent 1297385762
commit 4589274c43
6 changed files with 25 additions and 20 deletions

View File

@ -56,7 +56,7 @@ static inline pkgconf_dependency_t *
pkgconf_dependency_addraw(const pkgconf_client_t *client, pkgconf_list_t *list, const char *package, size_t package_sz, const char *version, size_t version_sz, pkgconf_pkg_comparator_t compare) pkgconf_dependency_addraw(const pkgconf_client_t *client, pkgconf_list_t *list, const char *package, size_t package_sz, const char *version, size_t version_sz, pkgconf_pkg_comparator_t compare)
{ {
pkgconf_dependency_t *dep; pkgconf_dependency_t *dep;
char depbuf[PKGCONF_BUFSIZE]; char depbuf[PKGCONF_ITEM_SIZE];
dep = calloc(sizeof(pkgconf_dependency_t), 1); dep = calloc(sizeof(pkgconf_dependency_t), 1);
dep->package = pkgconf_strndup(package, package_sz); dep->package = pkgconf_strndup(package, package_sz);
@ -161,7 +161,7 @@ pkgconf_dependency_parse_str(const pkgconf_client_t *client, pkgconf_list_t *dep
{ {
parse_state_t state = OUTSIDE_MODULE; parse_state_t state = OUTSIDE_MODULE;
pkgconf_pkg_comparator_t compare = PKGCONF_CMP_ANY; pkgconf_pkg_comparator_t compare = PKGCONF_CMP_ANY;
char cmpname[PKGCONF_BUFSIZE]; char cmpname[PKGCONF_ITEM_SIZE];
char buf[PKGCONF_BUFSIZE]; char buf[PKGCONF_BUFSIZE];
size_t package_sz = 0, version_sz = 0; size_t package_sz = 0, version_sz = 0;
char *start = buf; char *start = buf;

View File

@ -112,7 +112,7 @@ pkgconf_fragment_munge(const pkgconf_client_t *client, char *buf, size_t buflen,
static inline char * static inline char *
pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source) pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source)
{ {
char mungebuf[PKGCONF_BUFSIZE]; char mungebuf[PKGCONF_ITEM_SIZE];
pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, source, client->sysroot_dir); pkgconf_fragment_munge(client, mungebuf, sizeof mungebuf, source, client->sysroot_dir);
return strdup(mungebuf); return strdup(mungebuf);
} }
@ -148,7 +148,7 @@ pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const
} }
else else
{ {
char mungebuf[PKGCONF_BUFSIZE]; char mungebuf[PKGCONF_ITEM_SIZE];
if (list->tail != NULL && list->tail->data != NULL) if (list->tail != NULL && list->tail->data != NULL)
{ {

View File

@ -78,7 +78,7 @@ void
pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter) pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
{ {
pkgconf_path_t *node; pkgconf_path_t *node;
char path[PKGCONF_BUFSIZE]; char path[PKGCONF_ITEM_SIZE];
pkgconf_strlcpy(path, text, sizeof path); pkgconf_strlcpy(path, text, sizeof path);
pkgconf_path_relocate(path, sizeof path); pkgconf_path_relocate(path, sizeof path);
@ -92,7 +92,7 @@ pkgconf_path_add(const char *text, pkgconf_list_t *dirlist, bool filter)
return; return;
if (S_ISLNK(st.st_mode)) if (S_ISLNK(st.st_mode))
{ {
char linkdest[PKGCONF_BUFSIZE]; char linkdest[PKGCONF_ITEM_SIZE];
ssize_t len; ssize_t len;
memset(linkdest, '\0', sizeof linkdest); memset(linkdest, '\0', sizeof linkdest);
@ -204,7 +204,7 @@ bool
pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist) pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist)
{ {
pkgconf_node_t *n = NULL; pkgconf_node_t *n = NULL;
char relocated[PKGCONF_BUFSIZE]; char relocated[PKGCONF_ITEM_SIZE];
const char *cpath = path; const char *cpath = path;
pkgconf_strlcpy(relocated, path, sizeof relocated); pkgconf_strlcpy(relocated, path, sizeof relocated);

View File

@ -36,7 +36,6 @@
#endif #endif
#define PKG_CONFIG_EXT ".pc" #define PKG_CONFIG_EXT ".pc"
#define PKG_CONFIG_PATH_SZ (65535)
static inline bool static inline bool
str_has_suffix(const char *str, const char *suffix) str_has_suffix(const char *str, const char *suffix)
@ -287,8 +286,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
{ {
pkgconf_pkg_t *pkg; pkgconf_pkg_t *pkg;
char readbuf[PKGCONF_BUFSIZE]; char readbuf[PKGCONF_BUFSIZE];
char pathbuf[PKGCONF_BUFSIZE]; char pathbuf[PKGCONF_ITEM_SIZE];
char prefixbuf[PKGCONF_BUFSIZE];
char *idptr; char *idptr;
size_t lineno = 0; size_t lineno = 0;
@ -374,7 +372,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
pkgconf_tuple_add(client, &pkg->vars, key, value, true); pkgconf_tuple_add(client, &pkg->vars, key, value, true);
else else
{ {
const char *relvalue = determine_prefix(pkg, prefixbuf, sizeof prefixbuf); const char *relvalue = determine_prefix(pkg, pathbuf, sizeof pathbuf);
if (relvalue != NULL) if (relvalue != NULL)
{ {
pkgconf_tuple_add(client, &pkg->vars, "orig_prefix", value, true); pkgconf_tuple_add(client, &pkg->vars, "orig_prefix", value, true);
@ -509,8 +507,8 @@ pkgconf_pkg_try_specific_path(pkgconf_client_t *client, const char *path, const
{ {
pkgconf_pkg_t *pkg = NULL; pkgconf_pkg_t *pkg = NULL;
FILE *f; FILE *f;
char locbuf[PKG_CONFIG_PATH_SZ]; char locbuf[PKGCONF_ITEM_SIZE];
char uninst_locbuf[PKG_CONFIG_PATH_SZ]; char uninst_locbuf[PKGCONF_ITEM_SIZE];
PKGCONF_TRACE(client, "trying path: %s for %s", path, name); PKGCONF_TRACE(client, "trying path: %s for %s", path, name);
@ -547,7 +545,7 @@ pkgconf_pkg_scan_dir(pkgconf_client_t *client, const char *path, void *data, pkg
for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir)) for (dirent = readdir(dir); dirent != NULL; dirent = readdir(dir))
{ {
char filebuf[PKGCONF_BUFSIZE]; char filebuf[PKGCONF_ITEM_SIZE];
pkgconf_pkg_t *pkg; pkgconf_pkg_t *pkg;
FILE *f; FILE *f;
@ -634,7 +632,7 @@ pkgconf_pkg_find_in_registry_key(pkgconf_client_t *client, HKEY hkey, const char
while (RegEnumValue(key, i++, buf, &bufsize, NULL, NULL, NULL, NULL) while (RegEnumValue(key, i++, buf, &bufsize, NULL, NULL, NULL, NULL)
== ERROR_SUCCESS) == ERROR_SUCCESS)
{ {
char pathbuf[PKG_CONFIG_PATH_SZ]; char pathbuf[PKGCONF_ITEM_SIZE];
DWORD type; DWORD type;
DWORD pathbuflen = sizeof pathbuf; DWORD pathbuflen = sizeof pathbuf;
@ -669,7 +667,7 @@ pkgconf_pkg_find_in_registry_key(pkgconf_client_t *client, HKEY hkey, const char
pkgconf_pkg_t * pkgconf_pkg_t *
pkgconf_pkg_find(pkgconf_client_t *client, const char *name) pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
{ {
char pathbuf[PKGCONF_BUFSIZE]; char pathbuf[PKGCONF_ITEM_SIZE];
pkgconf_pkg_t *pkg = NULL; pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *n; pkgconf_node_t *n;
FILE *f; FILE *f;
@ -749,7 +747,7 @@ int
pkgconf_compare_version(const char *a, const char *b) pkgconf_compare_version(const char *a, const char *b)
{ {
char oldch1, oldch2; char oldch1, oldch2;
char buf1[PKGCONF_BUFSIZE], buf2[PKGCONF_BUFSIZE]; char buf1[PKGCONF_ITEM_SIZE], buf2[PKGCONF_ITEM_SIZE];
char *str1, *str2; char *str1, *str2;
char *one, *two; char *one, *two;
int ret; int ret;

View File

@ -49,11 +49,18 @@
# else # else
# include <dirent.h> # include <dirent.h>
# endif # endif
# define PKGCONF_ITEM_SIZE (_MAX_PATH + 1024)
#else #else
# define PATH_DEV_NULL "/dev/null" # define PATH_DEV_NULL "/dev/null"
# define SIZE_FMT_SPECIFIER "%zu" # define SIZE_FMT_SPECIFIER "%zu"
# include <dirent.h> # include <dirent.h>
# include <unistd.h> # include <unistd.h>
# include <limits.h>
# ifdef PATH_MAX
# define PKGCONF_ITEM_SIZE (PATH_MAX + 1024)
# else
# define PKGCONF_ITEM_SIZE (4096 + 1024)
# endif
#endif #endif
#endif #endif

View File

@ -231,7 +231,7 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
*bptr++ = *ptr; *bptr++ = *ptr;
else if (*(ptr + 1) == '{') else if (*(ptr + 1) == '{')
{ {
char varname[PKGCONF_BUFSIZE]; char varname[PKGCONF_ITEM_SIZE];
char *vptr = varname; char *vptr = varname;
const char *pptr; const char *pptr;
char *kv, *parsekv; char *kv, *parsekv;
@ -296,7 +296,7 @@ pkgconf_tuple_parse(const pkgconf_client_t *client, pkgconf_list_t *vars, const
strlen(buf) > strlen(client->sysroot_dir) && strlen(buf) > strlen(client->sysroot_dir) &&
strstr(buf + strlen(client->sysroot_dir), client->sysroot_dir) != NULL) strstr(buf + strlen(client->sysroot_dir), client->sysroot_dir) != NULL)
{ {
char cleanpath[PKGCONF_BUFSIZE]; char cleanpath[PKGCONF_ITEM_SIZE];
pkgconf_strlcpy(cleanpath, buf + strlen(client->sysroot_dir), sizeof cleanpath); pkgconf_strlcpy(cleanpath, buf + strlen(client->sysroot_dir), sizeof cleanpath);
pkgconf_path_relocate(cleanpath, sizeof cleanpath); pkgconf_path_relocate(cleanpath, sizeof cleanpath);