strcmp(pw->pw_name, e->e_from.q_user) == 0 &&
!internal)
{
- buildfname(pw->pw_gecos, e->e_from.q_user, buf);
+ buildfname(pw->pw_gecos, e->e_from.q_user,
+ buf, sizeof buf);
if (buf[0] != '\0')
FullName = newstr(buf);
}
a->q_gid = pw->pw_gid;
a->q_ruser = newstr(pw->pw_name);
a->q_flags |= QGOODUID;
- buildfname(pw->pw_gecos, pw->pw_name, nbuf);
+ buildfname(pw->pw_gecos, pw->pw_name, nbuf, sizeof nbuf);
if (nbuf[0] != '\0')
a->q_fullname = newstr(nbuf);
if (!usershellok(pw->pw_name, pw->pw_shell))
}
# endif
- buildfname(pw->pw_gecos, pw->pw_name, buf);
+ buildfname(pw->pw_gecos, pw->pw_name, buf, sizeof buf);
if (strchr(buf, ' ') != NULL && !strcasecmp(buf, name))
{
if (tTd(29, 4))
*/
void
-buildfname(gecos, login, buf)
+buildfname(gecos, login, buf, bufsiz)
register char *gecos;
char *login;
char *buf;
+ int bufsiz;
{
register char *p;
register char *bp = buf;
if (*gecos == '*')
gecos++;
- /* find length of final string */
- l = 0;
- for (p = gecos; *p != '\0' && *p != ',' && *p != ';' && *p != '%'; p++)
- {
- if (*p == '&')
- l += strlen(login);
- else
- l++;
- }
-
- /* now fill in buf */
- for (p = gecos; *p != '\0' && *p != ',' && *p != ';' && *p != '%'; p++)
+ for (p = gecos; *p != '\0' && *p != ',' && *p != ';' && *p != '%'
+ && ((bp - buf) <= (bufsiz - 1)); p++)
{
if (*p == '&')
{
- (void) strcpy(bp, login);
+ (void) strncpy(bp, login, (bufsiz - (bp - buf) - 1));
+ buf[bufsiz - 1] = '\0';
*bp = toupper(*bp);
while (*bp != '\0')
bp++;