mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zkey: Use macro S_ISDIR() to test type of file
Testing whether a file is a directory by masking the struct stat field
st_mode with S_IFDIR is wrong. Depending on the values of the macros
S_IF* block special devices might be considered as directories.
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: c944f23d7e ("zkey: Add keystore implementation")
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Acked-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Keystore handling functions
|
||||
*
|
||||
* Copyright IBM Corp. 2018
|
||||
* Copyright IBM Corp. 2018, 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.
|
||||
@@ -1378,7 +1378,7 @@ struct keystore *keystore_new(const char *directory, bool verbose)
|
||||
warnx("Can not access '%s': %s", directory, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
if (!(sb.st_mode & S_IFDIR)) {
|
||||
if (!S_ISDIR(sb.st_mode)) {
|
||||
warnx("'%s' is not a directory", directory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user