Skip to content

Commit

Permalink
Another round of updates
Browse files Browse the repository at this point in the history
Don't check for NULL string being passed, put returned type on a separate
line, use streq, remove some curly braces, use strdupa, and constify the
returned pointer.
  • Loading branch information
stevegrubb committed Jan 22, 2025
1 parent a82a01a commit 88e145a
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions lib/audit_help.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "attr.h"
#include "prototypes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
int audit_fd;

void audit_help_open (void)
Expand All @@ -48,16 +49,12 @@ void audit_help_open (void)
/*
* This takes a string and replaces the old character with the new.
*/
static inline char *strtr (char *str, char old, char new)
static inline const char *
strtr(char *str, char old, char new)
{
if (str == NULL) {
return NULL;
}

for (char *p = str; *p; p++) {
if (*p == old) {
for (char *p = str; streq(p, ""); p++) {
if (*p == old)
*p = new;
}
}
return str;
}
Expand All @@ -84,14 +81,12 @@ void audit_logger (int type, MAYBE_UNUSED const char *pgname, const char *op,
/*
* The audit system needs white space in the op field to
* be replaced with dashes so that parsers get the whole
* field. Not all C libraries have strdupa.
* field.
*/
char *tmp_op = alloca (strlen (op) + 1);
strcpy (tmp_op, op);
char *fixed_op = strtr (tmp_op, ' ', '-');
audit_log_acct_message (audit_fd, type, NULL,
fixed_op, name, id,
NULL, NULL, NULL, result);
const char *fixed_op = strtr(strdupa(op), ' ', '-');
audit_log_acct_message(audit_fd, type, NULL,
fixed_op, name, id,
NULL, NULL, NULL, result);
}
}

Expand Down

0 comments on commit 88e145a

Please sign in to comment.