Skip to content

Commit

Permalink
app: return dynamicatty allocated string if too long
Browse files Browse the repository at this point in the history
  • Loading branch information
ImeevMA committed Aug 24, 2023
1 parent 7f31935 commit f67e568
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ cfg_gets(const char *param)
return val;
}

char *
cfg_gets_dynamic(const char *param)
{
cfg_get(param);
if (lua_isnil(tarantool_L, -1))
return NULL;
const char *str = lua_tostring(tarantool_L, -1);
size_t size = strlen(str) + 1;
char *res = xmalloc(size);
memcpy(res, str, size);
lua_pop(tarantool_L, 1);
return res;
}

double
cfg_getd(const char *param)
{
Expand Down
8 changes: 8 additions & 0 deletions src/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ cfg_geti64(const char *param);
const char *
cfg_gets(const char *param);

/**
* Returns a dynamically allocated string. Unlike the result of cfg_gets(), the
* result of this function should be freed. This string may be longer than
* MAX_OPT_VAL_LEN.
*/
char *
cfg_gets_dynamic(const char *param);

double
cfg_getd(const char *param);

Expand Down
3 changes: 2 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ load_cfg(void)
if (work_dir != NULL && chdir(work_dir) == -1)
panic_syserror("can't chdir to `%s'", work_dir);

const char *username = cfg_gets("username");
char *username = cfg_gets_dynamic("username");
if (username != NULL) {
if (getuid() == 0 || geteuid() == 0) {
struct passwd *pw;
Expand All @@ -387,6 +387,7 @@ load_cfg(void)
username);
}
}
free(username);

if (cfg_geti("coredump")) {
struct rlimit c = { 0, 0 };
Expand Down

0 comments on commit f67e568

Please sign in to comment.