Skip to content

Commit

Permalink
Do some code cleanups from static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
RH-steve-grubb committed May 25, 2020
1 parent 005fcc1 commit dc5c031
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 174 deletions.
10 changes: 5 additions & 5 deletions audisp/audispd-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void start_watching(void)
watching = 1;
}

static int create_af_unix_socket(const char *path, int mode)
static int create_af_unix_socket(const char *spath, int mode)
{
struct sockaddr_un addr;
socklen_t len;
Expand All @@ -113,7 +113,7 @@ static int create_af_unix_socket(const char *path, int mode)
}
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
snprintf(&addr.sun_path[0], 108, "%.107s", path);
snprintf(&addr.sun_path[0], 108, "%.107s", spath);
len = sizeof(addr);
rc = bind(sock, (const struct sockaddr *)&addr, len);
if (rc < 0) {
Expand All @@ -122,11 +122,11 @@ static int create_af_unix_socket(const char *path, int mode)
destroy_af_unix();
return -1;
}
if (mode != -1) {
rc = chmod(path, mode);
if (mode != -1) {
rc = chmod(spath, mode);
if (rc < 0) {
syslog(LOG_ERR, "Couldn't chmod %s to %04o (%s)",
path, mode, strerror(errno));
spath, mode, strerror(errno));
destroy_af_unix();
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion audisp/plugins/remote/audisp-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ static int recv_token(int s, gss_buffer_t tok)
}

/* Same here. */
int send_token(int s, gss_buffer_t tok)
static int send_token(int s, gss_buffer_t tok)
{
int ret;
unsigned char lenbuf[4];
Expand Down
10 changes: 5 additions & 5 deletions auparse/ellist.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,22 @@ static int parse_up_record(rnode* r)
if (*n.val == '"')
nvlist_append(&r->nv, &n);
else {
char *key, *ptr, *saved2;
char *key, *ptr2, *saved2;

key = (char *)au_unescape(n.val);
if (key == NULL) {
// Malformed key - save as is
nvlist_append(&r->nv, &n);
continue;
}
ptr = strtok_r(key, key_sep, &saved2);
ptr2 = strtok_r(key, key_sep, &saved2);
free(n.name);
free(n.val);
while (ptr) {
while (ptr2) {
n.name = strdup("key");
n.val = escape(ptr);
n.val = escape(ptr2);
nvlist_append(&r->nv, &n);
ptr = strtok_r(NULL,
ptr2 = strtok_r(NULL,
key_sep, &saved2);
}
free(key);
Expand Down
47 changes: 22 additions & 25 deletions auparse/interpret.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,16 @@ static void escape(const char *s, char *dest, unsigned int len,
switch (escape_mode)
{
case AUPARSE_ESC_RAW:
return;
break;
case AUPARSE_ESC_TTY:
return tty_escape(s, dest, len);
tty_escape(s, dest, len);
break;
case AUPARSE_ESC_SHELL:
return shell_escape(s, dest, len);
shell_escape(s, dest, len);
break;
case AUPARSE_ESC_SHELL_QUOTE:
return shell_quote_escape(s, dest, len);
shell_quote_escape(s, dest, len);
break;
}
}

Expand Down Expand Up @@ -502,13 +505,10 @@ static const char *aulookup_success(int s)
{
default:
return success[0];
break;
case S_FAILED:
return success[1];
break;
case S_SUCCESS:
return success[2];
break;
}
}

Expand Down Expand Up @@ -698,10 +698,10 @@ static const char *print_ipccall(const char *val, unsigned int base)
errno = 0;
a0 = strtol(val, NULL, base);
if (errno) {
char *out;
if (asprintf(&out, "conversion error(%s)", val) < 0)
out = NULL;
return out;
char *out2;
if (asprintf(&out2, "conversion error(%s)", val) < 0)
out2 = NULL;
return out2;
}
func = ipc_i2s(a0);
if (func)
Expand All @@ -722,10 +722,10 @@ static const char *print_socketcall(const char *val, unsigned int base)
errno = 0;
a0 = strtol(val, NULL, base);
if (errno) {
char *out;
if (asprintf(&out, "conversion error(%s)", val) < 0)
out = NULL;
return out;
char *out2;
if (asprintf(&out2, "conversion error(%s)", val) < 0)
out2 = NULL;
return out2;
}
func = sock_i2s(a0);
if (func)
Expand Down Expand Up @@ -1124,7 +1124,7 @@ static const char *print_sockaddr(const char *val)
case AF_LOCAL:
{
const struct sockaddr_un *un =
(struct sockaddr_un *)saddr;
(const struct sockaddr_un *)saddr;
if (un->sun_path[0])
rc = asprintf(&out,
"{ saddr_fam=%s path=%s }", str,
Expand Down Expand Up @@ -1157,7 +1157,7 @@ static const char *print_sockaddr(const char *val)
case AF_AX25:
{
const struct sockaddr_ax25 *x =
(struct sockaddr_ax25 *)saddr;
(const struct sockaddr_ax25 *)saddr;
rc = asprintf(&out,
"{ saddr_fam=%s call=%c%c%c%c%c%c%c }",
str,
Expand All @@ -1173,7 +1173,7 @@ static const char *print_sockaddr(const char *val)
case AF_IPX:
{
const struct sockaddr_ipx *ip =
(struct sockaddr_ipx *)saddr;
(const struct sockaddr_ipx *)saddr;
rc = asprintf(&out,
"{ saddr_fam=%s lport=%d ipx-net=%u }",
str, ip->sipx_port, ip->sipx_network);
Expand All @@ -1182,15 +1182,15 @@ static const char *print_sockaddr(const char *val)
case AF_ATMPVC:
{
const struct sockaddr_atmpvc* at =
(struct sockaddr_atmpvc *)saddr;
(const struct sockaddr_atmpvc *)saddr;
rc = asprintf(&out, "{ saddr_fam=%s int=%d }", str,
at->sap_addr.itf);
}
break;
case AF_X25:
{
const struct sockaddr_x25* x =
(struct sockaddr_x25 *)saddr;
(const struct sockaddr_x25 *)saddr;
rc = asprintf(&out, "{ saddr_fam=%s laddr=%.15s }",
str, x->sx25_addr.x25_addr);
}
Expand All @@ -1217,7 +1217,7 @@ static const char *print_sockaddr(const char *val)
case AF_NETLINK:
{
const struct sockaddr_nl *n =
(struct sockaddr_nl *)saddr;
(const struct sockaddr_nl *)saddr;
rc = asprintf(&out,
"{ saddr_fam=%s nlnk-fam=%u nlnk-pid=%u }",
str, n->nl_family, n->nl_pid);
Expand Down Expand Up @@ -2146,13 +2146,10 @@ static const char *aulookup_fanotify(unsigned s)
{
default:
return fanotify[0];
break;
case FAN_ALLOW:
return fanotify[1];
break;
case FAN_DENY:
return fanotify[2];
break;
}
}

Expand All @@ -2162,7 +2159,7 @@ static const char *print_fanotify(const char *val)

if (isdigit(*val)) {
errno = 0;
res = strtoul(val, NULL, 10);
res = strtoul(val, NULL, 10);
if (errno) {
char *out;
if (asprintf(&out, "conversion error(%s)", val) < 0)
Expand Down
2 changes: 1 addition & 1 deletion auparse/normalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static void collect_own_obj2(auparse_state_t *au, const char *syscall)

static void collect_id_obj2(auparse_state_t *au, const char *syscall)
{
unsigned int limit, cnt = 1;;
unsigned int limit, cnt = 1;

if (strcmp(syscall, "setuid") == 0)
limit = 1;
Expand Down
2 changes: 1 addition & 1 deletion common/audit-fgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int audit_fgets_more(size_t blen)
int audit_fgets(char *buf, size_t blen, int fd)
{
int complete = 0;
size_t line_len;
size_t line_len = 0;
char *line_end = NULL;

assert(blen != 0);
Expand Down
17 changes: 9 additions & 8 deletions src/auditctl-listing.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ static void print_rule(const struct audit_rule_data *r)
free(rkey);
} else if (field == AUDIT_PERM) {
char perms[5];
int val=r->values[i];
unsigned int val=r->values[i];
perms[0] = 0;
if (val & AUDIT_PERM_READ)
strcat(perms, "r");
Expand Down Expand Up @@ -482,7 +482,7 @@ void audit_print_init(void)
list_create(&l);
}

const char *get_enable(unsigned e)
static const char *get_enable(unsigned e)
{
switch (e)
{
Expand All @@ -497,7 +497,7 @@ const char *get_enable(unsigned e)
}
}

const char *get_failure(unsigned f)
static const char *get_failure(unsigned f)
{
switch (f)
{
Expand All @@ -515,11 +515,11 @@ const char *get_failure(unsigned f)
/*
* This function interprets the reply and prints it to stdout. It returns
* 0 if no more should be read and 1 to indicate that more messages of this
* type may need to be read.
* type may need to be read.
*/
int audit_print_reply(struct audit_reply *rep, int fd)
{
_audit_elf = 0;
_audit_elf = 0;

switch (rep->type) {
case NLMSG_NOOP:
Expand All @@ -540,9 +540,9 @@ int audit_print_reply(struct audit_reply *rep, int fd)
list_clear(&l);
}
break;
case NLMSG_ERROR:
case NLMSG_ERROR:
printf("NLMSG_ERROR %d (%s)\n",
-rep->error->error,
-rep->error->error,
strerror(-rep->error->error));
printed = 1;
break;
Expand Down Expand Up @@ -571,7 +571,8 @@ int audit_print_reply(struct audit_reply *rep, int fd)
defined(HAVE_STRUCT_AUDIT_STATUS_FEATURE_BITMAP)
case AUDIT_GET_FEATURE:
{
uint32_t mask = AUDIT_FEATURE_TO_MASK(AUDIT_FEATURE_LOGINUID_IMMUTABLE);
uint32_t mask = AUDIT_FEATURE_TO_MASK(
AUDIT_FEATURE_LOGINUID_IMMUTABLE);
if (rep->features->mask & mask)
printf("loginuid_immutable %u %s\n",
!!(rep->features->features & mask),
Expand Down
Loading

0 comments on commit dc5c031

Please sign in to comment.