|
Packit Service |
991b93 |
/*
|
|
Packit Service |
991b93 |
* Copyright (C) 2019 Tim Rühsen
|
|
Packit Service |
991b93 |
*
|
|
Packit Service |
991b93 |
* This file is part of GnuTLS.
|
|
Packit Service |
991b93 |
*
|
|
Packit Service |
991b93 |
* GnuTLS is free software; you can redistribute it and/or modify it
|
|
Packit Service |
991b93 |
* under the terms of the GNU General Public License as published by
|
|
Packit Service |
991b93 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
991b93 |
* (at your option) any later version.
|
|
Packit Service |
991b93 |
*
|
|
Packit Service |
991b93 |
* GnuTLS is distributed in the hope that it will be useful, but
|
|
Packit Service |
991b93 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
991b93 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
991b93 |
* General Public License for more details.
|
|
Packit Service |
991b93 |
*
|
|
Packit Service |
991b93 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
991b93 |
* along with GnuTLS; if not, write to the Free Software Foundation,
|
|
Packit Service |
991b93 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
Packit Service |
991b93 |
*/
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
991b93 |
#include <config.h>
|
|
Packit Service |
991b93 |
#endif
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
#include <stdio.h>
|
|
Packit Service |
991b93 |
#include <stdlib.h>
|
|
Packit Service |
991b93 |
#include <string.h>
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
#include <gnutls_int.h>
|
|
Packit Service |
991b93 |
#include "utils.h"
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
void doit(void)
|
|
Packit Service |
991b93 |
{
|
|
Packit Service |
991b93 |
static const struct test_data {
|
|
Packit Service |
991b93 |
const char *
|
|
Packit Service |
991b93 |
input;
|
|
Packit Service |
991b93 |
const char *
|
|
Packit Service |
991b93 |
output;
|
|
Packit Service |
991b93 |
} test_data[] = {
|
|
Packit Service |
991b93 |
{ "%20%20", " ", },
|
|
Packit Service |
991b93 |
{ "%20", " ", },
|
|
Packit Service |
991b93 |
{ "%2z", "%2z", },
|
|
Packit Service |
991b93 |
{ "%2", "%2", },
|
|
Packit Service |
991b93 |
{ "%", "%", },
|
|
Packit Service |
991b93 |
{ "", "", },
|
|
Packit Service |
991b93 |
};
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
for (unsigned it = 0; it < countof(test_data); it++) {
|
|
Packit Service |
991b93 |
const struct test_data *t = &test_data[it];
|
|
Packit Service |
991b93 |
gnutls_buffer_st str;
|
|
Packit Service |
991b93 |
int ret;
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
_gnutls_buffer_init(&str);
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
ret = _gnutls_buffer_append_data(&str, t->input, strlen(t->input));
|
|
Packit Service |
991b93 |
if (ret < 0)
|
|
Packit Service |
991b93 |
fail("_gnutls_buffer_append_str: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
ret = _gnutls_buffer_unescape(&str);
|
|
Packit Service |
991b93 |
if (ret < 0)
|
|
Packit Service |
991b93 |
fail("_gnutls_buffer_unescape: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
ret = _gnutls_buffer_append_data(&str, "", 1);
|
|
Packit Service |
991b93 |
if (ret < 0)
|
|
Packit Service |
991b93 |
fail("_gnutls_buffer_append_data: %s\n", gnutls_strerror(ret));
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
/* using malloc() instead of stack memory for better buffer overflow detection */
|
|
Packit Service |
991b93 |
gnutls_datum output;
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
_gnutls_buffer_pop_datum(&str, &output, strlen(t->output) + 1);
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
if (strcmp(t->output, (char *) output.data))
|
|
Packit Service |
991b93 |
fail("output differs [%d]: expected '%s', seen '%s'\n", it, t->output, (char *) output.data);
|
|
Packit Service |
991b93 |
|
|
Packit Service |
991b93 |
_gnutls_buffer_clear(&str);
|
|
Packit Service |
991b93 |
}
|
|
Packit Service |
991b93 |
}
|
|
Packit Service |
991b93 |
|