From: Alejandro Colomar Date: Fri, 10 Feb 2023 21:52:25 +0000 (+0100) Subject: Use stpecpy() where appropriate X-Git-Tag: 4.14.0-rc1~178 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5956cea1d18b269fc4c0b1201b4e81a6f03bbe70;p=thirdparty%2Fshadow.git 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 --- diff --git a/src/groupmod.c b/src/groupmod.c index ee6c3e6c1..a2facfb80 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); - - 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); + gr = stpecpy(gr, gr_end, ", new gid: "); + stpeprintf(gr, gr_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