Skip to content

Commit

Permalink
ticket: 6200
Browse files Browse the repository at this point in the history
status: open

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.


git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@21003 dc483132-0cff-0310-8789-dd5450dbe970
  • Loading branch information
ghudson committed Nov 5, 2008
1 parent d91011c commit f8152e9
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/clients/ksu/authorization.c
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/include/k5-buf.h
Expand Up @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion src/lib/crypto/t_hmac.c
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gssapi/mechglue/oid_ops.c
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/kadm5/alt_prof.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/kadm5/str_conv.c
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/krb/preauth.c
Expand Up @@ -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);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/krb/srv_rcache.c
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/os/dnssrv.c
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/krb5/os/hst_realm.c
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/krb5/os/sendto_kdc.c
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kdb/ldap/libkdb_ldap/ldap_principal.c
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/support/k5buf.c
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/support/libkrb5support-fixed.exports
Expand Up @@ -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
32 changes: 16 additions & 16 deletions src/util/support/t_k5buf.c
Expand Up @@ -63,15 +63,15 @@ 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");

krb5int_buf_init_dynamic(&buf);
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);
Expand All @@ -93,15 +93,15 @@ 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");

/* Cause the same buffer to double in size to 512 bytes. */
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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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");

Expand All @@ -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");
}
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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");

Expand All @@ -260,15 +260,15 @@ 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");

/* Format more text into the same buffer, causing a big resize. */
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);
Expand Down

0 comments on commit f8152e9

Please sign in to comment.