char **argv0;
{
int rem, pid = 0;
- char *host=0, *cp, **ap, buf[RCMD_BUFSIZ], *args, **argv = argv0, *user = 0;
+ char *host=0, **ap, buf[RCMD_BUFSIZ], *args, **argv = argv0, *user = 0;
register int cc;
struct passwd *pwd;
fd_set readfrom, ready;
cc += strlen(*ap) + 1;
if (encrypt_flag)
cc += 3;
- cp = args = (char *) malloc((unsigned) cc);
- if (encrypt_flag) {
- strcpy(args, "-x ");
- cp += 3;
- }
+ args = (char *) malloc((unsigned) cc);
+ if (encrypt_flag)
+ strlcpy(args, "-x ", cc);
for (ap = argv; *ap; ap++) {
- (void) strcpy(cp, *ap);
- while (*cp)
- cp++;
+ (void) strlcat(args, *ap, cc);
if (ap[1])
- *cp++ = ' ';
+ strlcat(args, " ", cc);
}
if(debug_port == 0) {
offst = 3;
}
- strcpy((char *) cmdbuf + offst, kprogdir);
+ strlcpy(cmdbuf + offst, kprogdir, sizeof(cmdbuf) - offst);
cp = copy + 3 + offst;
- cmdbuf[sizeof(cmdbuf) - 1] = '\0';
- if (auth_sys == KRB5_RECVAUTH_V4) {
- strncat(cmdbuf, "/v4rcp", sizeof(cmdbuf) - 1 - strlen(cmdbuf));
- } else {
- strncat(cmdbuf, "/rcp", sizeof(cmdbuf) - 1 - strlen(cmdbuf));
- }
+ if (auth_sys == KRB5_RECVAUTH_V4)
+ strlcat(cmdbuf, "/v4rcp", sizeof(cmdbuf));
+ else
+ strlcat(cmdbuf, "/rcp", sizeof(cmdbuf));
+
if (stat((char *)cmdbuf + offst, &s2) >= 0)
- strncat(cmdbuf, cp, sizeof(cmdbuf) - 1 - strlen(cmdbuf));
+ strlcat(cmdbuf, cp, sizeof(cmdbuf));
else
- strncpy(cmdbuf, copy, sizeof(cmdbuf) - 1 - strlen(cmdbuf));
+ strlcpy(cmdbuf, copy, sizeof(cmdbuf));
free(copy);
}
#endif
struct sockaddr_storage adr;
unsigned int adr_length = sizeof(adr);
int e;
- unsigned int buflen = strlen(cmdbuf)+strlen(locuser)+32;
- char * chksumbuf = (char *) malloc(buflen);
+ char namebuf[32], *chksumbuf = NULL;
- if (chksumbuf == 0)
- goto error_cleanup;
if (getsockname(netfd, (struct sockaddr *) &adr, &adr_length) != 0)
goto error_cleanup;
e = getnameinfo((struct sockaddr *)&adr, adr_length, 0, 0,
- chksumbuf, buflen, NI_NUMERICSERV);
- if (e) {
- free(chksumbuf);
+ namebuf, sizeof(namebuf), NI_NUMERICSERV);
+ if (e)
fatal(netfd, "local error: can't examine port number");
- }
- if (strlen(chksumbuf) > 30) {
- free(chksumbuf);
- fatal(netfd, "wacky local port number?!");
- }
- strcat(chksumbuf, ":");
- strcat(chksumbuf,cmdbuf);
- strcat(chksumbuf,locuser);
+ if (asprintf(&chksumbuf, "%s:%s%s", namebuf, cmdbuf, locuser) < 0)
+ goto error_cleanup;
status = krb5_verify_checksum(bsd_context,
authenticator->checksum->checksum_type,
if(msg_data.app_length < sizeof(ibuf) - 2) {
memmove(ibuf, msg_data.app_data,
msg_data.app_length);
- strcpy(&ibuf[msg_data.app_length], "\r\n");
+ memcpy(&ibuf[msg_data.app_length], "\r\n",
+ 3);
} else {
printf("Message too long!");
}
if(msg_buf.length < sizeof(ibuf) - 2 - 1) {
memcpy(ibuf, msg_buf.value,
msg_buf.length);
- strcpy(&ibuf[msg_buf.length], "\r\n");
+ memcpy(&ibuf[msg_buf.length], "\r\n", 3);
} else {
user_gss_error(maj_stat, min_stat,
"reply was too long");
*gpathp = 0;
if (gethdir(gpath + 1))
globerr = "Unknown user name after ~";
- (void) strcpy(gpath, gpath + 1);
+ (void) memmove(gpath, gpath + 1,
+ strlen(gpath));
} else
(void) strncpy(gpath, home, FTP_BUFSIZ - 1);
gpath[FTP_BUFSIZ - 1] = '\0';
return(s);
}
(void) memcpy(s, msg_data.app_data, msg_data.app_length);
- (void) strcpy(s+msg_data.app_length, "\r\n");
+ (void) memcpy(s+msg_data.app_length, "\r\n", 3);
}
#endif /* KRB5_KRB4_COMPAT */
#ifdef GSSAPI
}
memcpy(s, msg_buf.value, msg_buf.length);
- strcpy(s+msg_buf.length-(s[msg_buf.length-1]?0:1), "\r\n");
+ memcpy(s+msg_buf.length-(s[msg_buf.length-1]?0:1), "\r\n", 3);
gss_release_buffer(&min_stat, &msg_buf);
}
#endif /* GSSAPI */
write(2, "Gettytab entry too long\n", 24);
q[TABBUFSIZ - (p-tbuf)] = 0;
}
- strcpy(p, q+1);
+ strlcpy(p, q+1, TABBUFSIZ - (p-tbuf));
tbuf = holdtbuf;
return(1);
}
{
char *cp, *fullname;
krb5_error_code retval;
+ int result;
/* assumes def_realm is initialized! */
- fullname = (char *)malloc(strlen(name) + 1 + strlen(def_realm) + 1);
- if (fullname == NULL)
- return ENOMEM;
- strcpy(fullname, name);
- cp = strchr(fullname, '@');
+ cp = strchr(name, '@');
while (cp) {
- if (cp - fullname && *(cp - 1) != '\\')
+ if (cp - name && *(cp - 1) != '\\')
break;
else
cp = strchr(cp + 1, '@');
}
- if (cp == NULL) {
- strcat(fullname, "@");
- strcat(fullname, def_realm);
- }
+ if (cp == NULL)
+ result = asprintf(&fullname, "%s@%s", name, def_realm);
+ else
+ fullname = strdup(name);
+ if (result < 0)
+ return ENOMEM;
retval = krb5_parse_name(context, fullname, principal);
free(fullname);
return retval;
extern int setup_gss_names(struct svc_req *, gss_buffer_desc *,
gss_buffer_desc *);
-extern char *client_addr(struct svc_req *, char *);
extern void *global_server_handle;
extern int nofork;
extern short l_port;
static char abuf[33];
-char *client_addr(struct svc_req *svc, char *buf) {
- return strcpy(buf, inet_ntoa(svc->rq_xprt->xp_raddr.sin_addr));
+/* Result is stored in a static buffer and is invalidated by the next call. */
+static const char *client_addr(struct svc_req *svc) {
+ strlcpy(abuf, inet_ntoa(svc->rq_xprt->xp_raddr.sin_addr), sizeof(abuf));
+ return abuf;
}
static char *reply_ok_str = "UPDATE_OK";
krb5_klog_syslog(LOG_NOTICE, LOG_UNAUTH, whoami,
"<null>", client_name, service_name,
- client_addr(rqstp, abuf));
+ client_addr(rqstp));
goto out;
}
obuf,
((kret == 0) ? "success" : error_message(kret)),
client_name, service_name,
- client_addr(rqstp, abuf));
+ client_addr(rqstp));
out:
if (nofork)
* Return arg cl str ptr on success, else NULL.
*/
static char *
-getclhoststr(char *clprinc, char *cl, int len)
+getclhoststr(char *clprinc, char *cl, size_t len)
{
char *s;
if ((s = strchr(clprinc, '/')) != NULL) {
krb5_klog_syslog(LOG_NOTICE, LOG_UNAUTH, whoami,
"<null>", client_name, service_name,
- client_addr(rqstp, abuf));
+ client_addr(rqstp));
goto out;
}
"<null>",
"success",
client_name, service_name,
- client_addr(rqstp, abuf));
+ client_addr(rqstp));
goto out;
}
char *realm;
char *trans;
char *otrans, *otrans_ptr;
+ size_t bufsize;
/* The following are for stepping through the transited field */
/* +1 for null,
+1 for extra comma which may be added between
+1 for potential space when leading slash in realm */
- if (!(trans = (char *) malloc(strlen(realm) + strlen(otrans) + 3))) {
+ bufsize = strlen(realm) + strlen(otrans) + 3;
+ if (bufsize > MAX_REALM_LN)
+ bufsize = MAX_REALM_LN;
+ if (!(trans = (char *) malloc(bufsize))) {
retval = ENOMEM;
goto fail;
}
}
if (new_trans->length != 0) {
- if (strlen(trans) + 2 >= MAX_REALM_LN) {
+ if (strlcat(trans, ",", bufsize) >= bufsize) {
retval = KRB5KRB_AP_ERR_ILL_CR_TKT;
goto fail;
}
- strcat(trans, ",");
}
- if (strlen(trans) + strlen(current) + 1 >= MAX_REALM_LN) {
+ if (strlcat(trans, current, bufsize) >= bufsize) {
retval = KRB5KRB_AP_ERR_ILL_CR_TKT;
goto fail;
}
- strcat(trans, current);
new_trans->length = strlen(trans);
strncpy(prev, exp, sizeof(prev) - 1);
if (!added) {
if (new_trans->length != 0) {
- if (strlen(trans) + 2 >= MAX_REALM_LN) {
+ if (strlcat(trans, ",", bufsize) >= bufsize) {
retval = KRB5KRB_AP_ERR_ILL_CR_TKT;
goto fail;
}
- strcat(trans, ",");
}
if((realm[0] == '/') && trans[0]) {
- if (strlen(trans) + 2 >= MAX_REALM_LN) {
+ if (strlcat(trans, " ", bufsize) >= bufsize) {
retval = KRB5KRB_AP_ERR_ILL_CR_TKT;
goto fail;
}
- strcat(trans, " ");
}
- if (strlen(trans) + strlen(realm) + 1 >= MAX_REALM_LN) {
+ if (strlcat(trans, realm, bufsize) >= bufsize) {
retval = KRB5KRB_AP_ERR_ILL_CR_TKT;
goto fail;
}
- strcat(trans, realm);
new_trans->length = strlen(trans);
}
snprintf(stmp, sizeof(stmp), "%s%ld", i ? " " : "", (long)ktype[i]);
if (strlen(s) + strlen(stmp) + sizeof("}") > len)
break;
- strcat(s, stmp);
+ strlcat(s, stmp, len);
}
if (i < nktypes) {
/*
continue;
}
}
- strcat(s, "...");
+ strlcat(s, "...", len);
}
- strcat(s, "}");
+ strlcat(s, "}", len);
return;
}
if (rep->ticket != NULL) {
snprintf(stmp, sizeof(stmp),
" tkt=%ld", (long)rep->ticket->enc_part.enctype);
- strcat(s, stmp);
+ strlcat(s, stmp, len);
}
if (rep->ticket != NULL
&& rep->ticket->enc_part2->session != NULL) {
snprintf(stmp, sizeof(stmp), " ses=%ld",
(long)rep->ticket->enc_part2->session->enctype);
- strcat(s, stmp);
+ strlcat(s, stmp, len);
}
- strcat(s, "}");
+ strlcat(s, "}", len);
return;
}
KTEXT e_pkt = &e_pkt_st;
static char e_msg[128];
- strcpy(e_msg, "\nKerberos error -- ");
- strncat(e_msg, string, sizeof(e_msg) - 1 - 19);
+ snprintf(e_msg, sizeof(e_msg), "\nKerberos error -- %s", string);
cr_err_reply(e_pkt, req_name_ptr, req_inst_ptr, req_realm_ptr,
req_time_ws, err, e_msg);
return make_response((char *) e_pkt->dat, e_pkt->length);
}
*q++ = '\0';
if (!parsed_realm)
- strcpy(krb5_princ_realm(context, principal)->data, default_realm);
+ strlcpy(krb5_princ_realm(context, principal)->data, default_realm, realmsize + 1);
/*
* Alright, we're done. Now stuff a pointer to this monstrosity
* into the return variable, and let's get out of here.
struct srv_dns_entry **answers)
{
const unsigned char *p = NULL, *base = NULL;
- char host[MAXDNAME], *h;
- int size, ret, rdlen, nlen;
+ char host[MAXDNAME];
+ int size, ret, rdlen, nlen, len;
unsigned short priority, weight, port;
struct krb5int_dns_state *ds = NULL;
+ struct k5buf buf;
struct srv_dns_entry *head = NULL;
struct srv_dns_entry *srv = NULL, *entry = NULL;
if (memchr(realm->data, 0, realm->length))
return 0;
- if ( strlen(service) + strlen(protocol) + realm->length + 6
- > MAXDNAME )
- return 0;
- if (snprintf(host, sizeof(host), "%s.%s.%.*s",
- service, protocol, (int) realm->length,
- realm->data) >= sizeof(host))
- return 0;
+ krb5int_buf_init_fixed(&buf, host, sizeof(host));
+ krb5int_buf_add_fmt(&buf, "%s.%s.", service, protocol);
+ krb5int_buf_add_len(&buf, realm->data, realm->length);
/* Realm names don't (normally) end with ".", but if the query
doesn't end with "." and doesn't get an answer as is, the
a search on the prefix alone then the intention is to allow
the local domain or domain search lists to be expanded. */
- h = host + strlen (host);
- if ((h[-1] != '.') && ((h - host + 1) < sizeof(host)))
- strcpy (h, ".");
+ len = krb5int_buf_len(&buf);
+ if (len > 0 && host[len - 1] != '.')
+ krb5int_buf_add(&buf, ".");
+
+ if (krb5int_buf_cstr(&buf) == NULL)
+ return 0;
#ifdef TEST
fprintf (stderr, "sending DNS SRV query for %s\n", host);
srv->port = port;
/* The returned names are fully qualified. Don't let the
local resolver code do domain search path stuff. */
- if (strlen(host) + 2 < sizeof(host))
- strcat(host, ".");
- srv->host = strdup(host);
- if (srv->host == NULL) {
+ if (asprintf(&srv->host, "%s.", host) < 0) {
free(srv);
goto out;
}
{
krb5_error_code retval = KRB5_ERR_HOST_REALM_UNKNOWN;
const unsigned char *p, *base;
- char host[MAXDNAME], *h;
+ char host[MAXDNAME];
int ret, rdlen, len;
struct krb5int_dns_state *ds = NULL;
+ struct k5buf buf;
/*
* Form our query, and send it via DNS
*/
+ krb5int_buf_init_fixed(&buf, host, sizeof(host));
if (name == NULL || name[0] == '\0') {
- if (strlcpy(host, prefix, sizeof(host)) >= sizeof(host))
- return KRB5_ERR_HOST_REALM_UNKNOWN;
+ krb5int_buf_add(&buf, prefix);
} else {
- if ( strlen(prefix) + strlen(name) + 3 > MAXDNAME )
- return KRB5_ERR_HOST_REALM_UNKNOWN;
- if (snprintf(host, sizeof(host), "%s.%s", prefix, name) >= sizeof(host))
- return KRB5_ERR_HOST_REALM_UNKNOWN;
+ krb5int_buf_add_fmt(&buf, "%s.%s", prefix, name);
/* Realm names don't (normally) end with ".", but if the query
doesn't end with "." and doesn't get an answer as is, the
the local domain or domain search lists to be expanded.
*/
- h = host + strlen (host);
- if ((h > host) && (h[-1] != '.') && ((h - host + 1) < sizeof(host)))
- strcpy (h, ".");
+ len = krb5int_buf_len(&buf);
+ if (len > 0 && host[len - 1] != '.')
+ krb5int_buf_add(&buf, ".");
}
+ if (krb5int_buf_cstr(&buf) == NULL)
+ return KRB5_ERR_HOST_REALM_UNKNOWN;
ret = krb5int_dns_init(&ds, host, C_IN, T_TXT);
if (ret < 0)
goto errout;
/* Check if the entry has the path of a certificate */
if (!strncmp(start, "{FILE}", strlen("{FILE}"))) {
/* Set *password = {FILE}<path to cert>\0<cert password> */
- /*ptr = strchr(start, ':');
- if (ptr == NULL) { */
- *password = (unsigned char *)malloc(strlen(start) + 2);
+ size_t len = strlen(start);
+
+ *password = (unsigned char *)malloc(len + 2);
if (*password == NULL) {
st = ENOMEM;
goto rp_exit;
}
- (*password)[strlen(start) + 1] = '\0';
- (*password)[strlen(start)] = '\0';
- strcpy((char *)(*password), start);
+ memcpy((char *)(*password), start, len);
+ (*password)[len] = '\0';
+ (*password)[len + 1] = '\0';
goto got_password;
} else {
CT.value = (unsigned char *)start;
{
krb5_data rdat;
char *prompt;
+ const char *warning;
krb5_prompt kprompt;
krb5_prompt_type prompt_type;
int r = 0;
rdat.data = NULL;
rdat.length = 0;
} else {
- if ((prompt = (char *) malloc(sizeof (tip->label) + 32)) == NULL)
- return ENOMEM;
- sprintf(prompt, "%.*s PIN", sizeof (tip->label), tip->label);
if (tip->flags & CKF_USER_PIN_LOCKED)
- strcat(prompt, " (Warning: PIN locked)");
+ warning = " (Warning: PIN locked)";
else if (tip->flags & CKF_USER_PIN_FINAL_TRY)
- strcat(prompt, " (Warning: PIN final try)");
+ warning = " (Warning: PIN final try)";
else if (tip->flags & CKF_USER_PIN_COUNT_LOW)
- strcat(prompt, " (Warning: PIN count low)");
+ warning = " (Warning: PIN count low)";
+ else
+ warning = "";
+ if (asprintf(&prompt, "%.*s PIN%s", (int) sizeof (tip->label),
+ tip->label, warning) < 0)
+ return ENOMEM;
rdat.data = (char *)malloc(tip->ulMaxPinLen + 2);
rdat.length = tip->ulMaxPinLen + 1;
krb5_etype_info_entry *** p;
{
krb5_etype_info_entry **info;
- int i;
- char buf[80];
+ int i, len;
+ char *str;
info = malloc(sizeof(krb5_etype_info_entry *) * 4);
if (!info)
if (info[i] == 0)
goto memfail;
info[i]->etype = i;
- sprintf(buf, "Morton's #%d", i);
- info[i]->length = strlen(buf);
- info[i]->salt = (unsigned char *) strdup(buf);
- if (info[i]->salt == 0)
+ len = asprintf(&str, "Morton's #%d", i);
+ if (len < 0)
goto memfail;
+ info[i]->salt = (krb5_octet *) str;
+ info[i]->length = len;
info[i]->s2kparams.data = NULL;
info[i]->s2kparams.length = 0;
info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
krb5_etype_info_entry *** p;
{
krb5_etype_info_entry **info;
- int i;
- char buf[80];
+ int i, len;
+ char *str;
info = malloc(sizeof(krb5_etype_info_entry *) * 4);
if (!info)
if (info[i] == 0)
goto memfail;
info[i]->etype = i;
- sprintf(buf, "Morton's #%d", i);
- info[i]->length = strlen(buf);
- info[i]->salt = (unsigned char *) strdup(buf);
- if (info[i]->salt == 0)
+ len = asprintf(&str, "Morton's #%d", i);
+ if (len < 0)
goto memfail;
- sprintf(buf, "s2k: %d", i);
- info[i]->s2kparams.data = malloc(strlen(buf)+1);
- if (info[i]->s2kparams.data == NULL)
+ info[i]->salt = (krb5_octet *) str;
+ info[i]->length = (unsigned int) len;
+ len = asprintf(&info[i]->s2kparams.data, "s2k: %d", i);
+ if (len < 0)
goto memfail;
- strcpy( info[i]->s2kparams.data, buf);
- info[i]->s2kparams.length = strlen(buf);
+ info[i]->s2kparams.length = (unsigned int) len;
info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
}
free(info[1]->salt);
#ifdef ENABLE_LDAP
static krb5_error_code ktest_make_sample_key_data(krb5_key_data *p, int i)
{
- char buf[10];
+ char *str;
+ int len;
p->key_data_ver = 2;
p->key_data_kvno = 42;
- sprintf(buf, "key%d", i);
+ len = asprintf(&str, "key%d", i);
p->key_data_type[0] = 2;
- p->key_data_length[0] = strlen(buf);
- p->key_data_contents[0] = strdup(buf);
- sprintf(buf, "salt%d", i);
+ p->key_data_length[0] = (unsigned int) len;
+ p->key_data_contents[0] = (krb5_octet *) str;
+ len = asprintf(&str, "salt%d", i);
p->key_data_type[1] = i;
- p->key_data_length[1] = strlen(buf);
- p->key_data_contents[1] = strdup(buf);
+ p->key_data_length[1] = (unsigned int) len;
+ p->key_data_contents[1] = (krb5_octet *) str;
if (p->key_data_contents[0] == NULL || p->key_data_contents[1] == NULL)
return ENOMEM;
return 0;
memset(d, 0, len);
fcopy = (char *) d + slen;
assert(fcopy == d->filespec);
- strcpy(fcopy, filename);
+ strlcpy(fcopy, filename, flen + 1);
d->refcount = 1;
d->comment = NULL;
d->magic = PROF_MAGIC_FILE_DATA;