ethumb - ensure buf is nul terminated

this SHOULD deal with CID 1039577  and CID 1039576
This commit is contained in:
Carsten Haitzler 2013-12-13 18:41:03 +09:00
parent a99bc89331
commit 75fbf9e03a
1 changed files with 8 additions and 3 deletions

View File

@ -698,13 +698,17 @@ _ethumb_build_absolute_path(const char *path, char buf[PATH_MAX])
p = buf;
if (path[0] == '/')
strcpy(p, path);
{
strncpy(p, path, PATH_MAX - 1);
p[PATH_MAX - 1] = 0;
}
else if (path[0] == '~')
{
const char *home = getenv("HOME");
if (!home)
return NULL;
strcpy(p, home);
strncpy(p, home, PATH_MAX - 1);
p[PATH_MAX - 1] = 0;
len = strlen(p);
p += len;
p[0] = '/';
@ -719,7 +723,8 @@ _ethumb_build_absolute_path(const char *path, char buf[PATH_MAX])
p += len;
p[0] = '/';
p++;
strcpy(p, path);
strncpy(p, path, PATH_MAX - 1 - len - 1);
p[PATH_MAX - 1 - len - 1] = 0;
}
return buf;