1
0
mirror of https://git.code.sf.net/p/linux-ima/ima-evm-utils synced 2025-04-27 22:32:31 +02:00

libimaevm: Rename variable returned from readlink to len

The variable returned from readlink is a length indicator of the
number of bytes placed into a buffer, not only an error. Leave
a note in the code that a zero-length link is also treated as an
error, besides the usual -1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
Stefan Berger 2021-04-19 11:01:48 -04:00 committed by Mimi Zohar
parent 837591b81b
commit 3a28dd2721

View File

@ -213,15 +213,16 @@ static int add_dir_hash(const char *file, EVP_MD_CTX *ctx)
static int add_link_hash(const char *path, EVP_MD_CTX *ctx)
{
int err;
int len;
char buf[1024];
err = readlink(path, buf, sizeof(buf));
if (err <= 0)
len = readlink(path, buf, sizeof(buf));
/* 0-length links are also an error */
if (len <= 0)
return -1;
log_info("link: %s -> %.*s\n", path, err, buf);
return !EVP_DigestUpdate(ctx, buf, err);
log_info("link: %s -> %.*s\n", path, len, buf);
return !EVP_DigestUpdate(ctx, buf, len);
}
static int add_dev_hash(struct stat *st, EVP_MD_CTX *ctx)