diff options
author | Greg Hudson <ghudson@mit.edu> | 2008-10-30 19:32:50 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2008-10-30 19:32:50 +0000 |
commit | 5a36d207b1e79b53cd0e440e5b5229148ad23772 (patch) | |
tree | c149eb4199a310d1bca2c18271c9ab9f222c4bc1 /src/lib/kadm5/str_conv.c | |
parent | 131ac802ba0975a047c72f010657f3200b9a2be5 (diff) | |
download | krb5-5a36d207b1e79b53cd0e440e5b5229148ad23772.zip krb5-5a36d207b1e79b53cd0e440e5b5229148ad23772.tar.gz krb5-5a36d207b1e79b53cd0e440e5b5229148ad23772.tar.bz2 |
Use the k5buf module instead of strcpy/strcat in several places
ticket: 6200
status: open
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20941 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/kadm5/str_conv.c')
-rw-r--r-- | src/lib/kadm5/str_conv.c | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c index b9e58aa..7ffcc8e 100644 --- a/src/lib/kadm5/str_conv.c +++ b/src/lib/kadm5/str_conv.c @@ -173,45 +173,29 @@ krb5_flags_to_string(flags, sep, buffer, buflen) int i; krb5_flags pflags; const char *sepstring; - char *op; - int initial; - krb5_error_code retval; + struct k5buf buf; - retval = 0; - op = buffer; pflags = 0; - initial = 1; sepstring = (sep) ? sep : flags_default_sep; + krb5int_buf_init_fixed(&buf, buffer, buflen); /* Blast through the table matching all we can */ for (i=0; i<flags_table_nents; i++) { if (flags & flags_table[i].fl_flags) { - /* Found a match, see if it'll fit into the output buffer */ - if ((op+strlen(flags_table[i].fl_output)+strlen(sepstring)) < - (buffer + buflen)) { - if (!initial) { - strcpy(op, sep); - op += strlen(sep); - } - initial = 0; - strcpy(op, flags_table[i].fl_output); - op += strlen(flags_table[i].fl_output); - } - else { - retval = ENOMEM; - break; - } + if (krb5int_buf_len(&buf) > 0) + krb5int_buf_add(&buf, sepstring); + krb5int_buf_add(&buf, flags_table[i].fl_output); /* Keep track of what we matched */ pflags |= flags_table[i].fl_flags; } } - if (!retval) { - /* See if there's any leftovers */ - if (flags & ~pflags) - retval = EINVAL; - else if (initial) - *buffer = '\0'; - } - return(retval); + if (krb5int_buf_cstr(&buf) == NULL) + return(ENOMEM); + + /* See if there's any leftovers */ + if (flags & ~pflags) + return(EINVAL); + + return(0); } krb5_error_code |