From ddf60ba5e894ad339c96c6f61446dfc8cb79e779 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 5 Nov 2008 17:08:47 +0000 Subject: [PATCH] Rename krb5int_buf_cstr to krb5int_buf_data, since k5bufs can be used for binary data as well as C string data. The buffer will always have a null byte at krb5int_buf_len bytes regardless of whether it contains C string data. ticket: 6200 status: open git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21003 dc483132-0cff-0310-8789-dd5450dbe970 --- src/clients/ksu/authorization.c | 2 +- src/include/k5-buf.h | 6 ++-- src/lib/crypto/t_hmac.c | 2 +- src/lib/gssapi/mechglue/oid_ops.c | 2 +- src/lib/kadm5/alt_prof.c | 2 +- src/lib/kadm5/str_conv.c | 2 +- src/lib/krb5/krb/preauth.c | 2 +- src/lib/krb5/krb/srv_rcache.c | 2 +- src/lib/krb5/os/dnssrv.c | 2 +- src/lib/krb5/os/hst_realm.c | 2 +- src/lib/krb5/os/sendto_kdc.c | 4 +-- .../kdb/ldap/libkdb_ldap/ldap_principal.c | 2 +- src/util/support/k5buf.c | 2 +- src/util/support/libkrb5support-fixed.exports | 2 +- src/util/support/t_k5buf.c | 32 +++++++++---------- 15 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/clients/ksu/authorization.c b/src/clients/ksu/authorization.c index 829251d81..fa596230b 100644 --- a/src/clients/ksu/authorization.c +++ b/src/clients/ksu/authorization.c @@ -515,7 +515,7 @@ krb5_boolean find_first_cmd_that_exists(fcmd_arr, cmd_out, err_out) for(j= 0; j < i; j ++) krb5int_buf_add_fmt(&buf, " %s ", fcmd_arr[j]); krb5int_buf_add(&buf, "\n"); - *err_out = krb5int_buf_cstr(&buf); + *err_out = krb5int_buf_data(&buf); if (*err_out == NULL) { perror(prog_name); exit(1); diff --git a/src/include/k5-buf.h b/src/include/k5-buf.h index 885c2fdc2..de869d347 100644 --- a/src/include/k5-buf.h +++ b/src/include/k5-buf.h @@ -106,17 +106,17 @@ void krb5int_buf_truncate(struct k5buf *buf, size_t len); For a dynamic buffer, any buffer modification operation except krb5int_buf_truncate may invalidate the byte array address. */ -char *krb5int_buf_cstr(struct k5buf *buf); +char *krb5int_buf_data(struct k5buf *buf); /* Retrieve the length of BUF, or -1 if there has been an allocation failure or the fixed buffer ran out of room. The length is equal - to strlen(krb5int_buf_cstr(buf)) unless binary data was added with + to strlen(krb5int_buf_data(buf)) unless binary data was added with krb5int_buf_add_len. */ ssize_t krb5int_buf_len(struct k5buf *buf); /* Free the storage used in the dynamic buffer BUF. The caller may choose to take responsibility for freeing the return value of - krb5int_buf_cstr instead of using this function. If BUF is a fixed + krb5int_buf_data instead of using this function. If BUF is a fixed buffer, an assertion failure will result. It is unnecessary (though harmless) to free a buffer after an error is detected; the storage will already have been freed in that case. */ diff --git a/src/lib/crypto/t_hmac.c b/src/lib/crypto/t_hmac.c index 63b90c76f..bf629c359 100644 --- a/src/lib/crypto/t_hmac.c +++ b/src/lib/crypto/t_hmac.c @@ -245,7 +245,7 @@ static void test_hmac() krb5int_buf_add(&buf, "0x"); for (j = 0; j < out.length; j++) krb5int_buf_add_fmt(&buf, "%02x", 0xff & outbuf[j]); - if (krb5int_buf_cstr(&buf) == NULL) + if (krb5int_buf_data(&buf) == NULL) abort(); if (strcmp(stroutbuf, md5tests[i].hexdigest)) { printf("*** CHECK FAILED!\n" diff --git a/src/lib/gssapi/mechglue/oid_ops.c b/src/lib/gssapi/mechglue/oid_ops.c index 44d79f361..9e77ef1be 100644 --- a/src/lib/gssapi/mechglue/oid_ops.c +++ b/src/lib/gssapi/mechglue/oid_ops.c @@ -256,7 +256,7 @@ generic_gss_oid_to_str(minor_status, oid, oid_str) } } krb5int_buf_add(&buf, "}"); - bp = krb5int_buf_cstr(&buf); + bp = krb5int_buf_data(&buf); if (bp == NULL) { *minor_status = ENOMEM; return(GSS_S_FAILURE); diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c index 8fa742c2e..b6d8bdc14 100644 --- a/src/lib/kadm5/alt_prof.c +++ b/src/lib/kadm5/alt_prof.c @@ -92,7 +92,7 @@ krb5_aprof_init(fname, envname, acontextp) krb5int_buf_add(&buf, filenames[i]); } krb5_free_config_files(filenames); - profile_path = krb5int_buf_cstr(&buf); + profile_path = krb5int_buf_data(&buf); if (profile_path == NULL) return ENOMEM; profile = (profile_t) NULL; diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c index 7ffcc8e11..c35d51521 100644 --- a/src/lib/kadm5/str_conv.c +++ b/src/lib/kadm5/str_conv.c @@ -188,7 +188,7 @@ krb5_flags_to_string(flags, sep, buffer, buflen) pflags |= flags_table[i].fl_flags; } } - if (krb5int_buf_cstr(&buf) == NULL) + if (krb5int_buf_data(&buf) == NULL) return(ENOMEM); /* See if there's any leftovers */ diff --git a/src/lib/krb5/krb/preauth.c b/src/lib/krb5/krb/preauth.c index 32249df87..11574116a 100644 --- a/src/lib/krb5/krb/preauth.c +++ b/src/lib/krb5/krb/preauth.c @@ -444,7 +444,7 @@ char *handle_sam_labels(krb5_sam_challenge *sc) } krb5int_buf_add_len(&buf, prompt, prompt_len); krb5int_buf_add(&buf, ": "); - return krb5int_buf_cstr(&buf); + return krb5int_buf_data(&buf); } /* diff --git a/src/lib/krb5/krb/srv_rcache.c b/src/lib/krb5/krb/srv_rcache.c index 4ce073301..a426881d4 100644 --- a/src/lib/krb5/krb/srv_rcache.c +++ b/src/lib/krb5/krb/srv_rcache.c @@ -66,7 +66,7 @@ krb5_get_server_rcache(krb5_context context, const krb5_data *piece, krb5int_buf_add_fmt(&buf, "_%lu", uid); #endif - cachename = krb5int_buf_cstr(&buf); + cachename = krb5int_buf_data(&buf); if (cachename == NULL) return ENOMEM; diff --git a/src/lib/krb5/os/dnssrv.c b/src/lib/krb5/os/dnssrv.c index e10d01d04..4dcd57cb8 100644 --- a/src/lib/krb5/os/dnssrv.c +++ b/src/lib/krb5/os/dnssrv.c @@ -99,7 +99,7 @@ krb5int_make_srv_query_realm(const krb5_data *realm, if (len > 0 && host[len - 1] != '.') krb5int_buf_add(&buf, "."); - if (krb5int_buf_cstr(&buf) == NULL) + if (krb5int_buf_data(&buf) == NULL) return 0; #ifdef TEST diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index 038348eae..2150ab38a 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -119,7 +119,7 @@ krb5_try_realm_txt_rr(const char *prefix, const char *name, char **realm) if (len > 0 && host[len - 1] != '.') krb5int_buf_add(&buf, "."); } - if (krb5int_buf_cstr(&buf) == NULL) + if (krb5int_buf_data(&buf) == NULL) return KRB5_ERR_HOST_REALM_UNKNOWN; ret = krb5int_dns_init(&ds, host, C_IN, T_TXT); if (ret < 0) diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c index 46ed6f6af..971047b54 100644 --- a/src/lib/krb5/os/sendto_kdc.c +++ b/src/lib/krb5/os/sendto_kdc.c @@ -240,8 +240,8 @@ krb5int_debug_fprint (const char *fmt, ...) krb5int_buf_add_fmt(&buf, " af%d", ai->ai_addr->sa_family); } else krb5int_buf_add_fmt(&buf, " %s.%s", addrbuf, portbuf); - if (krb5int_buf_cstr(&buf)) - putstr(krb5int_buf_cstr(&buf)); + if (krb5int_buf_data(&buf)) + putstr(krb5int_buf_data(&buf)); krb5int_free_buf(&buf); break; case 'D': diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal.c index 26f498453..d0b7aa1dc 100644 --- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal.c +++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_principal.c @@ -468,7 +468,7 @@ krb5_ldap_parse_principal_name(i_princ_name, o_princ_name) krb5int_buf_add_len(&buf, p, 1); } krb5int_buf_add(&buf, at_rlm_name); - *o_princ_name = krb5int_buf_cstr(&buf); + *o_princ_name = krb5int_buf_data(&buf); if (!*o_princ_name) return ENOMEM; } diff --git a/src/util/support/k5buf.c b/src/util/support/k5buf.c index 974893d6e..0bdffb1ad 100644 --- a/src/util/support/k5buf.c +++ b/src/util/support/k5buf.c @@ -192,7 +192,7 @@ void krb5int_buf_truncate(struct k5buf *buf, size_t len) } -char *krb5int_buf_cstr(struct k5buf *buf) +char *krb5int_buf_data(struct k5buf *buf) { return (buf->buftype == ERROR) ? NULL : buf->data; } diff --git a/src/util/support/libkrb5support-fixed.exports b/src/util/support/libkrb5support-fixed.exports index 1b4b0a8a3..fef8fbac7 100644 --- a/src/util/support/libkrb5support-fixed.exports +++ b/src/util/support/libkrb5support-fixed.exports @@ -35,6 +35,6 @@ krb5int_buf_add krb5int_buf_add_len krb5int_buf_add_fmt krb5int_buf_truncate -krb5int_buf_cstr +krb5int_buf_data krb5int_buf_len krb5int_free_buf diff --git a/src/util/support/t_k5buf.c b/src/util/support/t_k5buf.c index cfb2547f6..bb60db440 100644 --- a/src/util/support/t_k5buf.c +++ b/src/util/support/t_k5buf.c @@ -63,7 +63,7 @@ static void test_basic() krb5int_buf_add(&buf, "Hello "); krb5int_buf_add_len(&buf, "world", 5); check_buf(&buf, "basic fixed"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || strcmp(s, "Hello world") != 0 || len != 11, "basic fixed"); @@ -71,7 +71,7 @@ static void test_basic() krb5int_buf_add_len(&buf, "Hello", 5); krb5int_buf_add(&buf, " world"); check_buf(&buf, "basic dynamic"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || strcmp(s, "Hello world") != 0 || len != 11, "basic dynamic"); krb5int_free_buf(&buf); @@ -93,7 +93,7 @@ static void test_realloc() krb5int_buf_add_len(&buf, data, 128); fail_if(buf.space != 256, "realloc 1"); check_buf(&buf, "realloc 1"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 138 || memcmp(s, data, len) != 0, "realloc 1"); @@ -101,7 +101,7 @@ static void test_realloc() krb5int_buf_add_len(&buf, data, 128); fail_if(buf.space != 512, "realloc 2"); check_buf(&buf, "realloc 2"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 266 || memcmp(s, data, len) != 0, "realloc 2"); krb5int_free_buf(&buf); @@ -112,7 +112,7 @@ static void test_realloc() krb5int_buf_add_len(&buf, data, 256); fail_if(buf.space != 512, "realloc 3"); check_buf(&buf, "realloc 3"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 266 || memcmp(s, data, len) != 0, "realloc 3"); krb5int_free_buf(&buf); @@ -123,7 +123,7 @@ static void test_realloc() krb5int_buf_add_len(&buf, data, 512); fail_if(buf.space != 1024, "realloc 4"); check_buf(&buf, "realloc 4"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 522 || memcmp(s, data, len) != 0, "realloc 4"); krb5int_free_buf(&buf); @@ -133,7 +133,7 @@ static void test_realloc() krb5int_buf_add_len(&buf, data, 10); krb5int_buf_add_len(&buf, NULL, SPACE_MAX); check_buf(&buf, "realloc 5"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(buf.buftype != ERROR || s != NULL || len != -1, "realloc 5"); krb5int_free_buf(&buf); @@ -143,7 +143,7 @@ static void test_realloc() krb5int_buf_add_len(&buf, data, 100); krb5int_buf_add_len(&buf, NULL, SPACE_MAX * 2); check_buf(&buf, "realloc 6"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(buf.buftype != ERROR || s != NULL || len != -1, "realloc 6"); krb5int_free_buf(&buf); @@ -160,7 +160,7 @@ static void test_overflow() krb5int_buf_add(&buf, "12345"); krb5int_buf_add(&buf, "12345"); check_buf(&buf, "overflow 1"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(buf.buftype != ERROR || s != NULL || len != -1, "overflow 1"); @@ -169,7 +169,7 @@ static void test_overflow() krb5int_buf_add(&buf, "12345"); krb5int_buf_add_len(&buf, NULL, SPACE_MAX * 2); check_buf(&buf, "overflow 2"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(buf.buftype != ERROR || s != NULL || len != -1, "overflow 2"); } @@ -204,7 +204,7 @@ static void test_truncate() krb5int_buf_add(&buf, "fghij"); krb5int_buf_truncate(&buf, 7); check_buf(&buf, "truncate"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 7 || strcmp(s, "abcdefg") != 0, "truncate"); krb5int_free_buf(&buf); @@ -220,7 +220,7 @@ static void test_binary() krb5int_buf_add_len(&buf, data, 3); krb5int_buf_add_len(&buf, data, 3); check_buf(&buf, "binary"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 6, "binary"); fail_if(s[0] != 'a' || s[1] != 0 || s[2] != 'b', "binary"); @@ -244,14 +244,14 @@ static void test_fmt() krb5int_buf_add(&buf, "foo"); krb5int_buf_add_fmt(&buf, " %d ", 3); check_buf(&buf, "fmt 1"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 6 || strcmp(s, "foo 3 ") != 0, "fmt 1"); /* Overflow the same buffer with formatted text. */ krb5int_buf_add_fmt(&buf, "%d%d%d%d", 1, 2, 3, 4); check_buf(&buf, "fmt 2"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(buf.buftype != ERROR || s != NULL || len != -1, "fmt 2"); @@ -260,7 +260,7 @@ static void test_fmt() krb5int_buf_add(&buf, "foo"); krb5int_buf_add_fmt(&buf, " %d ", 3); check_buf(&buf, "fmt 3"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 6 || strcmp(s, "foo 3 ") != 0, "fmt 3"); @@ -268,7 +268,7 @@ static void test_fmt() krb5int_buf_add_fmt(&buf, "%s", data); check_buf(&buf, "fmt 4"); fail_if(buf.space != 2048, "fmt 4"); - s = krb5int_buf_cstr(&buf); + s = krb5int_buf_data(&buf); len = krb5int_buf_len(&buf); fail_if(!s || len != 1029 || strcmp(s + 6, data) != 0, "fmt 4"); krb5int_free_buf(&buf); -- 2.26.2