2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2005-01-27 01:50:01 +00:00
|
|
|
/* dbus-marshal-validate-util.c Would be in dbus-marshal-validate.c, but only used by tests/bus
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2005 Red Hat, Inc.
|
|
|
|
|
*
|
2023-01-02 15:31:43 +01:00
|
|
|
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
|
|
|
|
|
*
|
2005-01-27 01:50:01 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
|
|
|
|
*
|
|
|
|
|
* 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 2 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, write to the Free Software
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-01-27 01:50:01 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2018-09-28 16:36:49 +01:00
|
|
|
|
|
|
|
|
#include "misc-internals.h"
|
|
|
|
|
|
2013-06-28 16:25:54 +08:00
|
|
|
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
2006-10-20 03:05:00 +00:00
|
|
|
|
|
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
|
|
|
|
|
2018-09-28 16:36:49 +01:00
|
|
|
#include "dbus/dbus-internals.h"
|
|
|
|
|
#include "dbus/dbus-marshal-validate.h"
|
|
|
|
|
#include "dbus/dbus-marshal-recursive.h"
|
2017-11-14 14:13:45 +00:00
|
|
|
#include <dbus/dbus-test-tap.h>
|
2005-01-27 01:50:01 +00:00
|
|
|
|
2018-09-28 16:36:49 +01:00
|
|
|
#include "dbus/dbus-test.h"
|
|
|
|
|
|
|
|
|
|
#include "dbus-marshal-recursive-util.h"
|
|
|
|
|
|
2005-01-27 01:50:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
const char *data;
|
|
|
|
|
DBusValidity expected;
|
|
|
|
|
} ValidityTest;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
run_validity_tests (const ValidityTest *tests,
|
|
|
|
|
int n_tests,
|
|
|
|
|
DBusValidity (* func) (const DBusString*,int,int))
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_tests; i++)
|
|
|
|
|
{
|
|
|
|
|
DBusString str;
|
|
|
|
|
DBusValidity v;
|
|
|
|
|
|
|
|
|
|
_dbus_string_init_const (&str, tests[i].data);
|
|
|
|
|
|
|
|
|
|
v = (*func) (&str, 0, _dbus_string_get_length (&str));
|
|
|
|
|
|
|
|
|
|
if (v != tests[i].expected)
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Improper validation result %d for '%s'", v, tests[i].data);
|
2005-01-27 01:50:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const ValidityTest signature_tests[] = {
|
|
|
|
|
{ "", DBUS_VALID },
|
2017-07-04 17:00:59 +01:00
|
|
|
{ "sss", DBUS_VALID },
|
2005-01-27 01:50:01 +00:00
|
|
|
{ "i", DBUS_VALID },
|
2017-07-04 17:00:59 +01:00
|
|
|
{ "b", DBUS_VALID },
|
2005-01-27 01:50:01 +00:00
|
|
|
{ "ai", DBUS_VALID },
|
|
|
|
|
{ "(i)", DBUS_VALID },
|
2005-01-28 03:06:56 +00:00
|
|
|
{ "w", DBUS_INVALID_UNKNOWN_TYPECODE },
|
2005-01-27 01:50:01 +00:00
|
|
|
{ "a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
|
|
|
|
{ "aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
|
|
|
|
{ "ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
|
|
|
|
{ "ia", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
|
|
|
|
/* DBUS_INVALID_SIGNATURE_TOO_LONG, */ /* too hard to test this way */
|
|
|
|
|
{ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
|
|
|
|
DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION },
|
|
|
|
|
{ "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((ii))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))",
|
|
|
|
|
DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION },
|
|
|
|
|
{ ")", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
|
|
|
|
|
{ "i)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
|
2016-01-28 12:24:56 -08:00
|
|
|
{ "a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
2005-01-27 01:50:01 +00:00
|
|
|
{ "(", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
|
|
|
|
|
{ "(i", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
|
|
|
|
|
{ "(iiiii", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
|
|
|
|
|
{ "(ai", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
|
|
|
|
|
{ "()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
|
|
|
|
|
{ "(())", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
|
|
|
|
|
{ "a()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
|
|
|
|
|
{ "i()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
|
2005-02-05 21:03:28 +00:00
|
|
|
{ "()i", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
|
|
|
|
|
{ "(a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
|
|
|
|
{ "a{ia}", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
|
2005-02-11 01:13:45 +00:00
|
|
|
{ "a{}", DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS },
|
|
|
|
|
{ "a{aii}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
|
2017-07-04 17:00:59 +01:00
|
|
|
{ " ", DBUS_INVALID_UNKNOWN_TYPECODE },
|
|
|
|
|
{ "not a valid signature", DBUS_INVALID_UNKNOWN_TYPECODE },
|
|
|
|
|
{ "123", DBUS_INVALID_UNKNOWN_TYPECODE },
|
|
|
|
|
{ ".", DBUS_INVALID_UNKNOWN_TYPECODE },
|
|
|
|
|
/* https://bugs.freedesktop.org/show_bug.cgi?id=17803 */
|
|
|
|
|
{ "a{(ii)i}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
|
2017-07-04 17:04:16 +01:00
|
|
|
{ "a{i}", DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD },
|
|
|
|
|
{ "{is}", DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY },
|
|
|
|
|
{ "a{isi}", DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS },
|
2005-01-27 01:50:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
2018-09-03 12:18:39 -07:00
|
|
|
_dbus_marshal_validate_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
|
2005-01-27 01:50:01 +00:00
|
|
|
{
|
|
|
|
|
DBusString str;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
const char *valid_paths[] = {
|
|
|
|
|
"/",
|
|
|
|
|
"/foo/bar",
|
|
|
|
|
"/foo",
|
|
|
|
|
"/foo/bar/baz"
|
|
|
|
|
};
|
|
|
|
|
const char *invalid_paths[] = {
|
|
|
|
|
"bar",
|
|
|
|
|
"bar/baz",
|
|
|
|
|
"/foo/bar/",
|
2015-01-06 22:14:08 +00:00
|
|
|
"/foo/",
|
2005-01-27 01:50:01 +00:00
|
|
|
"foo/",
|
|
|
|
|
"boo//blah",
|
|
|
|
|
"//",
|
|
|
|
|
"///",
|
|
|
|
|
"foo///blah/",
|
|
|
|
|
"Hello World",
|
|
|
|
|
"",
|
|
|
|
|
" ",
|
|
|
|
|
"foo bar"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *valid_interfaces[] = {
|
|
|
|
|
"org.freedesktop.Foo",
|
|
|
|
|
"Bar.Baz",
|
|
|
|
|
"Blah.Blah.Blah.Blah.Blah",
|
|
|
|
|
"a.b",
|
|
|
|
|
"a.b.c.d.e.f.g",
|
|
|
|
|
"a0.b1.c2.d3.e4.f5.g6",
|
|
|
|
|
"abc123.foo27"
|
|
|
|
|
};
|
|
|
|
|
const char *invalid_interfaces[] = {
|
|
|
|
|
".",
|
|
|
|
|
"",
|
|
|
|
|
"..",
|
|
|
|
|
".Foo.Bar",
|
|
|
|
|
"..Foo.Bar",
|
|
|
|
|
"Foo.Bar.",
|
|
|
|
|
"Foo.Bar..",
|
|
|
|
|
"Foo",
|
|
|
|
|
"9foo.bar.baz",
|
|
|
|
|
"foo.bar..baz",
|
|
|
|
|
"foo.bar...baz",
|
|
|
|
|
"foo.bar.b..blah",
|
|
|
|
|
":",
|
|
|
|
|
":0-1",
|
|
|
|
|
"10",
|
|
|
|
|
":11.34324",
|
|
|
|
|
"0.0.0",
|
|
|
|
|
"0..0",
|
|
|
|
|
"foo.Bar.%",
|
|
|
|
|
"foo.Bar!!",
|
|
|
|
|
"!Foo.bar.bz",
|
|
|
|
|
"foo.$.blah",
|
|
|
|
|
"",
|
|
|
|
|
" ",
|
|
|
|
|
"foo bar"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *valid_unique_names[] = {
|
|
|
|
|
":0",
|
|
|
|
|
":a",
|
|
|
|
|
":",
|
|
|
|
|
":.a",
|
|
|
|
|
":.1",
|
|
|
|
|
":0.1",
|
|
|
|
|
":000.2222",
|
|
|
|
|
":.blah",
|
|
|
|
|
":abce.freedesktop.blah"
|
|
|
|
|
};
|
|
|
|
|
const char *invalid_unique_names[] = {
|
2005-10-05 20:43:46 +00:00
|
|
|
//":-",
|
2005-01-27 01:50:01 +00:00
|
|
|
":!",
|
2005-10-05 20:43:46 +00:00
|
|
|
//":0-10",
|
2005-01-27 01:50:01 +00:00
|
|
|
":blah.",
|
|
|
|
|
":blah.",
|
|
|
|
|
":blah..org",
|
|
|
|
|
":blah.org..",
|
|
|
|
|
":..blah.org",
|
|
|
|
|
"",
|
|
|
|
|
" ",
|
|
|
|
|
"foo bar"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *valid_members[] = {
|
|
|
|
|
"Hello",
|
|
|
|
|
"Bar",
|
|
|
|
|
"foobar",
|
|
|
|
|
"_foobar",
|
|
|
|
|
"foo89"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *invalid_members[] = {
|
|
|
|
|
"9Hello",
|
|
|
|
|
"10",
|
|
|
|
|
"1",
|
|
|
|
|
"foo-bar",
|
|
|
|
|
"blah.org",
|
|
|
|
|
".blah",
|
|
|
|
|
"blah.",
|
|
|
|
|
"Hello.",
|
|
|
|
|
"!foo",
|
|
|
|
|
"",
|
|
|
|
|
" ",
|
|
|
|
|
"foo bar"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Signature with reason */
|
|
|
|
|
|
|
|
|
|
run_validity_tests (signature_tests, _DBUS_N_ELEMENTS (signature_tests),
|
|
|
|
|
_dbus_validate_signature_with_reason);
|
|
|
|
|
|
|
|
|
|
/* Path validation */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (valid_paths))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, valid_paths[i]);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_validate_path (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Path \"%s\" should have been valid", valid_paths[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (invalid_paths))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, invalid_paths[i]);
|
|
|
|
|
|
|
|
|
|
if (_dbus_validate_path (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Path \"%s\" should have been invalid", invalid_paths[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interface validation */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, valid_interfaces[i]);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_validate_interface (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Interface \"%s\" should have been valid", valid_interfaces[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, invalid_interfaces[i]);
|
|
|
|
|
|
|
|
|
|
if (_dbus_validate_interface (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Interface \"%s\" should have been invalid", invalid_interfaces[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Bus name validation (check that valid interfaces are valid bus names,
|
|
|
|
|
* and invalid interfaces are invalid services except if they start with ':')
|
|
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, valid_interfaces[i]);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_validate_bus_name (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Bus name \"%s\" should have been valid", valid_interfaces[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
|
|
|
|
|
{
|
|
|
|
|
if (invalid_interfaces[i][0] != ':')
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, invalid_interfaces[i]);
|
|
|
|
|
|
|
|
|
|
if (_dbus_validate_bus_name (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Bus name \"%s\" should have been invalid", invalid_interfaces[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* unique name validation */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (valid_unique_names))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, valid_unique_names[i]);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_validate_bus_name (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Bus name \"%s\" should have been valid", valid_unique_names[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (invalid_unique_names))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, invalid_unique_names[i]);
|
|
|
|
|
|
|
|
|
|
if (_dbus_validate_bus_name (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Bus name \"%s\" should have been invalid", invalid_unique_names[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Error name validation (currently identical to interfaces)
|
|
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (valid_interfaces))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, valid_interfaces[i]);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_validate_error_name (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Error name \"%s\" should have been valid", valid_interfaces[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (invalid_interfaces))
|
|
|
|
|
{
|
|
|
|
|
if (invalid_interfaces[i][0] != ':')
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, invalid_interfaces[i]);
|
|
|
|
|
|
|
|
|
|
if (_dbus_validate_error_name (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Error name \"%s\" should have been invalid", invalid_interfaces[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Member validation */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (valid_members))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, valid_members[i]);
|
|
|
|
|
|
|
|
|
|
if (!_dbus_validate_member (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Member \"%s\" should have been valid", valid_members[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < (int) _DBUS_N_ELEMENTS (invalid_members))
|
|
|
|
|
{
|
|
|
|
|
_dbus_string_init_const (&str, invalid_members[i]);
|
|
|
|
|
|
|
|
|
|
if (_dbus_validate_member (&str, 0,
|
|
|
|
|
_dbus_string_get_length (&str)))
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Member \"%s\" should have been invalid", invalid_members[i]);
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Validate claimed length longer than real length */
|
|
|
|
|
_dbus_string_init_const (&str, "abc.efg");
|
|
|
|
|
if (_dbus_validate_bus_name (&str, 0, 8))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated too-long string");
|
2005-01-27 01:50:01 +00:00
|
|
|
if (_dbus_validate_interface (&str, 0, 8))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated too-long string");
|
2005-01-27 01:50:01 +00:00
|
|
|
if (_dbus_validate_error_name (&str, 0, 8))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated too-long string");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
_dbus_string_init_const (&str, "abc");
|
|
|
|
|
if (_dbus_validate_member (&str, 0, 4))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated too-long string");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
/* Validate string exceeding max name length */
|
|
|
|
|
if (!_dbus_string_init (&str))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("no memory");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
|
|
|
|
|
if (!_dbus_string_append (&str, "abc.def"))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("no memory");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
if (_dbus_validate_bus_name (&str, 0, _dbus_string_get_length (&str)))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated overmax string");
|
2005-01-27 01:50:01 +00:00
|
|
|
if (_dbus_validate_interface (&str, 0, _dbus_string_get_length (&str)))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated overmax string");
|
2005-01-27 01:50:01 +00:00
|
|
|
if (_dbus_validate_error_name (&str, 0, _dbus_string_get_length (&str)))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated overmax string");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
/* overlong member */
|
|
|
|
|
_dbus_string_set_length (&str, 0);
|
|
|
|
|
while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
|
|
|
|
|
if (!_dbus_string_append (&str, "abc"))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("no memory");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
if (_dbus_validate_member (&str, 0, _dbus_string_get_length (&str)))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated overmax string");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
/* overlong unique name */
|
|
|
|
|
_dbus_string_set_length (&str, 0);
|
|
|
|
|
_dbus_string_append (&str, ":");
|
|
|
|
|
while (_dbus_string_get_length (&str) <= DBUS_MAXIMUM_NAME_LENGTH)
|
|
|
|
|
if (!_dbus_string_append (&str, "abc"))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("no memory");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
if (_dbus_validate_bus_name (&str, 0, _dbus_string_get_length (&str)))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("validated overmax string");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
_dbus_string_free (&str);
|
|
|
|
|
|
|
|
|
|
/* Body validation; test basic validation of valid bodies for both endian */
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 01:50:01 +00:00
|
|
|
{
|
|
|
|
|
int sequence;
|
|
|
|
|
DBusString signature;
|
|
|
|
|
DBusString body;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&signature) || !_dbus_string_init (&body))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("oom");
|
2005-01-27 01:50:01 +00:00
|
|
|
|
|
|
|
|
sequence = 0;
|
2018-07-23 17:29:56 +01:00
|
|
|
while (_dbus_test_generate_bodies (sequence, DBUS_LITTLE_ENDIAN,
|
|
|
|
|
&signature, &body))
|
2005-01-27 01:50:01 +00:00
|
|
|
{
|
|
|
|
|
DBusValidity validity;
|
|
|
|
|
|
|
|
|
|
validity = _dbus_validate_body_with_reason (&signature, 0,
|
|
|
|
|
DBUS_LITTLE_ENDIAN,
|
|
|
|
|
NULL, &body, 0,
|
|
|
|
|
_dbus_string_get_length (&body));
|
|
|
|
|
if (validity != DBUS_VALID)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("invalid code %d expected valid on sequence %d little endian",
|
2005-01-27 01:50:01 +00:00
|
|
|
validity, sequence);
|
|
|
|
|
_dbus_verbose_bytes_of_string (&signature, 0, _dbus_string_get_length (&signature));
|
|
|
|
|
_dbus_verbose_bytes_of_string (&body, 0, _dbus_string_get_length (&body));
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("test failed");
|
2005-01-27 01:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_set_length (&signature, 0);
|
|
|
|
|
_dbus_string_set_length (&body, 0);
|
|
|
|
|
++sequence;
|
|
|
|
|
}
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 01:50:01 +00:00
|
|
|
sequence = 0;
|
2018-07-23 17:29:56 +01:00
|
|
|
while (_dbus_test_generate_bodies (sequence, DBUS_BIG_ENDIAN,
|
|
|
|
|
&signature, &body))
|
2005-01-27 01:50:01 +00:00
|
|
|
{
|
|
|
|
|
DBusValidity validity;
|
|
|
|
|
|
|
|
|
|
validity = _dbus_validate_body_with_reason (&signature, 0,
|
|
|
|
|
DBUS_BIG_ENDIAN,
|
|
|
|
|
NULL, &body, 0,
|
|
|
|
|
_dbus_string_get_length (&body));
|
|
|
|
|
if (validity != DBUS_VALID)
|
|
|
|
|
{
|
2016-07-21 11:01:01 +01:00
|
|
|
_dbus_warn ("invalid code %d expected valid on sequence %d big endian",
|
2005-01-27 01:50:01 +00:00
|
|
|
validity, sequence);
|
|
|
|
|
_dbus_verbose_bytes_of_string (&signature, 0, _dbus_string_get_length (&signature));
|
|
|
|
|
_dbus_verbose_bytes_of_string (&body, 0, _dbus_string_get_length (&body));
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("test failed");
|
2005-01-27 01:50:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_set_length (&signature, 0);
|
|
|
|
|
_dbus_string_set_length (&body, 0);
|
|
|
|
|
++sequence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&signature);
|
|
|
|
|
_dbus_string_free (&body);
|
|
|
|
|
}
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 01:50:01 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-20 03:05:00 +00:00
|
|
|
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
|
|
|
|
|
|
2013-06-28 16:25:54 +08:00
|
|
|
#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
|