SCREWUP("size not delimited");
if (targisdir) {
if (strlen(targ) + strlen(cp) + 1 < sizeof(nambuf)) {
- (void) sprintf(nambuf, "%s%s%s", targ,
- *targ ? "/" : "", cp);
+ (void) snprintf(nambuf, sizeof(nambuf),
+ "%s%s%s", targ,
+ *targ ? "/" : "", cp);
} else {
SCREWUP("target directory name too long");
}
static char banner[1024];
if (uname(&name) < 0)
- sprintf(banner, "\r\nError getting hostname: %s\r\n",
- strerror(errno));
+ snprintf(banner, sizeof(banner),
+ "\r\nError getting hostname: %s\r\n",
+ strerror(errno));
else {
#if defined(_AIX)
- sprintf(banner, "\r\n %%h (%s release %s.%s) (%%t)\r\n\r\n",
- name.sysname, name.version, name.release);
+ snprintf(banner, sizeof(banner),
+ "\r\n %%h (%s release %s.%s) (%%t)\r\n\r\n",
+ name.sysname, name.version, name.release);
#else
- sprintf(banner, "\r\n %%h (%s release %s %s) (%%t)\r\n\r\n",
- name.sysname, name.release, name.version);
+ snprintf(banner, sizeof(banner),
+ "\r\n %%h (%s release %s %s) (%%t)\r\n\r\n",
+ name.sysname, name.release, name.version);
#endif
}
return banner;
if (secflag) {
char slave_dev[16];
/*xxx This code needs to be fixed to work without ptynum; I don't understand why they don't currently use line, so I don't really know how to fix.*/
- sprintf(tty_dev, "/dev/pty/%03d", ptynum);
+ snprintf(tty_dev, sizeof(tty_dev), "/dev/pty/%03d", ptynum);
if (setdevs(tty_dev, &dv) < 0)
fatal(net, "cannot set pty security");
- sprintf(slave_dev, "/dev/ttyp%03d", ptynum);
+ snprintf(slave_dev, sizeof(slave_dev), "/dev/ttyp%03d", ptynum);
if (setdevs(slave_dev, &dv) < 0)
fatal(net, "cannot set tty security");
}
{
char buf[BUFSIZ];
- (void) sprintf(buf, "telnetd: %s.\r\n", msg);
+ (void) snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg);
#ifdef ENCRYPTION
if (encrypt_output) {
/*
{
char buf[BUFSIZ], *strerror();
- (void) sprintf(buf, "%s: %s\r\n", msg, strerror(errno));
+ (void) snprintf(buf, sizeof(buf), "%s: %s\r\n", msg, strerror(errno));
fatal(f, buf);
}
krb_get_lrealm(k4->realm, 1);
if (k4->inst[0])
- sprintf(k4->name, "%s.%s@%s", k4->aname, k4->inst, k4->realm);
+ snprintf(k4->name, sizeof(k4->name), "%s.%s@%s",
+ k4->aname, k4->inst, k4->realm);
else
- sprintf(k4->name, "%s@%s", k4->aname, k4->realm);
+ snprintf(k4->name, sizeof(k4->name), "%s@%s", k4->aname, k4->realm);
opts->principal_name = k4->name;
skip:
krb5_error_code code;
char prompt[1024];
- sprintf(prompt, "Password for %s", opts->principal_name);
+ snprintf(prompt, sizeof(prompt),
+ "Password for %s", opts->principal_name);
stash_password[0] = 0;
/*
Note: krb5_read_password does not actually look at the
getvprogname(v, progname)
char *v, *progname;
{
- unsigned int len = strlen(progname) + 2 + strlen(v) + 2;
- char *ret = malloc(len);
- if (ret)
- sprintf(ret, "%s(v%s)", progname, v);
+ char *ret;
+
+ if (asprintf(&ret, "%s(v%s)", progname, v) < 0)
+ return progname;
else
- ret = progname;
- return ret;
+ return ret;
}
#ifdef HAVE_KRB524
if ((retval = krb5_enctype_to_string(enctype, buf, sizeof(buf)))) {
/* XXX if there's an error != EINVAL, I should probably report it */
- sprintf(buf, "etype %d", enctype);
+ snprintf(buf, sizeof(buf), "etype %d", enctype);
}
return buf;
return 1;
}
} else {
- char *tmp = *keytab_str;
-
- *keytab_str = (char *)
- malloc(strlen("WRFILE:")+strlen(tmp)+1);
- if (*keytab_str == NULL) {
- com_err(whoami, ENOMEM, "while creating keytab name");
- return 1;
+ if (asprintf(keytab_str, "WRFILE:%s", *keytab_str) < 0) {
+ *keytab_str = NULL;
+ com_err(whoami, ENOMEM, "while creating keytab name");
+ return 1;
}
- sprintf(*keytab_str, "WRFILE:%s", tmp);
}
code = krb5_kt_resolve(my_context, *keytab_str, keytab);
krb5_error_code ret;
if ((ret = krb5_enctype_to_string(enctype, buf, sizeof(buf))))
- sprintf(buf, "etype %d", enctype);
+ snprintf(buf, sizeof(buf), "etype %d", enctype);
return buf;
}
error_buf[0] = '\0';
if (fmt)
- vsprintf(error_buf, fmt, args);
+ vsnprintf(error_buf, sizeof(error_buf), fmt, args);
syslog(LOG_ERR, "%s%s%s%s%s", whoami ? whoami : "", whoami ? ": " : "",
code ? error_message(code) : "", code ? " " : "", error_buf);
}