mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
chcp: Use macro S_ISDIR() to test type of file
Testing whether a file is a directory by comparing the struct stat
field st_mode against S_IFDIR is wrong. If st_mode has any access
permission bits set along with the file type code the test will always
fail.
The file type encoded in the struct stat field st_mode is actually an
enumeration. To test whether a file is a directory either extract the
file type from st_mode using the mask S_IFMT and compare it against
S_IFDIR or simply use the macro S_ISDIR().
Fixes: b627b8d8e1 ("Initial s390-tools-2.0.0 import")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Provide main function and command line parsing.
|
||||
*
|
||||
* Copyright IBM Corp. 2016, 2017
|
||||
* Copyright IBM Corp. 2016, 2019
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
@@ -236,7 +236,7 @@ static char *get_chp_dir(int css, int id)
|
||||
char *path;
|
||||
|
||||
path = util_path_sysfs("devices/css%x/chp%x.%x", css, css, id);
|
||||
if ((stat(path, &sb) == 0) && (sb.st_mode == S_IFDIR))
|
||||
if ((stat(path, &sb) == 0) && S_ISDIR(sb.st_mode))
|
||||
return path;
|
||||
free(path);
|
||||
return util_path_sysfs("devices/css%x/chp%x.%02x", css, css, id);
|
||||
@@ -296,7 +296,7 @@ static void perform_command(int css, int id)
|
||||
char *path;
|
||||
|
||||
path = get_chp_dir(css, id);
|
||||
if ((stat(path, &sb) != 0) || ((sb.st_mode & S_IFMT) != S_IFDIR)) {
|
||||
if ((stat(path, &sb) != 0) || !S_ISDIR(sb.st_mode)) {
|
||||
printf("Skipping unknown channel-path %x.%02x\n", css, id);
|
||||
goto out_free_path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user