Skip to content

Commit

Permalink
serial.c: make sure procentry->d_name fits in procpath
Browse files Browse the repository at this point in the history
  • Loading branch information
garyemiller committed Feb 9, 2018
1 parent fa47f73 commit b6717c8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,17 @@ static int fusercount(const char *path)
{
DIR *procd, *fdd;
struct dirent *procentry, *fdentry;
char procpath[32], fdpath[64], linkpath[64];
char procpath[64], fdpath[64], linkpath[64];
int cnt = 0;

if ((procd = opendir("/proc")) == NULL)
return -1;
while ((procentry = readdir(procd)) != NULL) {
if (isdigit(procentry->d_name[0])==0)
continue;
/* longest procentry->d_name I could find was 12 */
(void)snprintf(procpath, sizeof(procpath),
"/proc/%s/fd/", procentry->d_name);
"/proc/%.20s/fd/", procentry->d_name);
if ((fdd = opendir(procpath)) == NULL)
continue;
while ((fdentry = readdir(fdd)) != NULL) {
Expand Down

0 comments on commit b6717c8

Please sign in to comment.