replace sprintf all over the place
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1635 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -208,11 +208,11 @@ login(char *host)
|
||||
char prompt[128];
|
||||
if(myname &&
|
||||
(!strcmp(user, "ftp") || !strcmp(user, "anonymous"))){
|
||||
sprintf(defaultpass, "%s@%s", myname, mydomain);
|
||||
sprintf(prompt, "Password (%s): ", defaultpass);
|
||||
snprintf(defaultpass, sizeof(defaultpass), "%s@%s", myname, mydomain);
|
||||
snprintf(prompt, sizeof(prompt), "Password (%s): ", defaultpass);
|
||||
}else{
|
||||
strcpy(defaultpass, "");
|
||||
sprintf(prompt, "Password: ");
|
||||
snprintf(prompt, sizeof(prompt), "Password: ");
|
||||
}
|
||||
pass = defaultpass;
|
||||
des_read_pw_string (tmp, sizeof(tmp), prompt, 0);
|
||||
@@ -1140,15 +1140,11 @@ abort:
|
||||
int
|
||||
initconn(void)
|
||||
{
|
||||
char *p, *a;
|
||||
int result, len, tmpno = 0;
|
||||
int on = 1;
|
||||
int a0, a1, a2, a3, p0, p1;
|
||||
|
||||
if (passivemode) {
|
||||
u_int32_t tmpaddr;
|
||||
u_int16_t tmpport;
|
||||
|
||||
data = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (data < 0) {
|
||||
perror("ftp: socket");
|
||||
@@ -1644,7 +1640,7 @@ abort_remote(FILE *din)
|
||||
* send IAC in urgent mode instead of DM because 4.3BSD places oob mark
|
||||
* after urgent byte rather than before as is protocol now
|
||||
*/
|
||||
sprintf(buf, "%c%c%c", IAC, IP, IAC);
|
||||
snprintf(buf, sizeof(buf), "%c%c%c", IAC, IP, IAC);
|
||||
if (send(fileno(cout), buf, 3, MSG_OOB) != 3)
|
||||
warn("abort");
|
||||
fprintf(cout,"%cABOR\r\n", DM);
|
||||
|
@@ -101,7 +101,7 @@ void kauth(int argc, char **argv)
|
||||
for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
|
||||
*p = 0;
|
||||
|
||||
sprintf(buf, "Password for %s:", name);
|
||||
snprintf(buf, sizeof(buf), "Password for %s:", name);
|
||||
if (des_read_pw_string (passwd, sizeof(passwd)-1, buf, 0))
|
||||
*passwd = '\0';
|
||||
des_string_to_key (passwd, &key);
|
||||
|
@@ -510,12 +510,14 @@ int krb4_write_enc(FILE *F, char *fmt, va_list ap)
|
||||
char *p;
|
||||
char buf[1024];
|
||||
char enc[1024];
|
||||
vsprintf(buf, fmt, ap);
|
||||
|
||||
vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
len = krb_mk_priv(buf, enc, strlen(buf), schedule, &key,
|
||||
&myctladdr, &hisctladdr);
|
||||
base64_encode(enc, len, &p);
|
||||
|
||||
fprintf(F, "ENC %s", p);
|
||||
free (p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -79,7 +79,7 @@ ruserpass(char *host, char **aname, char **apass, char **aacct)
|
||||
hdir = getenv("HOME");
|
||||
if (hdir == NULL)
|
||||
hdir = ".";
|
||||
sprintf(buf, "%s/.netrc", hdir);
|
||||
snprintf(buf, sizeof(buf), "%s/.netrc", hdir);
|
||||
cfile = fopen(buf, "r");
|
||||
if (cfile == NULL) {
|
||||
if (errno != ENOENT)
|
||||
@@ -127,8 +127,7 @@ next:
|
||||
case LOGIN:
|
||||
if (token())
|
||||
if (*aname == 0) {
|
||||
*aname = malloc((unsigned) strlen(tokval) + 1);
|
||||
strcpy(*aname, tokval);
|
||||
*aname = strdup(tokval);
|
||||
} else {
|
||||
if (strcmp(*aname, tokval))
|
||||
goto next;
|
||||
@@ -143,8 +142,7 @@ next:
|
||||
goto bad;
|
||||
}
|
||||
if (token() && *apass == 0) {
|
||||
*apass = malloc((unsigned) strlen(tokval) + 1);
|
||||
strcpy(*apass, tokval);
|
||||
*apass = strdup(tokval);
|
||||
}
|
||||
break;
|
||||
case ACCOUNT:
|
||||
@@ -155,8 +153,7 @@ next:
|
||||
goto bad;
|
||||
}
|
||||
if (token() && *aacct == 0) {
|
||||
*aacct = malloc((unsigned) strlen(tokval) + 1);
|
||||
strcpy(*aacct, tokval);
|
||||
*aacct = strdup(tokval);
|
||||
}
|
||||
break;
|
||||
case MACDEF:
|
||||
|
@@ -1288,11 +1288,10 @@ copy(char *s)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = malloc((unsigned) strlen(s) + 1);
|
||||
p = strdup(s);
|
||||
if (p == NULL)
|
||||
fatal("Ran out of memory.");
|
||||
strcpy(p, s);
|
||||
return (p);
|
||||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1327,11 +1326,11 @@ help(struct tab *ctab, char *s)
|
||||
columns = 1;
|
||||
lines = (NCMDS + columns - 1) / columns;
|
||||
for (i = 0; i < lines; i++) {
|
||||
sprintf(buf, " ");
|
||||
strcpy (buf, " ");
|
||||
for (j = 0; j < columns; j++) {
|
||||
c = ctab + j * lines + i;
|
||||
sprintf(buf + strlen(buf), "%s%c", c->name,
|
||||
c->implemented ? ' ' : '*');
|
||||
snprintf (buf + strlen(buf), sizeof(buf) - strlen(buf),
|
||||
"%s%c", c->name, c->implemented ? ' ' : '*');
|
||||
if (c + lines >= &ctab[NCMDS])
|
||||
break;
|
||||
w = strlen(c->name) + 1;
|
||||
|
@@ -301,7 +301,8 @@ main(int argc, char **argv)
|
||||
|
||||
/* detach from any tickets and tokens */
|
||||
|
||||
sprintf(tkfile, "/tmp/ftp_%u", (unsigned int)getpid());
|
||||
snprintf(tkfile, sizeof(tkfile),
|
||||
"/tmp/ftp_%u", (unsigned)getpid());
|
||||
krb_set_tkt_string(tkfile);
|
||||
if(k_hasafs())
|
||||
k_setpag();
|
||||
@@ -412,7 +413,7 @@ main(int argc, char **argv)
|
||||
debug = 0;
|
||||
|
||||
/* set this here so it can be put in wtmp */
|
||||
sprintf(ttyline, "ftp%u", (unsigned)getpid());
|
||||
snprintf(ttyline, sizeof(ttyline), "ftp%u", (unsigned)getpid());
|
||||
|
||||
|
||||
/* freopen(_PATH_DEVNULL, "w", stderr); */
|
||||
@@ -493,15 +494,14 @@ lostconn(int signo)
|
||||
static char *
|
||||
sgetsave(char *s)
|
||||
{
|
||||
char *new = malloc((unsigned) strlen(s) + 1);
|
||||
char *new = strdup(s);
|
||||
|
||||
if (new == NULL) {
|
||||
perror_reply(421, "Local resource failure: malloc");
|
||||
dologout(1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
strcpy(new, s);
|
||||
return (new);
|
||||
return new;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -785,10 +785,10 @@ int do_login(int code, char *passwd)
|
||||
if (guest) {
|
||||
reply(code, "Guest login ok, access restrictions apply.");
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
sprintf(proctitle, "%s: anonymous/%.*s", remotehost,
|
||||
sizeof(proctitle) - sizeof(remotehost) -
|
||||
sizeof(": anonymous/"), passwd);
|
||||
setproctitle(proctitle);
|
||||
snprintf (proctitle, sizeof(proctitle),
|
||||
"%s: anonymous/%s",
|
||||
remotehost,
|
||||
passwd);
|
||||
#endif /* HAVE_SETPROCTITLE */
|
||||
if (logging)
|
||||
syslog(LOG_INFO, "ANONYMOUS FTP LOGIN FROM %s(%s), %s",
|
||||
@@ -798,7 +798,7 @@ int do_login(int code, char *passwd)
|
||||
} else {
|
||||
reply(code, "User %s logged in.", pw->pw_name);
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
sprintf(proctitle, "%s: %s", remotehost, pw->pw_name);
|
||||
snprintf(proctitle, sizeof(proctitle), "%s: %s", remotehost, pw->pw_name);
|
||||
setproctitle(proctitle);
|
||||
#endif /* HAVE_SETPROCTITLE */
|
||||
if (logging)
|
||||
@@ -943,15 +943,9 @@ retrieve(char *cmd, char *name)
|
||||
char *tail = name + strlen(name) - strlen(p->ext);
|
||||
|
||||
if(strcmp(tail, p->ext) == 0){
|
||||
strncpy(line, p->cmd, sizeof(line));
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
strncat(line, name, sizeof(line)-strlen(line));
|
||||
line[sizeof(line) - 1] = '\0';
|
||||
line[strlen(line) - strlen(p->ext)] = 0;
|
||||
#if 0
|
||||
sprintf(line, p->cmd, name);
|
||||
/* XXX */
|
||||
#endif
|
||||
snprintf (line, sizeof(line),
|
||||
"%s%s",
|
||||
p->cmd, name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -966,7 +960,8 @@ retrieve(char *cmd, char *name)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sprintf(line, cmd, name), name = line;
|
||||
snprintf(line, sizeof(line), cmd, name);
|
||||
name = line;
|
||||
fin = ftpd_popen(line, "r", 1, 0);
|
||||
closefunc = ftpd_pclose;
|
||||
st.st_size = -1;
|
||||
@@ -1183,7 +1178,7 @@ dataconn(char *name, off_t size, char *mode)
|
||||
file_size = size;
|
||||
byte_count = 0;
|
||||
if (size != (off_t) -1)
|
||||
sprintf(sizebuf, " (%ld bytes)", size);
|
||||
snprintf(sizebuf, sizeof(sizebuf), " (%ld bytes)", size);
|
||||
else
|
||||
strcpy(sizebuf, "");
|
||||
if (pdata >= 0) {
|
||||
@@ -1448,7 +1443,7 @@ statfilecmd(char *filename)
|
||||
int c;
|
||||
char line[LINE_MAX];
|
||||
|
||||
sprintf(line, "/bin/ls -la %s", filename);
|
||||
snprintf(line, sizeof(line), "/bin/ls -la %s", filename);
|
||||
fin = ftpd_popen(line, "r", 1, 0);
|
||||
lreply(211, "status of %s:", filename);
|
||||
while ((c = getc(fin)) != EOF) {
|
||||
@@ -1544,12 +1539,12 @@ int_reply(int n, char *c, const char *fmt, va_list ap)
|
||||
char *p;
|
||||
p=buf;
|
||||
if(n){
|
||||
sprintf(p, "%d%s", n, c);
|
||||
snprintf(p, sizeof(buf), "%d%s", n, c);
|
||||
p+=strlen(p);
|
||||
}
|
||||
vsprintf(p, fmt, ap);
|
||||
vsnprintf(p, sizeof(buf) - strlen(p), fmt, ap);
|
||||
p+=strlen(p);
|
||||
sprintf(p, "\r\n");
|
||||
snprintf(p, sizeof(buf) - strlen(p), "\r\n");
|
||||
p+=strlen(p);
|
||||
auth_printf("%s", buf);
|
||||
fflush(stdout);
|
||||
@@ -1719,7 +1714,7 @@ dolog(struct sockaddr_in *sin)
|
||||
{
|
||||
inaddr2str (sin->sin_addr, remotehost, sizeof(remotehost));
|
||||
#ifdef HAVE_SETPROCTITLE
|
||||
sprintf(proctitle, "%s: connected", remotehost);
|
||||
snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
|
||||
setproctitle(proctitle);
|
||||
#endif /* HAVE_SETPROCTITLE */
|
||||
|
||||
@@ -1867,11 +1862,8 @@ gunique(char *local)
|
||||
}
|
||||
if (cp)
|
||||
*cp = '/';
|
||||
strcpy(new, local);
|
||||
cp = new + strlen(new);
|
||||
*cp++ = '.';
|
||||
for (count = 1; count < 100; count++) {
|
||||
sprintf(cp, "%d", count);
|
||||
snprintf (new, sizeof(new), "%s.%d", local, count);
|
||||
if (stat(new, &st) < 0)
|
||||
return (new);
|
||||
}
|
||||
@@ -1958,7 +1950,7 @@ send_file_list(char *whichf)
|
||||
goto out;
|
||||
transflag++;
|
||||
}
|
||||
sprintf(buf, "%s%s\n", dirname,
|
||||
snprintf(buf, sizeof(buf), "%s%s\n", dirname,
|
||||
type == TYPE_A ? "\r" : "");
|
||||
auth_write(fileno(dout), buf, strlen(buf));
|
||||
byte_count += strlen(dirname) + 1;
|
||||
@@ -1977,7 +1969,7 @@ send_file_list(char *whichf)
|
||||
if (!strcmp(dir->d_name, ".."))
|
||||
continue;
|
||||
|
||||
sprintf(nbuf, "%s/%s", dirname, dir->d_name);
|
||||
snprintf(nbuf, sizeof(nbuf), "%s/%s", dirname, dir->d_name);
|
||||
|
||||
/*
|
||||
* We have to do a stat to insure it's
|
||||
@@ -1992,11 +1984,11 @@ send_file_list(char *whichf)
|
||||
transflag++;
|
||||
}
|
||||
if(strncmp(nbuf, "./", 2) == 0)
|
||||
sprintf(buf, "%s%s\n", nbuf +2,
|
||||
type == TYPE_A ? "\r" : "");
|
||||
snprintf(buf, sizeof(buf), "%s%s\n", nbuf +2,
|
||||
type == TYPE_A ? "\r" : "");
|
||||
else
|
||||
sprintf(buf, "%s%s\n", nbuf,
|
||||
type == TYPE_A ? "\r" : "");
|
||||
snprintf(buf, sizeof(buf), "%s%s\n", nbuf,
|
||||
type == TYPE_A ? "\r" : "");
|
||||
auth_write(fileno(dout), buf, strlen(buf));
|
||||
byte_count += strlen(nbuf) + 1;
|
||||
}
|
||||
@@ -2031,7 +2023,11 @@ find(char *pattern)
|
||||
{
|
||||
char line[1024];
|
||||
FILE *f;
|
||||
sprintf(line, "/bin/locate -d %s %s", ftp_rooted("/etc/locatedb"), pattern);
|
||||
|
||||
snprintf(line, sizeof(line),
|
||||
"/bin/locate -d %s %s",
|
||||
ftp_rooted("/etc/locatedb"),
|
||||
pattern);
|
||||
f = ftpd_popen(line, "r", 1, 1);
|
||||
if(f == NULL){
|
||||
perror_reply(550, "/bin/locate");
|
||||
|
@@ -175,8 +175,8 @@ int krb4_mic(char *msg)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmp = strdup(msg);
|
||||
sprintf(tmp, "%.*s", (int)m_data.app_length, m_data.app_data);
|
||||
tmp = malloc(strlen(msg) + 1);
|
||||
snprintf(tmp, strlen(msg) + 1, "%.*s", (int)m_data.app_length, m_data.app_data);
|
||||
if(!strstr(tmp, "\r\n"))
|
||||
strcat(tmp, "\r\n");
|
||||
new_ftp_command(tmp);
|
||||
@@ -217,7 +217,7 @@ int krb4_enc(char *msg)
|
||||
}
|
||||
|
||||
tmp = strdup(msg);
|
||||
sprintf(tmp, "%.*s", (int)m_data.app_length, m_data.app_data);
|
||||
snprintf(tmp, strlen(msg) + 1, "%.*s", (int)m_data.app_length, m_data.app_data);
|
||||
if(!strstr(tmp, "\r\n"))
|
||||
strcat(tmp, "\r\n");
|
||||
new_ftp_command(tmp);
|
||||
|
@@ -86,10 +86,11 @@ ftp_rooted(const char *path)
|
||||
static char home[MaxPathLen] = "";
|
||||
static char newpath[MaxPathLen];
|
||||
struct passwd *pwd;
|
||||
|
||||
if(!home[0])
|
||||
if((pwd = k_getpwnam("ftp")))
|
||||
strcpy(home, pwd->pw_dir);
|
||||
sprintf(newpath, "%s/%s", home, path);
|
||||
snprintf(newpath, sizeof(newpath), "%s/%s", home, path);
|
||||
if(access(newpath, X_OK))
|
||||
strcpy(newpath, path);
|
||||
return newpath;
|
||||
|
Reference in New Issue
Block a user