ibm-s390-linux / s390-tools

Tools for use with the s390 Linux kernel and device drivers
MIT License
63 stars 60 forks source link

lsqeth crashes if the qeth module is not loaded #43

Closed cohuck closed 6 years ago

cohuck commented 6 years ago

Running 'lsqeth' if the qeth driver is not loaded gives you:

free(): invalid pointer

and the core is dumped.

This code in main() (lsqeth.c) where it apparently crashes looks fishy:

                path = util_path_sysfs("bus/ccwgroup/drivers/qeth/");
                count = util_scandir(&de_vec, alphasort, path, "%s",
                                     ID_FORMAT);
                free(path);
                for (i = 0; i < count; i++) {
                        /* Check if a symbolic link */
                        if (de_vec[i]->d_type != DT_LNK)
                                continue;
                        if (i > 0)
                                rec = setup_rec();
                        print_device(rec, de_vec[i]->d_name);
                        free(rec);
                }
                util_scandir_free(de_vec, count);

If the qeth module is not loaded, /sys/bus/ccwgroup/drivers/qeth/ will not exist. Consequently, __scandir() when called by util_scandir()->scandir_regexp() will fail to open it and return -1 (even though the documentation states that util_scandir() returns a 'Number of returned directory entries', which seems to imply >= 0 to me). The code above does not seem to be prepared for handling count == -1.

Not sure where the best place to fix that is.

hoeppnerj commented 6 years ago

fyi, the just pushed fix addresses only the behaviour of util_ptr_vec_free(). I found numerous places in other tools that don't check for the util_scandir() return value as well. This will be addressed in another patch series.

Thanks for reporting!