From a6507b330d05a3033837768a54ce9959c2a84870 Mon Sep 17 00:00:00 2001 From: Jens Remus Date: Fri, 7 Jun 2019 14:12:24 +0200 Subject: [PATCH] zkey: Use macro S_ISDIR() to test type of file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: c944f23d7e1f ("zkey: Add keystore implementation") Signed-off-by: Jens Remus Acked-by: Ingo Franzki Signed-off-by: Jan Höppner --- zkey/keystore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zkey/keystore.c b/zkey/keystore.c index 33c8f936..271e08b8 100644 --- a/zkey/keystore.c +++ b/zkey/keystore.c @@ -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; }