From 5956cea1d18b269fc4c0b1201b4e81a6f03bbe70 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 10 Feb 2023 22:52:25 +0100 Subject: [PATCH] Use stpecpy() where appropriate This function simplifies the calculation of the bounds of the buffer for catenating strings. It would also reduce error checking, but we don't care about truncation in this specific code. :) Signed-off-by: Alejandro Colomar --- src/groupmod.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/groupmod.c b/src/groupmod.c index ee6c3e6c..a2facfb8 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -35,6 +35,7 @@ #include "sgroupio.h" #endif #include "shadowlog.h" +#include "stpecpy.h" #include "stpeprintf.h" /* * exit status values @@ -590,42 +591,27 @@ static void prepare_failure_reports (void) "group %s/%ju", group_name, (uintmax_t) group_id); if (nflg) { - strncat (info_group.action, ", new name: ", - 511 - strlen (info_group.audit_msg)); - strncat (info_group.action, group_newname, - 511 - strlen (info_group.audit_msg)); - + gr = stpecpy(gr, gr_end, ", new name: "); + gr = stpecpy(gr, gr_end, group_newname); #ifdef SHADOWGRP - strncat (info_gshadow.action, ", new name: ", - 511 - strlen (info_gshadow.audit_msg)); - strncat (info_gshadow.action, group_newname, - 511 - strlen (info_gshadow.audit_msg)); + sgr = stpecpy(sgr, sgr_end, ", new name: "); + sgr = stpecpy(sgr, sgr_end, group_newname); #endif - - strncat (info_passwd.action, ", new name: ", - 511 - strlen (info_passwd.audit_msg)); - strncat (info_passwd.action, group_newname, - 511 - strlen (info_passwd.audit_msg)); + pw = stpecpy(pw, pw_end, ", new name: "); + pw = stpecpy(pw, pw_end, group_newname); } if (pflg) { - strncat (info_group.action, ", new password", - 511 - strlen (info_group.audit_msg)); - + gr = stpecpy(gr, gr_end, ", new password"); #ifdef SHADOWGRP - strncat (info_gshadow.action, ", new password", - 511 - strlen (info_gshadow.audit_msg)); + sgr = stpecpy(sgr, sgr_end, ", new password"); #endif } if (gflg) { - strncat (info_group.action, ", new gid: ", - 511 - strlen (info_group.audit_msg)); - stpeprintf(info_group.action+strlen (info_group.action), - gr_end, "%ju", (uintmax_t) group_newid); + gr = stpecpy(gr, gr_end, ", new gid: "); + stpeprintf(gr, gr_end, "%ju", (uintmax_t) group_newid); - strncat (info_passwd.action, ", new gid: ", - 511 - strlen (info_passwd.audit_msg)); - stpeprintf(info_passwd.action+strlen (info_passwd.action), - pw_end, "%ju", (uintmax_t) group_newid); + pw = stpecpy(pw, pw_end, ", new gid: "); + stpeprintf(pw, pw_end, "%ju", (uintmax_t) group_newid); } // FIXME: add a system cleanup