diff options
author | Greg Hudson <ghudson@mit.edu> | 2013-02-14 11:41:10 -0500 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2013-02-14 11:42:28 -0500 |
commit | 6dda284554a869f7fa1e6d2a035df06c97f103ef (patch) | |
tree | 6854b38ce7274b914b82b20bfb65eb8130df1ab8 /src/util | |
parent | 80f53c8b2c745e75dc9d22acba63812d8533c133 (diff) | |
download | krb5-6dda284554a869f7fa1e6d2a035df06c97f103ef.tar.gz krb5-6dda284554a869f7fa1e6d2a035df06c97f103ef.tar.xz krb5-6dda284554a869f7fa1e6d2a035df06c97f103ef.zip |
Modernize k5buf
Rename the krb5int_buf_ family of functions to use the k5_ prefix for
brevity. Reformat some k5buf implementation code to match current
practices.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/gss-kernel-lib/t_kgss_user.c | 12 | ||||
-rw-r--r-- | src/util/support/json.c | 38 | ||||
-rw-r--r-- | src/util/support/k5buf-int.h | 11 | ||||
-rw-r--r-- | src/util/support/k5buf.c | 57 | ||||
-rw-r--r-- | src/util/support/libkrb5support-fixed.exports | 18 | ||||
-rw-r--r-- | src/util/support/t_k5buf.c | 208 |
6 files changed, 183 insertions, 161 deletions
diff --git a/src/util/gss-kernel-lib/t_kgss_user.c b/src/util/gss-kernel-lib/t_kgss_user.c index 8e13b46510..0af9aa6c82 100644 --- a/src/util/gss-kernel-lib/t_kgss_user.c +++ b/src/util/gss-kernel-lib/t_kgss_user.c @@ -138,7 +138,7 @@ start_child(int *to_child_out, int *from_child_out, pid_t *pid_out) *pid_out = pid; } -#define WRITE(b, d) krb5int_buf_add_len(b, (char *)&d, sizeof(d)) +#define WRITE(b, d) k5_buf_add_len(b, (char *)&d, sizeof(d)) /* Add the fields of lkey to bufp. */ static void @@ -146,7 +146,7 @@ add_lucid_key(struct k5buf *bufp, const gss_krb5_lucid_key_t *lkey) { WRITE(bufp, lkey->type); WRITE(bufp, lkey->length); - krb5int_buf_add_len(bufp, lkey->data, lkey->length); + k5_buf_add_len(bufp, lkey->data, lkey->length); } /* Using a machine-dependent format, marshal the fields of lctx into an @@ -157,7 +157,7 @@ marshal_lucid_context(const gss_krb5_lucid_context_v1_t *lctx, { struct k5buf buf; - krb5int_buf_init_dynamic(&buf); + k5_buf_init_dynamic(&buf); WRITE(&buf, lctx->version); WRITE(&buf, lctx->initiate); WRITE(&buf, lctx->endtime); @@ -175,9 +175,9 @@ marshal_lucid_context(const gss_krb5_lucid_context_v1_t *lctx, add_lucid_key(&buf, &lctx->cfx_kd.acceptor_subkey); } else abort(); - assert(krb5int_buf_data(&buf) != NULL); - *data_out = (unsigned char *)krb5int_buf_data(&buf); - *len_out = krb5int_buf_len(&buf); + assert(k5_buf_data(&buf) != NULL); + *data_out = (unsigned char *)k5_buf_data(&buf); + *len_out = k5_buf_len(&buf); } /* Export ctx as a lucid context, marshal it, and write it to fd. */ diff --git a/src/util/support/json.c b/src/util/support/json.c index e3edffd7cd..c7f6fdd4a9 100644 --- a/src/util/support/json.c +++ b/src/util/support/json.c @@ -575,22 +575,22 @@ encode_string(struct k5buf *buf, const char *str) size_t n; const char *p; - krb5int_buf_add(buf, "\""); + k5_buf_add(buf, "\""); while (*str != '\0') { n = strcspn(str, needs_quote); - krb5int_buf_add_len(buf, str, n); + k5_buf_add_len(buf, str, n); str += n; if (*str == '\0') break; - krb5int_buf_add(buf, "\\"); + k5_buf_add(buf, "\\"); p = strchr(quotemap_c, *str); if (p != NULL) - krb5int_buf_add_len(buf, quotemap_json + (p - quotemap_c), 1); + k5_buf_add_len(buf, quotemap_json + (p - quotemap_c), 1); else - krb5int_buf_add_fmt(buf, "u00%02X", (unsigned int)*str); + k5_buf_add_fmt(buf, "u00%02X", (unsigned int)*str); str++; } - krb5int_buf_add(buf, "\""); + k5_buf_add(buf, "\""); } struct obj_ctx { @@ -609,9 +609,9 @@ encode_obj_entry(void *ctx, const char *key, k5_json_value value) if (j->first) j->first = 0; else - krb5int_buf_add(j->buf, ","); + k5_buf_add(j->buf, ","); encode_string(j->buf, key); - krb5int_buf_add(j->buf, ":"); + k5_buf_add(j->buf, ":"); j->ret = encode_value(j->buf, value); } @@ -629,25 +629,25 @@ encode_value(struct k5buf *buf, k5_json_value val) type = k5_json_get_tid(val); switch (type) { case K5_JSON_TID_ARRAY: - krb5int_buf_add(buf, "["); + k5_buf_add(buf, "["); len = k5_json_array_length(val); for (i = 0; i < len; i++) { if (i != 0) - krb5int_buf_add(buf, ","); + k5_buf_add(buf, ","); ret = encode_value(buf, k5_json_array_get(val, i)); if (ret) return ret; } - krb5int_buf_add(buf, "]"); + k5_buf_add(buf, "]"); return 0; case K5_JSON_TID_OBJECT: - krb5int_buf_add(buf, "{"); + k5_buf_add(buf, "{"); ctx.buf = buf; ctx.ret = 0; ctx.first = 1; k5_json_object_iterate(val, encode_obj_entry, &ctx); - krb5int_buf_add(buf, "}"); + k5_buf_add(buf, "}"); return ctx.ret; case K5_JSON_TID_STRING: @@ -655,15 +655,15 @@ encode_value(struct k5buf *buf, k5_json_value val) return 0; case K5_JSON_TID_NUMBER: - krb5int_buf_add_fmt(buf, "%lld", k5_json_number_value(val)); + k5_buf_add_fmt(buf, "%lld", k5_json_number_value(val)); return 0; case K5_JSON_TID_NULL: - krb5int_buf_add(buf, "null"); + k5_buf_add(buf, "null"); return 0; case K5_JSON_TID_BOOL: - krb5int_buf_add(buf, k5_json_bool_value(val) ? "true" : "false"); + k5_buf_add(buf, k5_json_bool_value(val) ? "true" : "false"); return 0; default: @@ -678,13 +678,13 @@ k5_json_encode(k5_json_value val, char **json_out) int ret; *json_out = NULL; - krb5int_buf_init_dynamic(&buf); + k5_buf_init_dynamic(&buf); ret = encode_value(&buf, val); if (ret) { - krb5int_free_buf(&buf); + k5_free_buf(&buf); return ret; } - *json_out = krb5int_buf_data(&buf); + *json_out = k5_buf_data(&buf); return (*json_out == NULL) ? ENOMEM : 0; } diff --git a/src/util/support/k5buf-int.h b/src/util/support/k5buf-int.h index cc3c04c6e1..6f2ec19e7c 100644 --- a/src/util/support/k5buf-int.h +++ b/src/util/support/k5buf-int.h @@ -1,5 +1,5 @@ /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* util/support/k5buf-int.h */ +/* util/support/k5buf-int.h - Internal declarations for string buffers */ /* * Copyright 2008 Massachusetts Institute of Technology. * All Rights Reserved. @@ -24,17 +24,16 @@ * or implied warranty. */ -/* Internal declarations for the k5buf string buffer module */ - #ifndef K5BUF_INT_H #define K5BUF_INT_H #include "k5-platform.h" #include "k5-buf.h" -/* The k5buf structure has funny field names to discourage callers - from violating the abstraction barrier. Define less funny names - for them here. */ +/* + * The k5buf structure has funny field names to discourage callers from + * violating the abstraction barrier. Define less funny names for them here. + */ #define buftype xx_buftype #define data xx_data #define space xx_space diff --git a/src/util/support/k5buf.c b/src/util/support/k5buf.c index 5040dedd13..7d491ce2bd 100644 --- a/src/util/support/k5buf.c +++ b/src/util/support/k5buf.c @@ -1,5 +1,6 @@ /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/* util/support/k5buf.c */ +/* util/support/k5buf.c - string buffer functions */ + /* * Copyright 2008 Massachusetts Institute of Technology. * All Rights Reserved. @@ -24,11 +25,11 @@ * or implied warranty. */ -/* Implement the k5buf string buffer module. */ - -/* Can't include krb5.h here, or k5-int.h which includes it, because - krb5.h needs to be generated with error tables, after util/et, - which builds after this directory. */ +/* + * Can't include krb5.h here, or k5-int.h which includes it, because krb5.h + * needs to be generated with error tables, after util/et, which builds after + * this directory. + */ #include "k5buf-int.h" #include <assert.h> @@ -43,10 +44,13 @@ * data[len] = '\0' */ -/* Make sure there is room for LEN more characters in BUF, in addition - to the null terminator and what's already in there. Return true on - success. On failure, set the error flag and return false. */ -static int ensure_space(struct k5buf *buf, size_t len) +/* + * Make sure there is room for LEN more characters in BUF, in addition to the + * null terminator and what's already in there. Return true on success. On + * failure, set the error flag and return false. + */ +static int +ensure_space(struct k5buf *buf, size_t len) { size_t new_space; char *new_data; @@ -79,7 +83,8 @@ error_exit: return 0; } -void krb5int_buf_init_fixed(struct k5buf *buf, char *data, size_t space) +void +k5_buf_init_fixed(struct k5buf *buf, char *data, size_t space) { assert(space > 0); buf->buftype = BUFTYPE_FIXED; @@ -89,7 +94,8 @@ void krb5int_buf_init_fixed(struct k5buf *buf, char *data, size_t space) buf->data[0] = '\0'; } -void krb5int_buf_init_dynamic(struct k5buf *buf) +void +k5_buf_init_dynamic(struct k5buf *buf) { buf->buftype = BUFTYPE_DYNAMIC; buf->space = DYNAMIC_INITIAL_SIZE; @@ -102,12 +108,14 @@ void krb5int_buf_init_dynamic(struct k5buf *buf) buf->data[0] = '\0'; } -void krb5int_buf_add(struct k5buf *buf, const char *data) +void +k5_buf_add(struct k5buf *buf, const char *data) { - krb5int_buf_add_len(buf, data, strlen(data)); + k5_buf_add_len(buf, data, strlen(data)); } -void krb5int_buf_add_len(struct k5buf *buf, const char *data, size_t len) +void +k5_buf_add_len(struct k5buf *buf, const char *data, size_t len) { if (!ensure_space(buf, len)) return; @@ -116,7 +124,8 @@ void krb5int_buf_add_len(struct k5buf *buf, const char *data, size_t len) buf->data[buf->len] = '\0'; } -void krb5int_buf_add_fmt(struct k5buf *buf, const char *fmt, ...) +void +k5_buf_add_fmt(struct k5buf *buf, const char *fmt, ...) { va_list ap; int r; @@ -164,8 +173,8 @@ void krb5int_buf_add_fmt(struct k5buf *buf, const char *fmt, ...) return; } - /* It's a pre-C99 snprintf implementation, or something else went - wrong. Fall back to asprintf. */ + /* It's a pre-C99 snprintf implementation, or something else went wrong. + * Fall back to asprintf. */ va_start(ap, fmt); r = vasprintf(&tmp, fmt, ap); va_end(ap); @@ -181,7 +190,8 @@ void krb5int_buf_add_fmt(struct k5buf *buf, const char *fmt, ...) free(tmp); } -void krb5int_buf_truncate(struct k5buf *buf, size_t len) +void +k5_buf_truncate(struct k5buf *buf, size_t len) { if (buf->buftype == BUFTYPE_ERROR) return; @@ -191,17 +201,20 @@ void krb5int_buf_truncate(struct k5buf *buf, size_t len) } -char *krb5int_buf_data(struct k5buf *buf) +char * +k5_buf_data(struct k5buf *buf) { return (buf->buftype == BUFTYPE_ERROR) ? NULL : buf->data; } -ssize_t krb5int_buf_len(struct k5buf *buf) +ssize_t +k5_buf_len(struct k5buf *buf) { return (buf->buftype == BUFTYPE_ERROR) ? -1 : (ssize_t) buf->len; } -void krb5int_free_buf(struct k5buf *buf) +void +k5_free_buf(struct k5buf *buf) { if (buf->buftype == BUFTYPE_ERROR) return; diff --git a/src/util/support/libkrb5support-fixed.exports b/src/util/support/libkrb5support-fixed.exports index 41c8c6b7b6..d6f881d909 100644 --- a/src/util/support/libkrb5support-fixed.exports +++ b/src/util/support/libkrb5support-fixed.exports @@ -1,3 +1,12 @@ +k5_buf_init_fixed +k5_buf_init_dynamic +k5_buf_add +k5_buf_add_len +k5_buf_add_fmt +k5_buf_truncate +k5_buf_data +k5_buf_len +k5_free_buf k5_set_error k5_vset_error k5_set_error_fl @@ -61,15 +70,6 @@ krb5int_mutex_free krb5int_mutex_lock krb5int_mutex_unlock krb5int_gmt_mktime -krb5int_buf_init_fixed -krb5int_buf_init_dynamic -krb5int_buf_add -krb5int_buf_add_len -krb5int_buf_add_fmt -krb5int_buf_truncate -krb5int_buf_data -krb5int_buf_len -krb5int_free_buf krb5int_utf8cs_to_ucs2les krb5int_utf8s_to_ucs2les krb5int_ucs2lecs_to_utf8s diff --git a/src/util/support/t_k5buf.c b/src/util/support/t_k5buf.c index a6195fcecb..5e660d40fe 100644 --- a/src/util/support/t_k5buf.c +++ b/src/util/support/t_k5buf.c @@ -28,7 +28,8 @@ #include <stdio.h> #include <stdlib.h> -static void fail_if(int condition, const char *name) +static void +fail_if(int condition, const char *name) { if (condition) { fprintf(stderr, "%s failed\n", name); @@ -37,7 +38,8 @@ static void fail_if(int condition, const char *name) } /* Test the invariants of a buffer. */ -static void check_buf(struct k5buf *buf, const char *name) +static void +check_buf(struct k5buf *buf, const char *name) { fail_if(buf->buftype != BUFTYPE_FIXED && buf->buftype != BUFTYPE_DYNAMIC && buf->buftype != BUFTYPE_ERROR, name); @@ -49,31 +51,33 @@ static void check_buf(struct k5buf *buf, const char *name) fail_if(buf->data[buf->len] != 0, name); } -static void test_basic() +static void +test_basic() { struct k5buf buf; char storage[1024], *s; ssize_t len; - krb5int_buf_init_fixed(&buf, storage, sizeof(storage)); - krb5int_buf_add(&buf, "Hello "); - krb5int_buf_add_len(&buf, "world", 5); + k5_buf_init_fixed(&buf, storage, sizeof(storage)); + k5_buf_add(&buf, "Hello "); + k5_buf_add_len(&buf, "world", 5); check_buf(&buf, "basic fixed"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || strcmp(s, "Hello world") != 0 || len != 11, "basic fixed"); - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, "Hello", 5); - krb5int_buf_add(&buf, " world"); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, "Hello", 5); + k5_buf_add(&buf, " world"); check_buf(&buf, "basic dynamic"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || strcmp(s, "Hello world") != 0 || len != 11, "basic dynamic"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); } -static void test_realloc() +static void +test_realloc() { struct k5buf buf; char data[1024], *s; @@ -84,151 +88,156 @@ static void test_realloc() data[i] = 'a'; /* Cause the buffer size to double from 128 to 256 bytes. */ - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, data, 10); - krb5int_buf_add_len(&buf, data, 128); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, data, 10); + k5_buf_add_len(&buf, data, 128); fail_if(buf.space != 256, "realloc 1"); check_buf(&buf, "realloc 1"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 138 || memcmp(s, data, len) != 0, "realloc 1"); /* Cause the same buffer to double in size to 512 bytes. */ - krb5int_buf_add_len(&buf, data, 128); + k5_buf_add_len(&buf, data, 128); fail_if(buf.space != 512, "realloc 2"); check_buf(&buf, "realloc 2"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 266 || memcmp(s, data, len) != 0, "realloc 2"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); /* Cause a buffer to increase from 128 to 512 bytes directly. */ - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, data, 10); - krb5int_buf_add_len(&buf, data, 256); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, data, 10); + k5_buf_add_len(&buf, data, 256); fail_if(buf.space != 512, "realloc 3"); check_buf(&buf, "realloc 3"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 266 || memcmp(s, data, len) != 0, "realloc 3"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); /* Cause a buffer to increase from 128 to 1024 bytes directly. */ - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, data, 10); - krb5int_buf_add_len(&buf, data, 512); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, data, 10); + k5_buf_add_len(&buf, data, 512); fail_if(buf.space != 1024, "realloc 4"); check_buf(&buf, "realloc 4"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 522 || memcmp(s, data, len) != 0, "realloc 4"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); /* Cause a reallocation to fail by exceeding SPACE_MAX. */ - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, data, 10); - krb5int_buf_add_len(&buf, NULL, SPACE_MAX); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, data, 10); + k5_buf_add_len(&buf, NULL, SPACE_MAX); check_buf(&buf, "realloc 5"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1, "realloc 5"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); /* Cause a reallocation to fail by integer overflow. */ - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, data, 100); - krb5int_buf_add_len(&buf, NULL, SPACE_MAX * 2); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, data, 100); + k5_buf_add_len(&buf, NULL, SPACE_MAX * 2); check_buf(&buf, "realloc 6"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1, "realloc 6"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); } -static void test_overflow() +static void +test_overflow() { struct k5buf buf; char storage[10], *s; ssize_t len; /* Cause a fixed-sized buffer overflow. */ - krb5int_buf_init_fixed(&buf, storage, sizeof(storage)); - krb5int_buf_add(&buf, "12345"); - krb5int_buf_add(&buf, "12345"); + k5_buf_init_fixed(&buf, storage, sizeof(storage)); + k5_buf_add(&buf, "12345"); + k5_buf_add(&buf, "12345"); check_buf(&buf, "overflow 1"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1, "overflow 1"); /* Cause a fixed-sized buffer overflow with integer overflow. */ - krb5int_buf_init_fixed(&buf, storage, sizeof(storage)); - krb5int_buf_add(&buf, "12345"); - krb5int_buf_add_len(&buf, NULL, SPACE_MAX * 2); + k5_buf_init_fixed(&buf, storage, sizeof(storage)); + k5_buf_add(&buf, "12345"); + k5_buf_add_len(&buf, NULL, SPACE_MAX * 2); check_buf(&buf, "overflow 2"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1, "overflow 2"); } -static void test_error() +static void +test_error() { struct k5buf buf; char storage[1]; /* Cause an overflow and then perform actions afterwards. */ - krb5int_buf_init_fixed(&buf, storage, sizeof(storage)); - krb5int_buf_add(&buf, "1"); + k5_buf_init_fixed(&buf, storage, sizeof(storage)); + k5_buf_add(&buf, "1"); fail_if(buf.buftype != BUFTYPE_ERROR, "error"); check_buf(&buf, "error"); - krb5int_buf_add(&buf, "test"); + k5_buf_add(&buf, "test"); check_buf(&buf, "error"); - krb5int_buf_add_len(&buf, "test", 4); + k5_buf_add_len(&buf, "test", 4); check_buf(&buf, "error"); - krb5int_buf_truncate(&buf, 3); + k5_buf_truncate(&buf, 3); check_buf(&buf, "error"); fail_if(buf.buftype != BUFTYPE_ERROR, "error"); } -static void test_truncate() +static void +test_truncate() { struct k5buf buf; char *s; ssize_t len; - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add(&buf, "abcde"); - krb5int_buf_add(&buf, "fghij"); - krb5int_buf_truncate(&buf, 7); + k5_buf_init_dynamic(&buf); + k5_buf_add(&buf, "abcde"); + k5_buf_add(&buf, "fghij"); + k5_buf_truncate(&buf, 7); check_buf(&buf, "truncate"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 7 || strcmp(s, "abcdefg") != 0, "truncate"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); } -static void test_binary() +static void +test_binary() { struct k5buf buf; char *s, data[] = { 'a', 0, 'b' }; ssize_t len; - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add_len(&buf, data, 3); - krb5int_buf_add_len(&buf, data, 3); + k5_buf_init_dynamic(&buf); + k5_buf_add_len(&buf, data, 3); + k5_buf_add_len(&buf, data, 3); check_buf(&buf, "binary"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 6, "binary"); fail_if(s[0] != 'a' || s[1] != 0 || s[2] != 'b', "binary"); fail_if(s[3] != 'a' || s[4] != 0 || s[5] != 'b', "binary"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); } -static void test_fmt() +static void +test_fmt() { struct k5buf buf; char *s, storage[10], data[1024]; @@ -240,41 +249,42 @@ static void test_fmt() data[i] = '\0'; /* Format some text into a non-empty fixed buffer. */ - krb5int_buf_init_fixed(&buf, storage, sizeof(storage)); - krb5int_buf_add(&buf, "foo"); - krb5int_buf_add_fmt(&buf, " %d ", 3); + k5_buf_init_fixed(&buf, storage, sizeof(storage)); + k5_buf_add(&buf, "foo"); + k5_buf_add_fmt(&buf, " %d ", 3); check_buf(&buf, "fmt 1"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_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); + k5_buf_add_fmt(&buf, "%d%d%d%d", 1, 2, 3, 4); check_buf(&buf, "fmt 2"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1, "fmt 2"); /* Format some text into a non-empty dynamic buffer. */ - krb5int_buf_init_dynamic(&buf); - krb5int_buf_add(&buf, "foo"); - krb5int_buf_add_fmt(&buf, " %d ", 3); + k5_buf_init_dynamic(&buf); + k5_buf_add(&buf, "foo"); + k5_buf_add_fmt(&buf, " %d ", 3); check_buf(&buf, "fmt 3"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 6 || strcmp(s, "foo 3 ") != 0, "fmt 3"); /* Format more text into the same buffer, causing a big resize. */ - krb5int_buf_add_fmt(&buf, "%s", data); + k5_buf_add_fmt(&buf, "%s", data); check_buf(&buf, "fmt 4"); fail_if(buf.space != 2048, "fmt 4"); - s = krb5int_buf_data(&buf); - len = krb5int_buf_len(&buf); + s = k5_buf_data(&buf); + len = k5_buf_len(&buf); fail_if(!s || len != 1029 || strcmp(s + 6, data) != 0, "fmt 4"); - krb5int_free_buf(&buf); + k5_free_buf(&buf); } -int main() +int +main() { test_basic(); test_realloc(); |