SERIAL: Avoid potential SEGFAULT when scandir() fails on Linux
This commit is contained in:
parent
6a99ac81c6
commit
914d79c980
1 changed files with 2 additions and 2 deletions
|
@ -952,12 +952,12 @@ int ports = 0;
|
||||||
memset(list, 0, max*sizeof(*list));
|
memset(list, 0, max*sizeof(*list));
|
||||||
#if defined(__linux) || defined(__linux__)
|
#if defined(__linux) || defined(__linux__)
|
||||||
if (1) {
|
if (1) {
|
||||||
struct dirent **namelist;
|
struct dirent **namelist = NULL;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
i = scandir("/sys/class/tty/", &namelist, NULL, NULL);
|
i = scandir("/sys/class/tty/", &namelist, NULL, NULL);
|
||||||
|
|
||||||
while (i--) {
|
while (0 < i--) {
|
||||||
if (strcmp(namelist[i]->d_name, ".") &&
|
if (strcmp(namelist[i]->d_name, ".") &&
|
||||||
strcmp(namelist[i]->d_name, "..")) {
|
strcmp(namelist[i]->d_name, "..")) {
|
||||||
char path[1024], devicepath[1024], driverpath[1024];
|
char path[1024], devicepath[1024], driverpath[1024];
|
||||||
|
|
Loading…
Add table
Reference in a new issue