Skip to content

Commit

Permalink
lib: Fix t_get_working_dir() to properly allocate memory in data stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and GitLab committed Jan 30, 2017
1 parent 89bc31f commit f3370db
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib/path-util.c
Expand Up @@ -11,8 +11,8 @@
#define PATH_UTIL_MAX_PATH 8*1024
#define PATH_UTIL_MAX_SYMLINKS 80

static int t_getcwd_alloc(char **dir_r, size_t *asize_r,
const char **error_r) ATTR_NULL(2)
static int t_getcwd_noalloc(char **dir_r, size_t *asize_r,
const char **error_r) ATTR_NULL(2)
{
/* @UNSAFE */
char *dir;
Expand Down Expand Up @@ -48,7 +48,7 @@ static int path_normalize(const char *path, bool resolve_links,

if (path[0] != '/') {
/* relative; initialize npath with current directory */
if (t_getcwd_alloc(&npath, &asize, error_r) < 0)
if (t_getcwd_noalloc(&npath, &asize, error_r) < 0)
return -1;
npath_pos = npath + strlen(npath);
i_assert(npath[0] == '/');
Expand Down Expand Up @@ -304,9 +304,16 @@ const char *t_abspath_to(const char *path, const char *root)

int t_get_working_dir(const char **dir_r, const char **error_r)
{
char *dir;

i_assert(dir_r != NULL);
i_assert(error_r != NULL);
return t_getcwd_alloc((char**)dir_r, NULL, error_r);
if (t_getcwd_noalloc(&dir, NULL, error_r) < 0)
return -1;

t_buffer_alloc(strlen(dir) + 1);
*dir_r = dir;
return 0;
}

int t_readlink(const char *path, const char **dest_r, const char **error_r)
Expand Down

0 comments on commit f3370db

Please sign in to comment.