Fix buffer overflow in which(1).

This commit is contained in:
Jonas 'Sortie' Termansen 2014-05-12 19:09:46 +02:00
parent 0f80611403
commit 812d071481
1 changed files with 2 additions and 1 deletions

View File

@ -61,7 +61,8 @@ bool Which(const char* cmd, const char* path, bool all)
error(1, errno, "malloc");
memcpy(dirname, path, len * sizeof(char));
dirname[len] = '\0';
path += len + 1;
if ( (path += len)[0] == ':' )
path++;
int dirfd = open(dirname, O_RDONLY | O_DIRECTORY);
if ( dirfd < 0 )
{