} else {
if (*(ptr = &time_string[strlen(time_string)-1]) == '\n')
*ptr = '\0';
- sprintf(msg_ret, errstr, time_string);
+ snprintf(msg_ret, msg_len, errstr, time_string);
}
}
fprintf(stderr, "%s: Cannot bind socket.\n", whoami);
fprintf(stderr, "bind: %s\n", e_txt);
errno = oerrno;
- sprintf(portbuf, "%d", ntohs(addr.sin_port));
+ snprintf(portbuf, sizeof(portbuf), "%d", ntohs(addr.sin_port));
krb5_klog_syslog(LOG_ERR, "cannot bind simple chpw socket: %s",
e_txt);
if(oerrno == EADDRINUSE) {
{
char *fullname;
- fullname = (char *) malloc(strlen(name) + 1 +
- (realm ? strlen(realm) + 1 : 0));
- if (fullname == NULL)
- return NULL;
- if (realm)
- sprintf(fullname, "%s@%s", name, realm);
- else
- strcpy(fullname, name);
+ if (realm) {
+ if (asprintf(&fullname, "%s@%s", name, realm) < 0)
+ fullname = NULL;
+ } else
+ fullname = strdup(name);
+
return fullname;
}
if (vno != 1) {
ret = KRB5KDC_ERR_BAD_PVNO;
numresult = KRB5_KPASSWD_BAD_VERSION;
- sprintf(strresult,
- "Request contained unknown protocol version number %d", vno);
+ snprintf(strresult, sizeof(strresult),
+ "Request contained unknown protocol version number %d", vno);
goto chpwfail;
}
return;
}
- sprintf(s, "%d etypes {", nktypes);
+ snprintf(s, len, "%d etypes {", nktypes);
for (i = 0; i < nktypes; i++) {
- sprintf(stmp, "%s%ld", i ? " " : "", (long)ktype[i]);
+ snprintf(stmp, sizeof(stmp), "%s%ld", i ? " " : "", (long)ktype[i]);
if (strlen(s) + strlen(stmp) + sizeof("}") > len)
break;
strcat(s, stmp);
return;
}
- sprintf(s, "etypes {rep=%ld", (long)rep->enc_part.enctype);
+ snprintf(s, len, "etypes {rep=%ld", (long)rep->enc_part.enctype);
if (rep->ticket != NULL) {
- sprintf(stmp, " tkt=%ld", (long)rep->ticket->enc_part.enctype);
+ snprintf(stmp, sizeof(stmp),
+ " tkt=%ld", (long)rep->ticket->enc_part.enctype);
strcat(s, stmp);
}
if (rep->ticket != NULL
&& rep->ticket->enc_part2 != NULL
&& rep->ticket->enc_part2->session != NULL) {
- sprintf(stmp, " ses=%ld",
- (long)rep->ticket->enc_part2->session->enctype);
+ snprintf(stmp, sizeof(stmp), " ses=%ld",
+ (long)rep->ticket->enc_part2->session->enctype);
strcat(s, stmp);
}
strcat(s, "}");
case L_TKT_REQ:
case L_APPL_REQ:
strcpy(log_text, "PROCESS_V4:");
- vsprintf(log_text+strlen(log_text), format, pvar);
+ vsnprintf(log_text+strlen(log_text),
+ sizeof(log_text) - strlen(log_text),
+ format, pvar);
krb5_klog_syslog(logpri, "%s", log_text);
default:
/* ignore the other types... */
pause(); */
} else {
char buf[256];
- sprintf(buf,
+ snprintf(buf, sizeof(buf),
"Kerberos will wait %d seconds before dying so as not to loop init",
(int) pause_int);
klog(L_KRB_PERR, buf);
toggle ^= 1;
date = &principal->mod_date, text = principal->mod_date_txt) {
tp = localtime( (time_t *) date);
- sprintf( text, "%4d-%02d-%02d",
+ snprintf(text, sizeof(principal->mod_date_txt), "%4d-%02d-%02d",
tp->tm_year > 1900 ? tp->tm_year : tp->tm_year + 1900,
tp->tm_mon + 1, tp->tm_mday); /* January is 0, not 1 */
}
break;
case 'd': /* pathname for db */
/* now db_name is not a seperate argument. It has to be passed as part of the db_args */
- if( db_name == NULL )
- {
- db_name = malloc(sizeof("dbname=") + strlen(optarg));
- if( db_name == NULL )
- {
- fprintf(stderr,"%s: KDC cannot initialize. Not enough memory\n",
- argv[0] );
- exit(1);
+ if( db_name == NULL ) {
+ if (asprintf(&db_name, "dbname=%s", optarg) < 0) {
+ fprintf(stderr,
+ "%s: KDC cannot initialize. Not enough memory\n",
+ argv[0]);
+ exit(1);
}
-
- sprintf( db_name, "dbname=%s", optarg);
}
db_args_size++;
if ((retval = krb5_db2_db_get_age(context, NULL, &db_ctx->db_lf_time)))
goto err_out;
- sprintf(policy_db_name, db_ctx->tempdb ? "%s~.kadm5" : "%s.kadm5",
- db_ctx->db_name);
- sprintf(policy_lock_name, "%s.lock", policy_db_name);
+ snprintf(policy_db_name, sizeof(policy_db_name),
+ db_ctx->tempdb ? "%s~.kadm5" : "%s.kadm5",
+ db_ctx->db_name);
+ snprintf(policy_lock_name, sizeof(policy_lock_name),
+ "%s.lock", policy_db_name);
if ((retval = osa_adb_init_db(&db_ctx->policy_db, policy_db_name,
policy_lock_name, OSA_ADB_POLICY_DB_MAGIC)))
free_dbsuffix(okname);
}
- sprintf(policy_db_name, "%s.kadm5", db_name2);
- sprintf(policy_lock_name, "%s.lock", policy_db_name);
+ snprintf(policy_db_name, sizeof(policy_db_name), "%s.kadm5", db_name2);
+ snprintf(policy_lock_name, sizeof(policy_lock_name),
+ "%s.lock", policy_db_name);
retval = osa_adb_create_db(policy_db_name,
policy_lock_name, OSA_ADB_POLICY_DB_MAGIC);
if (retval1 || retval2)
return (retval1 ? retval1 : retval2);
- sprintf(policy_db_name, "%s.kadm5", dbname);
- sprintf(policy_lock_name, "%s.lock", policy_db_name);
+ snprintf(policy_db_name, sizeof(policy_db_name), "%s.kadm5", dbname);
+ snprintf(policy_lock_name, sizeof(policy_lock_name),
+ "%s.lock", policy_db_name);
retval1 = osa_adb_destroy_db(policy_db_name,
policy_lock_name, OSA_ADB_POLICY_DB_MAGIC);
now. */
char policy[2048], new_policy[2048];
assert (strlen(db_ctx->db_name) < 2000);
- sprintf(policy, "%s.kadm5", db_ctx->db_name);
- sprintf(new_policy, "%s~.kadm5", db_ctx->db_name);
+ snprintf(policy, sizeof(policy), "%s.kadm5", db_ctx->db_name);
+ snprintf(new_policy, sizeof(new_policy),
+ "%s~.kadm5", db_ctx->db_name);
if (0 != rename(new_policy, policy)) {
retval = errno;
goto errout;
if (envtmp && ((strlen(envtmp)+sizeof(fn)+1) > sizeof(path)))
return(-1);
- (void)sprintf(path, "%s%s", (envtmp ? envtmp : "/tmp"), fn);
+ (void)snprintf(path, sizeof(path),
+ "%s%s", (envtmp ? envtmp : "/tmp"), fn);
#ifdef SIG_BLOCK
(void)sigfillset(&set);