|
Packit Service |
4684c1 |
/*
|
|
Packit Service |
4684c1 |
* Copyright (C) 2019 Red Hat, Inc.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* Author: Daiki Ueno
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* This file is part of GnuTLS.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
4684c1 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
4684c1 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
4684c1 |
* (at your option) any later version.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
4684c1 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
4684c1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
4684c1 |
* General Public License for more details.
|
|
Packit Service |
4684c1 |
*
|
|
Packit Service |
4684c1 |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit Service |
4684c1 |
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
Packit Service |
4684c1 |
*/
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
4684c1 |
#include <config.h>
|
|
Packit Service |
4684c1 |
#endif
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "gnutls_int.h"
|
|
Packit Service |
4684c1 |
#include "../lib/iov.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#include "utils.h"
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct exp_st {
|
|
Packit Service |
4684c1 |
ssize_t ret;
|
|
Packit Service |
4684c1 |
size_t iov_index;
|
|
Packit Service |
4684c1 |
size_t iov_offset;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
struct test_st {
|
|
Packit Service |
4684c1 |
const char *name;
|
|
Packit Service |
4684c1 |
const giovec_t *iov;
|
|
Packit Service |
4684c1 |
size_t iovcnt;
|
|
Packit Service |
4684c1 |
size_t block_size;
|
|
Packit Service |
4684c1 |
const struct exp_st *exp;
|
|
Packit Service |
4684c1 |
size_t expcnt;
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const giovec_t iov16[] = {
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012345", 16},
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012345", 16},
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012345", 16},
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012345", 16}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp16_64[] = {
|
|
Packit Service |
4684c1 |
{64, 4, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp16_32[] = {
|
|
Packit Service |
4684c1 |
{32, 2, 0},
|
|
Packit Service |
4684c1 |
{32, 4, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp16_16[] = {
|
|
Packit Service |
4684c1 |
{16, 1, 0},
|
|
Packit Service |
4684c1 |
{16, 2, 0},
|
|
Packit Service |
4684c1 |
{16, 3, 0},
|
|
Packit Service |
4684c1 |
{16, 4, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp16_4[] = {
|
|
Packit Service |
4684c1 |
{16, 1, 0},
|
|
Packit Service |
4684c1 |
{16, 2, 0},
|
|
Packit Service |
4684c1 |
{16, 3, 0},
|
|
Packit Service |
4684c1 |
{16, 4, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp16_3[] = {
|
|
Packit Service |
4684c1 |
{15, 0, 15},
|
|
Packit Service |
4684c1 |
{3, 1, 2},
|
|
Packit Service |
4684c1 |
{12, 1, 14},
|
|
Packit Service |
4684c1 |
{3, 2, 1},
|
|
Packit Service |
4684c1 |
{15, 3, 0},
|
|
Packit Service |
4684c1 |
{15, 3, 15},
|
|
Packit Service |
4684c1 |
{1, 4, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const giovec_t iov8[] = {
|
|
Packit Service |
4684c1 |
{(void *) "01234567", 8},
|
|
Packit Service |
4684c1 |
{(void *) "01234567", 8},
|
|
Packit Service |
4684c1 |
{(void *) "01234567", 8},
|
|
Packit Service |
4684c1 |
{(void *) "01234567", 8}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp8_64[] = {
|
|
Packit Service |
4684c1 |
{32, 4, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const giovec_t iov_odd[] = {
|
|
Packit Service |
4684c1 |
{(void *) "0", 1},
|
|
Packit Service |
4684c1 |
{(void *) "012", 3},
|
|
Packit Service |
4684c1 |
{(void *) "01234", 5},
|
|
Packit Service |
4684c1 |
{(void *) "0123456", 7},
|
|
Packit Service |
4684c1 |
{(void *) "012345678", 9},
|
|
Packit Service |
4684c1 |
{(void *) "01234567890", 11},
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012", 13},
|
|
Packit Service |
4684c1 |
{(void *) "012345678901234", 15}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp_odd_16[] = {
|
|
Packit Service |
4684c1 |
{16, 4, 0},
|
|
Packit Service |
4684c1 |
{16, 5, 7},
|
|
Packit Service |
4684c1 |
{16, 6, 12},
|
|
Packit Service |
4684c1 |
{16, 8, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const giovec_t iov_skip[] = {
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012345", 16},
|
|
Packit Service |
4684c1 |
{(void *) "01234567", 8},
|
|
Packit Service |
4684c1 |
{(void *) "", 0},
|
|
Packit Service |
4684c1 |
{(void *) "", 0},
|
|
Packit Service |
4684c1 |
{(void *) "0123456789012345", 16}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp_skip_16[] = {
|
|
Packit Service |
4684c1 |
{16, 1, 0},
|
|
Packit Service |
4684c1 |
{16, 4, 8},
|
|
Packit Service |
4684c1 |
{8, 5, 0},
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const giovec_t iov_empty[] = {
|
|
Packit Service |
4684c1 |
{(void *) "", 0},
|
|
Packit Service |
4684c1 |
{(void *) "", 0},
|
|
Packit Service |
4684c1 |
{(void *) "", 0},
|
|
Packit Service |
4684c1 |
{(void *) "", 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct exp_st exp_empty_16[] = {
|
|
Packit Service |
4684c1 |
{0, 0, 0}
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static const struct test_st tests[] = {
|
|
Packit Service |
4684c1 |
{ "16/64", iov16, sizeof(iov16)/sizeof(iov16[0]), 64,
|
|
Packit Service |
4684c1 |
exp16_64, sizeof(exp16_64)/sizeof(exp16_64[0]) },
|
|
Packit Service |
4684c1 |
{ "16/32", iov16, sizeof(iov16)/sizeof(iov16[0]), 32,
|
|
Packit Service |
4684c1 |
exp16_32, sizeof(exp16_32)/sizeof(exp16_32[0]) },
|
|
Packit Service |
4684c1 |
{ "16/16", iov16, sizeof(iov16)/sizeof(iov16[0]), 16,
|
|
Packit Service |
4684c1 |
exp16_16, sizeof(exp16_16)/sizeof(exp16_16[0]) },
|
|
Packit Service |
4684c1 |
{ "16/4", iov16, sizeof(iov16)/sizeof(iov16[0]), 4,
|
|
Packit Service |
4684c1 |
exp16_4, sizeof(exp16_4)/sizeof(exp16_4[0]) },
|
|
Packit Service |
4684c1 |
{ "16/3", iov16, sizeof(iov16)/sizeof(iov16[0]), 3,
|
|
Packit Service |
4684c1 |
exp16_3, sizeof(exp16_3)/sizeof(exp16_3[0]) },
|
|
Packit Service |
4684c1 |
{ "8/64", iov8, sizeof(iov8)/sizeof(iov8[0]), 64,
|
|
Packit Service |
4684c1 |
exp8_64, sizeof(exp8_64)/sizeof(exp8_64[0]) },
|
|
Packit Service |
4684c1 |
{ "odd/16", iov_odd, sizeof(iov_odd)/sizeof(iov_odd[0]), 16,
|
|
Packit Service |
4684c1 |
exp_odd_16, sizeof(exp_odd_16)/sizeof(exp_odd_16[0]) },
|
|
Packit Service |
4684c1 |
{ "skip/16", iov_skip, sizeof(iov_skip)/sizeof(iov_skip[0]), 16,
|
|
Packit Service |
4684c1 |
exp_skip_16, sizeof(exp_skip_16)/sizeof(exp_skip_16[0]) },
|
|
Packit Service |
4684c1 |
{ "empty/16", iov_empty, sizeof(iov_empty)/sizeof(iov_empty[0]), 16,
|
|
Packit Service |
4684c1 |
exp_empty_16, sizeof(exp_empty_16)/sizeof(exp_empty_16[0]) },
|
|
Packit Service |
4684c1 |
};
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void
|
|
Packit Service |
4684c1 |
copy(giovec_t *dst, uint8_t *buffer, const giovec_t *src, size_t iovcnt)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
uint8_t *p = buffer;
|
|
Packit Service |
4684c1 |
size_t i;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (i = 0; i < iovcnt; i++) {
|
|
Packit Service |
4684c1 |
dst[i].iov_base = p;
|
|
Packit Service |
4684c1 |
dst[i].iov_len = src[i].iov_len;
|
|
Packit Service |
4684c1 |
memcpy(dst[i].iov_base, src[i].iov_base, src[i].iov_len);
|
|
Packit Service |
4684c1 |
p += src[i].iov_len;
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
static void
|
|
Packit Service |
4684c1 |
translate(uint8_t *data, size_t len)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
for (; len > 0; len--) {
|
|
Packit Service |
4684c1 |
uint8_t *p = &data[len - 1];
|
|
Packit Service |
4684c1 |
if (*p >= '0' && *p <= '9')
|
|
Packit Service |
4684c1 |
*p = 'A' + *p - '0';
|
|
Packit Service |
4684c1 |
else if (*p >= 'A' && *p <= 'Z')
|
|
Packit Service |
4684c1 |
*p = '0' + *p - 'A';
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
#define MAX_BUF 1024
|
|
Packit Service |
4684c1 |
#define MAX_IOV 16
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
void
|
|
Packit Service |
4684c1 |
doit (void)
|
|
Packit Service |
4684c1 |
{
|
|
Packit Service |
4684c1 |
uint8_t buffer[MAX_BUF];
|
|
Packit Service |
4684c1 |
size_t i;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
|
|
Packit Service |
4684c1 |
giovec_t iov[MAX_IOV];
|
|
Packit Service |
4684c1 |
struct iov_iter_st iter;
|
|
Packit Service |
4684c1 |
const struct exp_st *exp = tests[i].exp;
|
|
Packit Service |
4684c1 |
uint8_t *data;
|
|
Packit Service |
4684c1 |
size_t j;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
copy(iov, buffer, tests[i].iov, tests[i].iovcnt);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
success("%s\n", tests[i].name);
|
|
Packit Service |
4684c1 |
assert(_gnutls_iov_iter_init(&iter,
|
|
Packit Service |
4684c1 |
iov, tests[i].iovcnt,
|
|
Packit Service |
4684c1 |
tests[i].block_size) == 0);
|
|
Packit Service |
4684c1 |
for (j = 0; j < tests[i].expcnt; j++) {
|
|
Packit Service |
4684c1 |
ssize_t ret;
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _gnutls_iov_iter_next(&iter, &data);
|
|
Packit Service |
4684c1 |
if (ret != exp[j].ret)
|
|
Packit Service |
4684c1 |
fail("iov_iter_next: %d != %d\n",
|
|
Packit Service |
4684c1 |
(int) ret, (int) exp[j].ret);
|
|
Packit Service |
4684c1 |
else if (debug)
|
|
Packit Service |
4684c1 |
success("iov_iter_next: %d == %d\n",
|
|
Packit Service |
4684c1 |
(int) ret, (int) exp[j].ret);
|
|
Packit Service |
4684c1 |
if (ret == 0)
|
|
Packit Service |
4684c1 |
break;
|
|
Packit Service |
4684c1 |
if (ret > 0) {
|
|
Packit Service |
4684c1 |
if (iter.iov_index != exp[j].iov_index)
|
|
Packit Service |
4684c1 |
fail("iter.iov_index: %u != %u\n",
|
|
Packit Service |
4684c1 |
(unsigned) iter.iov_index, (unsigned) exp[j].iov_index);
|
|
Packit Service |
4684c1 |
else if (debug)
|
|
Packit Service |
4684c1 |
success("iter.iov_index: %u == %u\n",
|
|
Packit Service |
4684c1 |
(unsigned) iter.iov_index, (unsigned) exp[j].iov_index);
|
|
Packit Service |
4684c1 |
if (iter.iov_offset != exp[j].iov_offset)
|
|
Packit Service |
4684c1 |
fail("iter.iov_offset: %u != %u\n",
|
|
Packit Service |
4684c1 |
(unsigned) iter.iov_offset, (unsigned) exp[j].iov_offset);
|
|
Packit Service |
4684c1 |
else if (debug)
|
|
Packit Service |
4684c1 |
success("iter.iov_offset: %u == %u\n",
|
|
Packit Service |
4684c1 |
(unsigned) iter.iov_offset, (unsigned) exp[j].iov_offset);
|
|
Packit Service |
4684c1 |
if (iter.block_offset != 0)
|
|
Packit Service |
4684c1 |
fail("iter.block_offset: %u != 0\n",
|
|
Packit Service |
4684c1 |
(unsigned) iter.block_offset);
|
|
Packit Service |
4684c1 |
else if (debug)
|
|
Packit Service |
4684c1 |
success("iter.block_offset: %u == 0\n",
|
|
Packit Service |
4684c1 |
(unsigned) iter.block_offset);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
translate(data, ret);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
ret = _gnutls_iov_iter_sync(&iter, data, ret);
|
|
Packit Service |
4684c1 |
if (ret < 0)
|
|
Packit Service |
4684c1 |
fail("sync failed\n");
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
for (j = 0; j < tests[i].iovcnt; j++) {
|
|
Packit Service |
4684c1 |
translate(iov[j].iov_base, iov[j].iov_len);
|
|
Packit Service |
4684c1 |
|
|
Packit Service |
4684c1 |
if (memcmp(iov[j].iov_base, tests[i].iov[j].iov_base,
|
|
Packit Service |
4684c1 |
iov[j].iov_len) != 0)
|
|
Packit Service |
4684c1 |
fail("iov doesn't match: %*s != %*s\n",
|
|
Packit Service |
4684c1 |
(int)iov[j].iov_len,
|
|
Packit Service |
4684c1 |
(char *)iov[j].iov_base,
|
|
Packit Service |
4684c1 |
(int)tests[i].iov[j].iov_len,
|
|
Packit Service |
4684c1 |
(char *)tests[i].iov[j].iov_len);
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|
|
Packit Service |
4684c1 |
}
|