From 5f2bd3bdacc0f62ccc6cd03c9b7bfb0b9a9518dc Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Mon, 24 Apr 2017 14:56:41 +0000 Subject: [PATCH] scandir(3): promote arraysz to size_t to match numitems. The internal array size goes through a loop and is compared with numitems which at its limits makes can be unreachably higher than arraysz. Prevent an hypothetical overflow by matching the types. MFC after: 1 week --- lib/libc/gen/scandir.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 2382cb03290b..00183b61de73 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -82,8 +82,7 @@ scandir(const char *dirname, struct dirent ***namelist, #endif { struct dirent *d, *p, **names = NULL; - size_t numitems; - long arraysz; + size_t arraysz, numitems; DIR *dirp; if ((dirp = opendir(dirname)) == NULL)