@@ -45,7 +45,7 @@ typedef int (*selabel_initfunc)(struct selabel_handle *rec,
const struct selinux_opt *opts,
unsigned nopts);
-static selabel_initfunc initfuncs[] = {
+static const selabel_initfunc initfuncs[] = {
&selabel_file_init,
CONFIG_MEDIA_BACKEND(selabel_media_init),
CONFIG_X_BACKEND(selabel_x_init),
@@ -56,8 +56,7 @@ static selabel_initfunc initfuncs[] = {
static inline struct selabel_digest *selabel_is_digest_set
(const struct selinux_opt *opts,
- unsigned n,
- struct selabel_digest *entry)
+ unsigned n)
{
struct selabel_digest *digest = NULL;
@@ -77,8 +76,7 @@ static inline struct selabel_digest *selabel_is_digest_set
if (!digest->specfile_list)
goto err;
- entry = digest;
- return entry;
+ return digest;
}
}
return NULL;
@@ -121,7 +119,7 @@ static inline int selabel_is_validate_set(const struct selinux_opt *opts,
return 0;
}
-int selabel_validate(struct selabel_handle *rec,
+int selabel_validate(const struct selabel_handle *rec,
struct selabel_lookup_rec *contexts)
{
int rc = 0;
@@ -133,7 +131,7 @@ int selabel_validate(struct selabel_handle *rec,
if (rc < 0)
goto out;
- contexts->validated = 1;
+ contexts->validated = true;
out:
return rc;
}
@@ -215,15 +213,14 @@ struct selabel_handle *selabel_open(unsigned int backend,
goto out;
}
- rec = (struct selabel_handle *)malloc(sizeof(*rec));
+ rec = (struct selabel_handle *)calloc(1, sizeof(*rec));
if (!rec)
goto out;
- memset(rec, 0, sizeof(*rec));
rec->backend = backend;
rec->validating = selabel_is_validate_set(opts, nopts);
- rec->digest = selabel_is_digest_set(opts, nopts, rec->digest);
+ rec->digest = selabel_is_digest_set(opts, nopts);
if ((*initfuncs[backend])(rec, opts, nopts)) {
if (rec->digest)
@@ -63,7 +63,7 @@ struct selabel_digest {
};
extern int digest_add_specfile(struct selabel_digest *digest, FILE *fp,
- char *from_addr,
+ const char *from_addr,
size_t buf_len,
const char *path);
extern void digest_gen_hash(struct selabel_digest *digest);
@@ -118,7 +118,7 @@ struct selabel_handle {
* Validation function
*/
extern int
-selabel_validate(struct selabel_handle *rec,
+selabel_validate(const struct selabel_handle *rec,
struct selabel_lookup_rec *contexts) ;
/*
@@ -136,7 +136,7 @@ extern void __attribute__ ((format(printf, 1, 2)))
} while (0)
extern int
-compat_validate(struct selabel_handle *rec,
+compat_validate(const struct selabel_handle *rec,
struct selabel_lookup_rec *contexts,
const char *path, unsigned lineno) ;
@@ -10,7 +10,6 @@
#include <string.h>
#include <stdio.h>
#include <errno.h>
-#include <errno.h>
#include "label_internal.h"
/*
@@ -138,7 +137,6 @@ void digest_gen_hash(struct selabel_digest *digest)
Sha1Finalise(&context, (SHA1_HASH *)digest->digest);
free(digest->hashbuf);
digest->hashbuf = NULL;
- return;
}
/**
@@ -154,7 +152,7 @@ void digest_gen_hash(struct selabel_digest *digest)
* Return %0 on success, -%1 with @errno set on failure.
*/
int digest_add_specfile(struct selabel_digest *digest, FILE *fp,
- char *from_addr, size_t buf_len,
+ const char *from_addr, size_t buf_len,
const char *path)
{
unsigned char *tmp_buf;
@@ -35,7 +35,7 @@ void set_matchpathcon_printf(void (*f) (const char *fmt, ...))
myprintf_compat = 1;
}
-int compat_validate(struct selabel_handle *rec,
+int compat_validate(const struct selabel_handle *rec,
struct selabel_lookup_rec *contexts,
const char *path, unsigned lineno)
{
Drop unused parameter from selabel_is_digest_set(). It is only written to but writes to the function local copy of the pointer are void. Constify read-only handle parameter of selabel_validate() and compat_validate(). Constify read-only from-address parameter of digest_add_specfile(). Constify read-only function pointer array initfuncs. Merge malloc(3) and memset(3) calls into calloc(3). Simplify boolean assignment. Drop duplicate include file. Drop return at end of void function. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- libselinux/src/label.c | 17 +++++++---------- libselinux/src/label_internal.h | 6 +++--- libselinux/src/label_support.c | 4 +--- libselinux/src/matchpathcon.c | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-)