From 02f3d1f52b8c279f826ccda2d2cccb6ff7ec65cb Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Sat, 28 Mar 2015 13:27:47 +0100 Subject: [PATCH 2/2] Added a check for invalid encodings --- tests/Makefile.am | 2 +- tests/tst_invalid.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/tst_invalid.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 0f491ec..acb50b3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,7 +27,7 @@ libutils_a_SOURCES = utils.h utils.c ctests = tst_stringprep tst_punycode tst_idna tst_idna2 tst_idna3 \ tst_idna4 tst_nfkc tst_pr29 tst_strerror tst_toutf8 \ - tst_symbols + tst_symbols tst_invalid if TLD ctests += tst_tld endif diff --git a/tests/tst_invalid.c b/tests/tst_invalid.c new file mode 100644 index 0000000..32285a5 --- /dev/null +++ b/tests/tst_invalid.c @@ -0,0 +1,52 @@ +/* tst_idna.c --- Self tests for idna_to_ascii(). + * Copyright (C) 2015 Nikos Mavrogiannopoulos + * + * This file is part of GNU Libidn. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + + +#include +#include +#include + +int main() +{ + char *s = NULL, *s2 = NULL; + int rc; + char *x1 = strdup("\x7e\x64\x61\x72\x10\x2f\x2f\xf9\x2b\x71\x60\x79\x7b\x2e\x63\x75\x2b\x61\x65\x72\x75\x65\x56\x66\x7f\x62\xc5\x76\xe5\x00"); + char *x2 = strdup("\x76\x72\x6f\x63\x65\x72\x74\x2e\x79\x65\x5e\xdc\xf6\xd0\x00"); + + + rc = idna_to_ascii_8z(x1, &s, 0); + if (rc == IDNA_SUCCESS) { + /* should have failed */ + exit(1); + } + + rc = idna_to_ascii_8z(x2, &s2, 0); + if (rc == IDNA_SUCCESS) { + /* should have failed */ + exit(1); + } + free(x1); + free(x2); + exit(0); +} -- 2.1.4