use strlcat/strlcpy, from openbsd

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@12046 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2003-04-16 16:13:08 +00:00
parent c30d73e07e
commit 6223cf0f22
2 changed files with 15 additions and 11 deletions

View File

@@ -166,28 +166,32 @@ expand_realms(krb5_context context,
for(r = realms; r; r = r->next){
if(r->trailing_dot){
char *tmp;
size_t len = strlen(r->realm) + strlen(prev_realm) + 1;
if(prev_realm == NULL)
prev_realm = client_realm;
tmp = realloc(r->realm, strlen(r->realm) + strlen(prev_realm) + 1);
tmp = realloc(r->realm, len);
if(tmp == NULL){
free_realms(realms);
krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
r->realm = tmp;
strcat(r->realm, prev_realm);
strlcat(r->realm, prev_realm, len);
}else if(r->leading_slash && !r->leading_space && prev_realm){
/* yet another exception: if you use x500-names, the
leading realm doesn't have to be "quoted" with a space */
char *tmp;
tmp = malloc(strlen(r->realm) + strlen(prev_realm) + 1);
size_t len = strlen(r->realm) + strlen(prev_realm) + 1;
tmp = malloc(len);
if(tmp == NULL){
free_realms(realms);
krb5_set_error_string (context, "malloc: out of memory");
return ENOMEM;
}
strcpy(tmp, prev_realm);
strcat(tmp, r->realm);
strlcpy(tmp, prev_realm, len);
strlcat(tmp, r->realm, len);
free(r->realm);
r->realm = tmp;
}
@@ -368,10 +372,10 @@ krb5_domain_x500_encode(char **realms, int num_realms, krb5_data *encoding)
*s = '\0';
for(i = 0; i < num_realms; i++){
if(i && i < num_realms - 1)
strcat(s, ",");
strlcat(s, ",", len + 1);
if(realms[i][0] == '/')
strcat(s, " ");
strcat(s, realms[i]);
strlcat(s, " ", len + 1);
strlcat(s, realms[i], len + 1);
}
encoding->data = s;
encoding->length = strlen(s);

View File

@@ -52,9 +52,9 @@ _warnerr(krb5_context context, int do_errtext,
args[0] = args[1] = NULL;
arg = args;
if(fmt){
strcat(xfmt, "%s");
strlcat(xfmt, "%s", sizeof(xfmt));
if(do_errtext)
strcat(xfmt, ": ");
strlcat(xfmt, ": ", sizeof(xfmt));
vasprintf(&msg, fmt, ap);
if(msg == NULL)
return ENOMEM;
@@ -63,7 +63,7 @@ _warnerr(krb5_context context, int do_errtext,
if(context && do_errtext){
const char *err_msg;
strcat(xfmt, "%s");
strlcat(xfmt, "%s", sizeof(xfmt));
err_str = krb5_get_error_string(context);
if (err_str != NULL) {