->max_alloc to krb5_storage and use it

This commit is contained in:
Love Hornquist Astrand
2011-05-08 00:16:02 -07:00
parent 35652e4a03
commit bd2d4c2f79
7 changed files with 87 additions and 10 deletions

View File

@@ -193,8 +193,6 @@ test_storage(krb5_context context, krb5_storage *sp)
test_uint8(context, sp);
test_uint16(context, sp);
test_uint32(context, sp);
krb5_storage_free(sp);
}
@@ -217,10 +215,25 @@ test_truncate(krb5_context context, krb5_storage *sp, int fd)
krb5_err(context, 1, errno, "fstat");
if (sb.st_size != 1024)
krb5_errx(context, 1, "length not 2");
krb5_storage_free(sp);
}
static void
check_too_large(krb5_context context, krb5_storage *sp)
{
uint32_t too_big_sizes[] = { INT_MAX, INT_MAX / 2, INT_MAX / 4, INT_MAX / 8 + 1};
krb5_error_code ret;
krb5_data data;
size_t n;
for (n = 0; n < sizeof(too_big_sizes) / sizeof(too_big_sizes); n++) {
krb5_storage_truncate(sp, 0);
krb5_store_uint32(sp, too_big_sizes[n]);
krb5_storage_seek(sp, 0, SEEK_SET);
ret = krb5_ret_data(sp, &data);
if (ret != HEIM_ERR_TOO_BIG)
errx(1, "not too big: %lu", (unsigned long)n);
}
}
/*
*
@@ -284,10 +297,13 @@ main(int argc, char **argv)
krb5_errx(context, 1, "krb5_storage_emem: no mem");
test_storage(context, sp);
check_too_large(context, sp);
krb5_storage_free(sp);
fd = open(fn, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (fd < 0)
krb5_err(context, 1, errno, "open(%s", fn);
krb5_err(context, 1, errno, "open(%s)", fn);
sp = krb5_storage_from_fd(fd);
close(fd);
@@ -295,6 +311,7 @@ main(int argc, char **argv)
krb5_errx(context, 1, "krb5_storage_from_fd: %s no mem", fn);
test_storage(context, sp);
krb5_storage_free(sp);
unlink(fn);
/*
@@ -303,13 +320,14 @@ main(int argc, char **argv)
fd = open(fn, O_RDWR|O_CREAT|O_TRUNC, 0600);
if (fd < 0)
krb5_err(context, 1, errno, "open(%s", fn);
krb5_err(context, 1, errno, "open(%s)", fn);
sp = krb5_storage_from_fd(fd);
if (sp == NULL)
krb5_errx(context, 1, "krb5_storage_from_fd: %s no mem", fn);
test_truncate(context, sp, fd);
krb5_storage_free(sp);
close(fd);
unlink(fn);