Skip to content

Commit

Permalink
libselinux/utils/selabel_digest: cleanup
Browse files Browse the repository at this point in the history
Avoid global variable.
Constify read-only parameters.

Signed-off-by: Christian Göttsche <[email protected]>
Acked-by: James Carter <[email protected]>
  • Loading branch information
cgzones authored and jwcart2 committed Mar 20, 2024
1 parent c774f15 commit 5f5edd4
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions libselinux/utils/selabel_digest.c
Expand Up @@ -6,8 +6,6 @@
#include <selinux/selinux.h>
#include <selinux/label.h>

static size_t digest_len;

static __attribute__ ((__noreturn__)) void usage(const char *progname)
{
fprintf(stderr,
Expand All @@ -25,11 +23,11 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname)
exit(1);
}

static int run_check_digest(char *cmd, char *selabel_digest)
static int run_check_digest(const char *cmd, const char *selabel_digest, size_t digest_len)
{
FILE *fp;
char files_digest[128];
char *files_ptr;
const char *files_ptr;
int rc = 0;

fp = popen(cmd, "r");
Expand Down Expand Up @@ -64,7 +62,7 @@ int main(int argc, char **argv)
char *baseonly = NULL, *file = NULL, *digest = (char *)1;
char **specfiles = NULL;
unsigned char *sha1_digest = NULL;
size_t i, num_specfiles;
size_t digest_len, i, num_specfiles;

char cmd_buf[4096];
char *cmd_ptr;
Expand Down Expand Up @@ -181,7 +179,7 @@ int main(int argc, char **argv)
sprintf(cmd_ptr, "| /usr/bin/openssl dgst -sha1 -hex");

if (validate)
rc = run_check_digest(cmd_buf, sha1_buf);
rc = run_check_digest(cmd_buf, sha1_buf, digest_len);
}

free(sha1_buf);
Expand Down

0 comments on commit 5f5edd4

Please sign in to comment.