[PATCH 03/21] crypto: replace stat() with access() for credential checks

Daniel P. Berrangé posted 21 patches 2 weeks, 1 day ago
Only 6 patches received!
There is a newer version of this series
[PATCH 03/21] crypto: replace stat() with access() for credential checks
Posted by Daniel P. Berrangé 2 weeks, 1 day ago
Readability of the credential files is what matters for our usage,
so access() is more appropriate than stat().

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 crypto/tlscreds.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c
index 9e59594d67..208a7e6d8f 100644
--- a/crypto/tlscreds.c
+++ b/crypto/tlscreds.c
@@ -100,7 +100,6 @@ qcrypto_tls_creds_get_path(QCryptoTLSCreds *creds,
                            char **cred,
                            Error **errp)
 {
-    struct stat sb;
     int ret = -1;
 
     if (!creds->dir) {
@@ -114,7 +113,7 @@ qcrypto_tls_creds_get_path(QCryptoTLSCreds *creds,
 
     *cred = g_strdup_printf("%s/%s", creds->dir, filename);
 
-    if (stat(*cred, &sb) < 0) {
+    if (access(*cred, R_OK) < 0) {
         if (errno == ENOENT && !required) {
             ret = 0;
         } else {
-- 
2.51.1


Re: [PATCH 03/21] crypto: replace stat() with access() for credential checks
Posted by Marc-André Lureau 2 weeks ago
Hi

On Thu, Oct 30, 2025 at 6:48 PM Daniel P. Berrangé <berrange@redhat.com>
wrote:

> Readability of the credential files is what matters for our usage,
> so access() is more appropriate than stat().
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  crypto/tlscreds.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/crypto/tlscreds.c b/crypto/tlscreds.c
> index 9e59594d67..208a7e6d8f 100644
> --- a/crypto/tlscreds.c
> +++ b/crypto/tlscreds.c
> @@ -100,7 +100,6 @@ qcrypto_tls_creds_get_path(QCryptoTLSCreds *creds,
>                             char **cred,
>                             Error **errp)
>  {
> -    struct stat sb;
>      int ret = -1;
>
>      if (!creds->dir) {
> @@ -114,7 +113,7 @@ qcrypto_tls_creds_get_path(QCryptoTLSCreds *creds,
>
>      *cred = g_strdup_printf("%s/%s", creds->dir, filename);
>
> -    if (stat(*cred, &sb) < 0) {
> +    if (access(*cred, R_OK) < 0) {
>          if (errno == ENOENT && !required) {
>              ret = 0;
>          } else {
> --
> 2.51.1
>
>