Skip to content

Commit

Permalink
contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and hallyn committed Jul 3, 2024
1 parent c601824 commit 59e5eef
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 132 deletions.
4 changes: 2 additions & 2 deletions contrib/adduser.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ safeget (char *buf, int maxlen)
bad = (!isalnum (c) && (c != '_') && (c != ' '));
*(buf++) = c;
}
*buf = '\0';
stpcpy(buf, "");

if (bad)
{
printf ("\nString contained banned character. Please stick to alphanumerics.\n");
*bstart = '\0';
stpcpy(bstart, "");
}
}

4 changes: 2 additions & 2 deletions lib/commonio.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static int do_lock_file (const char *file, const char *lock, bool log)
errno = EINVAL;
return 0;
}
buf[len] = '\0';
stpcpy(&buf[len], "");
if (get_pid(buf, &pid) == -1) {
if (log) {
(void) fprintf (shadow_logfd,
Expand Down Expand Up @@ -659,7 +659,7 @@ int commonio_open (struct commonio_db *db, int mode)
goto cleanup_buf;
}
}
*strchrnul(buf, '\n') = '\0';
stpcpy(strchrnul(buf, '\n'), "");

line = strdup (buf);
if (NULL == line) {
Expand Down
2 changes: 1 addition & 1 deletion lib/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
*/

while (fgets (buf, sizeof (buf), fp) != NULL) {
*strchrnul(buf, '\n') = '\0';
stpcpy(strchrnul(buf, '\n'), "");
if (strcmp (buf, tty) == 0) {
(void) fclose (fp);
return true;
Expand Down
3 changes: 2 additions & 1 deletion lib/copydir.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>

#include "alloc/malloc.h"
#include "alloc/x/xmalloc.h"
Expand Down Expand Up @@ -563,7 +564,7 @@ static /*@null@*/char *readlink_malloc (const char *filename)

if ((size_t) nchars < size) { /* The buffer was large enough */
/* readlink does not nul-terminate */
buffer[nchars] = '\0';
stpcpy(&buffer[nchars], "");
return buffer;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/fields.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
if (NULL == cp) {
return;
}
*cp = '\0';
stpcpy(cp, "");

if ('\0' != newf[0]) {
/*
* Remove leading and trailing whitespace. This also
* makes it possible to change the field to empty, by
* entering a space. --marekm
*/
*strrspn(newf, " \t\n") = '\0';
stpcpy(strrspn(newf, " \t\n"), "");

cp = newf;
while (isspace (*cp)) {
Expand Down
8 changes: 4 additions & 4 deletions lib/fputsx.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <config.h>

#include <stdio.h>
#include <string.h>

#include "defines.h"
#include "prototypes.h"

Expand All @@ -33,10 +35,8 @@ fgetsx(/*@returned@*/char *restrict buf, int cnt, FILE *restrict f)
ep = strrchr (cp, '\\');
if ((NULL != ep) && (*(ep + 1) == '\n')) {
cnt -= ep - cp;
if (cnt > 0) {
cp = ep;
*cp = '\0';
}
if (cnt > 0)
cp = stpcpy(ep, "");
} else {
break;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/getdate.y
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ static int LookupWord (char *buff)
else if (strlen (buff) == 4 && buff[3] == '.')
{
abbrev = true;
buff[3] = '\0';
stpcpy(&buff[3], "");
}
else
abbrev = false;
Expand Down Expand Up @@ -689,7 +689,7 @@ static int LookupWord (char *buff)
i = strlen (buff) - 1;
if (buff[i] == 's')
{
buff[i] = '\0';
stpcpy(&buff[i], "");
for (tp = UnitsTable; tp->name; tp++)
if (strcmp (buff, tp->name) == 0)
{
Expand Down Expand Up @@ -723,7 +723,7 @@ static int LookupWord (char *buff)
*p++ = *q;
else
i++;
*p = '\0';
stpcpy(p, "");
if (0 != i)
for (tp = TimezoneTable; NULL != tp->name; tp++)
if (strcmp (buff, tp->name) == 0)
Expand Down Expand Up @@ -772,7 +772,7 @@ yylex (void)
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
if (p < &buff[sizeof buff - 1])
*p++ = c;
*p = '\0';
stpcpy(p, "");
yyInput--;
return LookupWord (buff);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/getdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ static void def_load (void)
/*
* Trim trailing whitespace.
*/
*strrspn(buf, " \t\n") = '\0';
stpcpy(strrspn(buf, " \t\n"), "");

/*
* Break the line into two fields.
Expand All @@ -573,9 +573,9 @@ static void def_load (void)
if (*s == '\0')
continue; /* only 1 field?? */

*s++ = '\0';
stpcpy(s++, "");
value = stpspn(s, " \"\t"); /* next nonwhite */
*strchrnul(value, '"') = '\0';
stpcpy(strchrnul(value, '"'), "");

/*
* Store the value in def_table.
Expand Down
41 changes: 12 additions & 29 deletions lib/gshadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void endsgent (void)
}

strcpy (sgrbuf, string);
*strchrnul(sgrbuf, '\n') = '\0';
stpcpy(strchrnul(sgrbuf, '\n'), "");

/*
* There should be exactly 4 colon separated fields. Find
Expand Down Expand Up @@ -172,7 +172,7 @@ void endsgent (void)
return NULL;
}
}
*strchrnul(buf, '\n') = '\0';
stpcpy(strchrnul(buf, '\n'), "");
return (sgetsgent (buf));
}
return NULL;
Expand Down Expand Up @@ -244,53 +244,36 @@ int putsgent (const struct sgrp *sgrp, FILE * fp)
/*
* Copy the group name and passwd.
*/

strcpy (cp, sgrp->sg_name);
cp += strlen (cp);
*cp++ = ':';

strcpy (cp, sgrp->sg_passwd);
cp += strlen (cp);
*cp++ = ':';
cp = stpcpy(stpcpy(cp, sgrp->sg_name), ":");
cp = stpcpy(stpcpy(cp, sgrp->sg_passwd), ":");

/*
* Copy the administrators, separating each from the other
* with a ",".
*/

for (i = 0; NULL != sgrp->sg_adm[i]; i++) {
if (i > 0) {
*cp++ = ',';
}
if (i > 0)
cp = stpcpy(cp, ",");

strcpy (cp, sgrp->sg_adm[i]);
cp += strlen (cp);
cp = stpcpy(cp, sgrp->sg_adm[i]);
}
*cp = ':';
cp++;
cp = stpcpy(cp, ":");

/*
* Now do likewise with the group members.
*/

for (i = 0; NULL != sgrp->sg_mem[i]; i++) {
if (i > 0) {
*cp = ',';
cp++;
}
if (i > 0)
cp = stpcpy(cp, ",");

strcpy (cp, sgrp->sg_mem[i]);
cp += strlen (cp);
cp = stpcpy(cp, sgrp->sg_mem[i]);
}
*cp = '\n';
cp++;
*cp = '\0';
stpcpy(cp, "\n");

/*
* Output using the function which understands the line
* continuation conventions.
*/

if (fputsx (buf, fp) == EOF) {
free (buf);
return -1;
Expand Down
2 changes: 1 addition & 1 deletion lib/hushed.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool hushed (const char *username)
return false;
}
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
*strchrnul(buf, '\n') = '\0';
stpcpy(strchrnul(buf, '\n'), "");
found = (strcmp (buf, pw->pw_shell) == 0) ||
(strcmp (buf, pw->pw_name) == 0);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/loginprompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void login_prompt (char *name, int namesize)
if (NULL == cp) {
exit (EXIT_FAILURE);
}
*cp = '\0'; /* remove \n [ must be there ] */
stpcpy(cp, ""); /* remove \n [ must be there ] */

/*
* Skip leading whitespace. This makes " username" work right.
Expand All @@ -98,7 +98,7 @@ void login_prompt (char *name, int namesize)

for (i = 0; i < namesize - 1 && *cp != '\0'; name[i++] = *cp++);

name[i] = '\0';
stpcpy(&name[i], "");

/*
* Set the SIGQUIT handler back to its original value
Expand Down
10 changes: 4 additions & 6 deletions lib/obscure.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,10 @@ static /*@observer@*//*@null@*/const char *obscure_msg (

new1 = xstrdup (new);
old1 = xstrdup (old);
if (newlen > maxlen) {
new1[maxlen] = '\0';
}
if (oldlen > maxlen) {
old1[maxlen] = '\0';
}
if (newlen > maxlen)
stpcpy(&new1[maxlen], "");
if (oldlen > maxlen)
stpcpy(&old1[maxlen], "");

msg = password_check (old1, new1, pwdp);

Expand Down
16 changes: 6 additions & 10 deletions lib/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static struct port *getportent (void)
* TTY devices.
*/

*strchrnul(buf, '\n') = '\0';
stpcpy(strchrnul(buf, '\n'), "");

port.pt_names = ttys;
for (cp = buf, j = 0; j < PORT_TTY; j++) {
Expand All @@ -165,12 +165,10 @@ static struct port *getportent (void)
break;
}

if (',' == *cp) { /* end of current tty name */
*cp++ = '\0';
}
if (',' == *cp) /* end of current tty name */
stpcpy(cp++, "");
}
*cp = '\0';
cp++;
stpcpy(cp++, "");
port.pt_names[j] = NULL;

/*
Expand All @@ -186,8 +184,7 @@ static struct port *getportent (void)

for (j = 1; ':' != *cp; cp++) {
if ((',' == *cp) && (j < PORT_IDS)) {
*cp = '\0';
cp++;
stpcpy(cp++, "");
port.pt_users[j] = cp;
j++;
}
Expand All @@ -201,8 +198,7 @@ static struct port *getportent (void)
goto again;
}

*cp = '\0';
cp++;
stpcpy(cp++, "");

/*
* Get the list of valid times. The times field is the third
Expand Down
2 changes: 1 addition & 1 deletion lib/readpassphrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
*p++ = ch;
}
}
*p = '\0';
stpcpy(p, "");
save_errno = errno;
if (!(term.c_lflag & ECHO))
(void)write(output, "\n", 1);
Expand Down
19 changes: 10 additions & 9 deletions lib/salt.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ static /*@observer@*/unsigned long YESCRYPT_get_salt_cost (/*@null@*/const int *
static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long cost)
{
const size_t buf_begin = strlen (buf);
char *p;

/*
* Check if the result buffer is long enough.
Expand All @@ -302,17 +303,17 @@ static /*@observer@*/void YESCRYPT_salt_cost_to_buf (char *buf, unsigned long co
*/
assert (GENSALT_SETTING_SIZE > buf_begin + 4);

buf[buf_begin + 0] = 'j';
p = &buf[buf_begin];
p = stpcpy(p, "j");
if (cost < 3) {
buf[buf_begin + 1] = 0x36 + cost;
*p++ = 0x36 + cost;
} else if (cost < 6) {
buf[buf_begin + 1] = 0x34 + cost;
*p++ = 0x34 + cost;
} else {
buf[buf_begin + 1] = 0x3b + cost;
*p++ = 0x3b + cost;
}
buf[buf_begin + 2] = cost >= 3 ? 'T' : '5';
buf[buf_begin + 3] = '$';
buf[buf_begin + 4] = '\0';
p = stpcpy(p, (cost >= 3) ? "T" : "5");
stpcpy(p, "$");
}
#endif /* USE_YESCRYPT */

Expand All @@ -330,7 +331,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size)
strcat (salt, l64a (csrand ()));
} while (strlen (salt) < salt_size);

salt[salt_size] = '\0';
stpcpy(&salt[salt_size], "");

return salt;
}
Expand Down Expand Up @@ -421,7 +422,7 @@ static /*@observer@*/const char *gensalt (size_t salt_size)
salt_len = GENSALT_SETTING_SIZE - 1;
rounds = 0;
memset(result, '.', salt_len);
result[salt_len] = '\0';
stpcpy(&result[salt_len], "");
}

char *retval = crypt_gensalt (result, rounds, NULL, 0);
Expand Down
Loading

0 comments on commit 59e5eef

Please sign in to comment.