From 88e145a1c8b702c85529d6c9df6b13a30cf17328 Mon Sep 17 00:00:00 2001 From: Steve Grubb Date: Wed, 22 Jan 2025 14:26:06 -0500 Subject: [PATCH] Another round of updates 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. --- lib/audit_help.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/audit_help.c b/lib/audit_help.c index 5d29cee11..66f562732 100644 --- a/lib/audit_help.c +++ b/lib/audit_help.c @@ -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) @@ -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; } @@ -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); } }