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, "");
}
}
errno = EINVAL;
return 0;
}
- buf[len] = '\0';
+ stpcpy(&buf[len], "");
if (get_pid(buf, &pid) == -1) {
if (log) {
(void) fprintf (shadow_logfd,
goto cleanup_buf;
}
}
- *strchrnul(buf, '\n') = '\0';
+ stpcpy(strchrnul(buf, '\n'), "");
line = strdup (buf);
if (NULL == line) {
*/
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;
#include <sys/time.h>
#include <fcntl.h>
#include <stdio.h>
+#include <string.h>
#include "alloc/malloc.h"
#include "alloc/x/xmalloc.h"
if ((size_t) nchars < size) { /* The buffer was large enough */
/* readlink does not nul-terminate */
- buffer[nchars] = '\0';
+ stpcpy(&buffer[nchars], "");
return buffer;
}
if (NULL == cp) {
return;
}
- *cp = '\0';
+ stpcpy(cp, "");
if ('\0' != newf[0]) {
/*
* 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)) {
#include <config.h>
#include <stdio.h>
+#include <string.h>
+
#include "defines.h"
#include "prototypes.h"
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;
}
else if (strlen (buff) == 4 && buff[3] == '.')
{
abbrev = true;
- buff[3] = '\0';
+ stpcpy(&buff[3], "");
}
else
abbrev = false;
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)
{
*p++ = *q;
else
i++;
- *p = '\0';
+ stpcpy(p, "");
if (0 != i)
for (tp = TimezoneTable; NULL != tp->name; tp++)
if (strcmp (buff, tp->name) == 0)
for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';)
if (p < &buff[sizeof buff - 1])
*p++ = c;
- *p = '\0';
+ stpcpy(p, "");
yyInput--;
return LookupWord (buff);
}
/*
* Trim trailing whitespace.
*/
- *strrspn(buf, " \t\n") = '\0';
+ stpcpy(strrspn(buf, " \t\n"), "");
/*
* Break the line into two fields.
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.
}
strcpy (sgrbuf, string);
- *strchrnul(sgrbuf, '\n') = '\0';
+ stpcpy(strchrnul(sgrbuf, '\n'), "");
/*
* There should be exactly 4 colon separated fields. Find
return NULL;
}
}
- *strchrnul(buf, '\n') = '\0';
+ stpcpy(strchrnul(buf, '\n'), "");
return (sgetsgent (buf));
}
return NULL;
/*
* 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;
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);
}
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.
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
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);
* TTY devices.
*/
- *strchrnul(buf, '\n') = '\0';
+ stpcpy(strchrnul(buf, '\n'), "");
port.pt_names = ttys;
for (cp = buf, j = 0; j < PORT_TTY; j++) {
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;
/*
for (j = 1; ':' != *cp; cp++) {
if ((',' == *cp) && (j < PORT_IDS)) {
- *cp = '\0';
- cp++;
+ stpcpy(cp++, "");
port.pt_users[j] = cp;
j++;
}
goto again;
}
- *cp = '\0';
- cp++;
+ stpcpy(cp++, "");
/*
* Get the list of valid times. The times field is the third
*p++ = ch;
}
}
- *p = '\0';
+ stpcpy(p, "");
save_errno = errno;
if (!(term.c_lflag & ECHO))
(void)write(output, "\n", 1);
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.
*/
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 */
strcat (salt, l64a (csrand ()));
} while (strlen (salt) < salt_size);
- salt[salt_size] = '\0';
+ stpcpy(&salt[salt_size], "");
return salt;
}
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);
if (NULL == cp) {
break;
}
- *cp = '\0';
+ stpcpy(cp, "");
cp = buf;
/* ignore whitespace and comments */
continue;
}
/* NUL-terminate the name */
- *cp = '\0';
- cp++;
+ stpcpy(cp++, "");
val = cp;
#if 0 /* XXX untested, and needs rewrite with fewer goto's :-) */
/*
goto finished;
} else if (isspace (*cp)) {
/* unescaped whitespace - end of string */
- *cp = '\0';
+ stpcpy(cp, "");
goto finished;
} else {
cp++;
}
}
strcpy (grpbuf, buf);
- *strchrnul(grpbuf, '\n') = '\0';
+ stpcpy(strchrnul(grpbuf, '\n'), "");
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
grpfields[i] = strsep(&cp, ":");
return NULL; /* fail if too long */
}
strcpy (spwbuf, string);
- *strchrnul(spwbuf, '\n') = '\0';
+ stpcpy(strchrnul(spwbuf, '\n'), "");
/*
* Tokenize the string into colon separated fields. Allow up to
if (strlen (string) >= sizeof spwbuf)
return 0;
strcpy (spwbuf, string);
- *strchrnul(spwbuf, '\n') = '\0';
+ stpcpy(strchrnul(spwbuf, '\n'), "");
/*
* Tokenize the string into colon separated fields. Allow up to
if (fgets (buf, sizeof buf, fp) != NULL)
{
- *strchrnul(buf, '\n') = '\0';
+ stpcpy(strchrnul(buf, '\n'), "");
return my_sgetspent (buf);
}
return 0;
sssd_flush_cache(int dbflags)
{
int status, code, rv;
- int i = 0;
+ char *p;
char *sss_cache_args = NULL;
const char *cmd = "/usr/sbin/sss_cache";
const char *spawnedArgs[] = {"sss_cache", NULL, NULL};
return -1;
}
- sss_cache_args[i++] = '-';
- if (dbflags & SSSD_DB_PASSWD) {
- sss_cache_args[i++] = 'U';
- }
- if (dbflags & SSSD_DB_GROUP) {
- sss_cache_args[i++] = 'G';
- }
- sss_cache_args[i++] = '\0';
- if (i == 2) {
+ p = stpcpy(sss_cache_args, "-");
+ if (dbflags & SSSD_DB_PASSWD)
+ stpcpy(p, "U");
+ if (dbflags & SSSD_DB_GROUP)
+ stpcpy(p, "G");
+
+ if (*p == '\0') {
/* Neither passwd nor group, nothing to do */
free(sss_cache_args);
return 0;
}
free (path);
if ((size_t)ret >= sizeof(link) - 1) {
- link[sizeof(link) - 1] = '\0';
+ stpcpy(&link[sizeof(link) - 1], "");
fprintf (shadow_logfd,
_("%s: Suspiciously long symlink: %s\n"),
shadow_progname, link);
return NULL;
}
- link[ret] = '\0';
+ stpcpy(&link[ret], "");
rval = strdup (link);
if (NULL == rval) {
OUT_OF_MEMORY;
goto out_free_path;
}
while ((ind = strchr (ptr, '/'))) {
- *ind = '\0';
+ stpcpy(ind, "");
if (asprintf (&dir, TCB_DIR "/%s", path) == -1) {
OUT_OF_MEMORY;
return SHADOWTCB_FAILURE;
char *ind, *dir;
shadowtcb_status ret = SHADOWTCB_SUCCESS;
while ((ind = strrchr (path, '/'))) {
- *ind = '\0';
+ stpcpy(ind, "");
if (asprintf (&dir, TCB_DIR "/%s", path) == -1) {
OUT_OF_MEMORY;
return SHADOWTCB_FAILURE;
continue;
}
- *strchrnul(buf, '\n') = '\0';
+ stpcpy(strchrnul(buf, '\n'), "");
if ( (sscanf (buf, "%1023s %1023s", type, port) == 2)
&& (strcmp (line, port) == 0)) {
strcpy (tzbuf, def_tz);
} else {
- *strchrnul(tzbuf, '\n') = '\0';
+ stpcpy(strchrnul(tzbuf, '\n'), "");
}
if (NULL != fp) {
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
+#include <string.h>
#include <fcntl.h>
#include "alloc/x/xcalloc.h"
/* tmptty shall be bigger than full_tty */
static char tmptty[sizeof(full_tty) + 1];
- full_tty[0] = '\0';
+ stpcpy(full_tty, "");
if (tty[0] != '/')
strcpy (full_tty, "/dev/");
strncat(full_tty, tty, UTX_LINESIZE);
line++;
cp = strrchr (buf, '\n');
if (NULL != cp) {
- *cp = '\0';
+ stpcpy(cp, "");
} else {
fprintf (stderr, _("%s: line %d: line too long\n"),
Prog, line);
name = buf;
cp = strchr (name, ':');
if (NULL != cp) {
- *cp = '\0';
+ stpcpy(cp, "");
cp++;
} else {
fprintf (stderr,
line++;
cp = strrchr (buf, '\n');
if (NULL != cp) {
- *cp = '\0';
+ stpcpy(cp, "");
} else {
if (feof (stdin) == 0) {
name = buf;
cp = strchr (name, ':');
if (NULL != cp) {
- *cp = '\0';
- cp++;
+ stpcpy(cp++, "");
} else {
fprintf (stderr,
_("%s: line %d: missing new password\n"),
exit (E_BAD_ARG);
}
/* terminate name, point to value */
- *cp++ = '\0';
+ stpcpy(cp++, "");
if (putdef_str (optarg, cp, NULL) < 0) {
exit (E_BAD_ARG);
}
if (line[0] == '#') {
continue; /* comment line */
}
- *strrspn(line, " \t\n") = '\0';
+ stpcpy(strrspn(line, " \t\n"), "");
if (line[0] == '\0') { /* skip blank lines */
continue;
}
if (name[0] == '\0') {
gethostname (name, sizeof (name));
- name[MAXHOSTNAMELEN] = '\0';
+ stpcpy(&name[MAXHOSTNAMELEN], "");
}
return (name);
}
*/
at = strchr (tok + 1, '@');
if (NULL != at) { /* split user@host pattern */
- *at = '\0';
+ stpcpy(at, "");
return ( user_match (tok, string)
&& from_match (at + 1, myhostname ()));
#if HAVE_INNETGR
}
/* child */
- if (strncmp (ut->ut_line, "/dev/", 5) != 0) {
- strcpy (tty_name, "/dev/");
- } else {
- tty_name[0] = '\0';
- }
+ if (strncmp(ut->ut_line, "/dev/", 5) != 0)
+ strcpy(tty_name, "/dev/");
+ else
+ strcpy(tty_name, "");
STRNCAT(tty_name, ut->ut_line);
#ifndef O_NOCTTY
Prog, line);
fail_exit (EXIT_FAILURE);
}
- if (cp != NULL) {
- *cp = '\0';
- }
+ if (cp != NULL)
+ stpcpy(cp, "");
/*
* Break the string into fields and screw around with them.
erase_pass (clear);
strzero (cipher);
} else {
- orig[0] = '\0';
+ strcpy(orig, "");
}
/*
}
}
- if (dflg) {
- *cp = '\0';
- }
+ if (dflg)
+ strcpy(cp, "");
if (uflg && *cp == '!') {
if (cp[1] == '\0') {
continue;
}
- *strrspn(temp, " \t\n") = '\0';
+ stpcpy(strrspn(temp, " \t\n"), "");
posn = 0;
while (temp[posn] == ' ' || temp[posn] == '\t')
* values are used, everything else can be ignored.
*/
while (fgets (buf, sizeof buf, fp) == buf) {
- *strchrnul(buf, '\n') = '\0';
+ stpcpy(strchrnul(buf, '\n'), "");
cp = strchr (buf, '=');
if (NULL == cp) {
while (fgets (buf, sizeof buf, ifp) == buf) {
cp = strrchr (buf, '\n');
if (NULL != cp) {
- *cp = '\0';
+ stpcpy(cp, "");
} else {
/* A line which does not end with \n is only valid
* at the end of the file.
exit (E_BAD_ARG);
}
/* terminate name, point to value */
- *cp = '\0';
- cp++;
+ stpcpy(cp++, "");
if (putdef_str (optarg, cp, NULL) < 0) {
exit (E_BAD_ARG);
}
if (access (prefix_user_home, F_OK) == 0)
return;
- path[0] = '\0';
+ strcpy(path, "");
bhome = strdup(prefix_user_home);
if (!bhome) {
fprintf(stderr,
Prog, path);
fail_exit(E_HOMEDIR);
}
- btrfs_check[strlen(path) - strlen(cp) - 1] = '\0';
+ stpcpy(&btrfs_check[strlen(path) - strlen(cp) - 1], "");
if (is_btrfs(btrfs_check) <= 0) {
fprintf(stderr,
_("%s: home directory \"%s\" must be mounted on BTRFS\n"),
memset(name, '_', max);
- name[max] = '\0';
+ stpcpy(&name[max], "");
assert_true(false == is_valid_user_name(name));
- name[max - 1] = '\0';
+ stpcpy(&name[max - 1], "");
assert_true(is_valid_user_name(name));
free(name);