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 <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2023-02-10 22:52:25 +01:00 committed by Iker Pedrosa
parent 709e6b4497
commit 5956cea1d1

View File

@ -35,6 +35,7 @@
#include "sgroupio.h" #include "sgroupio.h"
#endif #endif
#include "shadowlog.h" #include "shadowlog.h"
#include "stpecpy.h"
#include "stpeprintf.h" #include "stpeprintf.h"
/* /*
* exit status values * exit status values
@ -590,42 +591,27 @@ static void prepare_failure_reports (void)
"group %s/%ju", group_name, (uintmax_t) group_id); "group %s/%ju", group_name, (uintmax_t) group_id);
if (nflg) { if (nflg) {
strncat (info_group.action, ", new name: ", gr = stpecpy(gr, gr_end, ", new name: ");
511 - strlen (info_group.audit_msg)); gr = stpecpy(gr, gr_end, group_newname);
strncat (info_group.action, group_newname,
511 - strlen (info_group.audit_msg));
#ifdef SHADOWGRP #ifdef SHADOWGRP
strncat (info_gshadow.action, ", new name: ", sgr = stpecpy(sgr, sgr_end, ", new name: ");
511 - strlen (info_gshadow.audit_msg)); sgr = stpecpy(sgr, sgr_end, group_newname);
strncat (info_gshadow.action, group_newname,
511 - strlen (info_gshadow.audit_msg));
#endif #endif
pw = stpecpy(pw, pw_end, ", new name: ");
strncat (info_passwd.action, ", new name: ", pw = stpecpy(pw, pw_end, group_newname);
511 - strlen (info_passwd.audit_msg));
strncat (info_passwd.action, group_newname,
511 - strlen (info_passwd.audit_msg));
} }
if (pflg) { if (pflg) {
strncat (info_group.action, ", new password", gr = stpecpy(gr, gr_end, ", new password");
511 - strlen (info_group.audit_msg));
#ifdef SHADOWGRP #ifdef SHADOWGRP
strncat (info_gshadow.action, ", new password", sgr = stpecpy(sgr, sgr_end, ", new password");
511 - strlen (info_gshadow.audit_msg));
#endif #endif
} }
if (gflg) { if (gflg) {
strncat (info_group.action, ", new gid: ", gr = stpecpy(gr, gr_end, ", new gid: ");
511 - strlen (info_group.audit_msg)); stpeprintf(gr, gr_end, "%ju", (uintmax_t) group_newid);
stpeprintf(info_group.action+strlen (info_group.action),
gr_end, "%ju", (uintmax_t) group_newid);
strncat (info_passwd.action, ", new gid: ", pw = stpecpy(pw, pw_end, ", new gid: ");
511 - strlen (info_passwd.audit_msg)); stpeprintf(pw, pw_end, "%ju", (uintmax_t) group_newid);
stpeprintf(info_passwd.action+strlen (info_passwd.action),
pw_end, "%ju", (uintmax_t) group_newid);
} }
// FIXME: add a system cleanup // FIXME: add a system cleanup