fix path string stuff to not be able to overflow (unlikely tho - ever)

SVN revision: 33571
This commit is contained in:
Carsten Haitzler 2008-01-24 00:25:13 +00:00
parent 28a9a00d43
commit 7bc642aff1
1 changed files with 9 additions and 2 deletions

View File

@ -697,7 +697,11 @@ setconfig(char *root)
/* add the default "include" directory */
if (root != NULL)
strcpy(path, root); /* path + filename (hopefully) */
{
/* path + filename (hopefully) */
strncpy(path, root, sizeof(path) - 1);
path[sizeof(path) - 1] = 0;
}
/* terminate just behind last \ or : */
if ((ptr = strrchr(path, DIRSEP_CHAR)) != NULL
|| (ptr = strchr(path, ':')) != NULL)
@ -708,7 +712,10 @@ setconfig(char *root)
* to the list in that case
*/
*(ptr + 1) = '\0';
strcat(path, "include");
if (strlen(path) < (sizeof(path) - 1 - 7))
{
strcat(path, "include");
}
len = strlen(path);
path[len] = DIRSEP_CHAR;
path[len + 1] = '\0';