Commit 68aab864 authored by Jussi Kivilinna's avatar Jussi Kivilinna Committed by Pekka Niemimaa
Browse files

apps/nshlib: nsh_fscmds: fix corrupting one memory byte with 'ls' and 'cp'



g_iobuffer[MAX_PATH] accesses memory beyond g_iobuffer is not large enough.
Signed-off-by: default avatarJussi Kivilinna <jussi.kivilinna@haltian.com>
parent 2f15cfb8
......@@ -147,19 +147,26 @@ static void trim_dir(char *arg)
#if CONFIG_NFILE_DESCRIPTORS > 0
static char *nsh_getdirpath(const char *path, const char *file)
{
char *dirpath = NULL;
int ret;
/* Handle the case where all that is left is '/' */
if (strcmp(path, "/") == 0)
{
sprintf(g_iobuffer, "/%s", file);
ret = asprintf(&dirpath, "/%s", file);
}
else
{
sprintf(g_iobuffer, "%s/%s", path, file);
ret = asprintf(&dirpath, "%s/%s", path, file);
}
if (ret < 0)
{
dirpath = NULL;
}
g_iobuffer[PATH_MAX] = '\0';
return strdup(g_iobuffer);
return dirpath;
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment