mirror of
https://github.com/strophe/libstrophe.git
synced 2026-08-05 19:36:20 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9931ad4fa2 | ||
|
|
5a1f282292 | ||
|
|
b360316b8b | ||
|
|
c6aaa96dcb | ||
|
|
f0706f56c4 | ||
|
|
4ef2740c36 |
@@ -1,3 +1,7 @@
|
|||||||
|
0.9.1
|
||||||
|
- Fixed bug #95 (DNS lookup failing on Cygwin)
|
||||||
|
- Removed dependency on the check package
|
||||||
|
|
||||||
0.9.0
|
0.9.0
|
||||||
- IPv6 support
|
- IPv6 support
|
||||||
- Legacy SSL support
|
- Legacy SSL support
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ TESTS = tests/check_parser tests/test_sha1 tests/test_md5 tests/test_rand \
|
|||||||
check_PROGRAMS = $(TESTS)
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
tests_check_parser_SOURCES = tests/check_parser.c tests/test.h
|
tests_check_parser_SOURCES = tests/check_parser.c tests/test.h
|
||||||
tests_check_parser_CFLAGS = @check_CFLAGS@ $(PARSER_CFLAGS) $(STROPHE_FLAGS) \
|
tests_check_parser_CFLAGS = $(PARSER_CFLAGS) $(STROPHE_FLAGS) \
|
||||||
-I$(top_srcdir)/src
|
-I$(top_srcdir)/src
|
||||||
tests_check_parser_LDADD = @check_LIBS@ $(STROPHE_LIBS)
|
tests_check_parser_LDADD = $(STROPHE_LIBS)
|
||||||
tests_check_parser_LDFLAGS = -static
|
tests_check_parser_LDFLAGS = -static
|
||||||
|
|
||||||
tests_test_ctx_SOURCES = tests/test_ctx.c
|
tests_test_ctx_SOURCES = tests/test_ctx.c
|
||||||
|
|||||||
@@ -58,9 +58,6 @@ libstrophe requires:
|
|||||||
To build libstrophe using autotools you will need autoconf, automake,
|
To build libstrophe using autotools you will need autoconf, automake,
|
||||||
libtool and pkg-config.
|
libtool and pkg-config.
|
||||||
|
|
||||||
In addition, if you wish to run the unit tests, you will need the
|
|
||||||
check package.
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT([libstrophe], [0.9.0], [jack@metajack.im])
|
AC_INIT([libstrophe], [0.9.1], [jack@metajack.im])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AM_INIT_AUTOMAKE([foreign])
|
AM_INIT_AUTOMAKE([foreign])
|
||||||
LT_INIT([dlopen])
|
LT_INIT([dlopen])
|
||||||
@@ -22,9 +22,6 @@ AC_ARG_WITH([libxml2],
|
|||||||
AC_ARG_ENABLE([tls],
|
AC_ARG_ENABLE([tls],
|
||||||
[AS_HELP_STRING([--disable-tls], [disable TLS support])])
|
[AS_HELP_STRING([--disable-tls], [disable TLS support])])
|
||||||
|
|
||||||
PKG_CHECK_MODULES([check], [check >= 0.9.4],
|
|
||||||
[], [AC_MSG_WARN([libcheck not found; unit tests will not be compilable])])
|
|
||||||
|
|
||||||
if test "x$enable_tls" != xno; then
|
if test "x$enable_tls" != xno; then
|
||||||
PKG_CHECK_MODULES([openssl], [openssl],
|
PKG_CHECK_MODULES([openssl], [openssl],
|
||||||
[PC_REQUIRES="openssl ${PC_REQUIRES}"],
|
[PC_REQUIRES="openssl ${PC_REQUIRES}"],
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "ostypes.h"
|
#include "ostypes.h"
|
||||||
#include "snprintf.h"
|
#include "snprintf.h"
|
||||||
|
#include "util.h" /* xmpp_min */
|
||||||
#include "resolver.h"
|
#include "resolver.h"
|
||||||
|
|
||||||
#define MESSAGE_HEADER_LEN 12
|
#define MESSAGE_HEADER_LEN 12
|
||||||
@@ -65,6 +66,26 @@ static uint8_t message_header_rcode(const struct message_header *header)
|
|||||||
return header->octet3 & 0x0f;
|
return header->octet3 & 0x0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Append a label or a dot to the target name with buffer overflow checks.
|
||||||
|
* Returns length of the non-truncated resulting string, may be bigger than
|
||||||
|
* name_max.
|
||||||
|
*/
|
||||||
|
static size_t message_name_append_safe(char *name, size_t name_len,
|
||||||
|
size_t name_max,
|
||||||
|
const char *tail, size_t tail_len)
|
||||||
|
{
|
||||||
|
size_t copy_len;
|
||||||
|
|
||||||
|
copy_len = name_max > name_len ? name_max - name_len : 0;
|
||||||
|
copy_len = xmpp_min(tail_len, copy_len);
|
||||||
|
if (copy_len > 0)
|
||||||
|
strncpy(&name[name_len], tail, copy_len);
|
||||||
|
|
||||||
|
return name_len + tail_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns length of the compressed name. This is NOT the same as strlen(). */
|
||||||
static unsigned message_name_get(const unsigned char *buf, size_t buf_len,
|
static unsigned message_name_get(const unsigned char *buf, size_t buf_len,
|
||||||
unsigned buf_offset,
|
unsigned buf_offset,
|
||||||
char *name, size_t name_max)
|
char *name, size_t name_max)
|
||||||
@@ -72,25 +93,41 @@ static unsigned message_name_get(const unsigned char *buf, size_t buf_len,
|
|||||||
size_t name_len = 0;
|
size_t name_len = 0;
|
||||||
unsigned i = buf_offset;
|
unsigned i = buf_offset;
|
||||||
unsigned pointer;
|
unsigned pointer;
|
||||||
|
unsigned rc;
|
||||||
unsigned char label_len;
|
unsigned char label_len;
|
||||||
|
|
||||||
while ((label_len = buf[i++]) != 0) {
|
|
||||||
/* label */
|
while (1) {
|
||||||
|
if (i >= buf_len) return 0;
|
||||||
|
label_len = buf[i++];
|
||||||
|
if (label_len == 0) break;
|
||||||
|
|
||||||
|
/* Label */
|
||||||
if ((label_len & 0xc0) == 0) {
|
if ((label_len & 0xc0) == 0) {
|
||||||
|
if (i + label_len - 1 >= buf_len) return 0;
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
if (name_len != 0)
|
name_len = message_name_append_safe(name, name_len, name_max,
|
||||||
name[name_len++] = '.';
|
(char *)&buf[i], label_len);
|
||||||
strncpy(&name[name_len], (char *)&buf[i], label_len);
|
name_len = message_name_append_safe(name, name_len, name_max,
|
||||||
|
".", 1);
|
||||||
}
|
}
|
||||||
i += label_len;
|
i += label_len;
|
||||||
name_len += label_len;
|
|
||||||
|
|
||||||
/* pointer */
|
/* Pointer */
|
||||||
} else if ((label_len & 0xc0) == 0xc0) {
|
} else if ((label_len & 0xc0) == 0xc0) {
|
||||||
|
if (i >= buf_len) return 0;
|
||||||
pointer = (label_len & 0x3f) << 8 | buf[i++];
|
pointer = (label_len & 0x3f) << 8 | buf[i++];
|
||||||
(void)message_name_get(buf, buf_len, pointer, &name[name_len],
|
if (name != NULL && name_len >= name_max && name_max > 0) {
|
||||||
name_max - name_len);
|
/* We have filled the name buffer. Don't pass it recursively. */
|
||||||
/* pointer is always the last */
|
name[name_max - 1] = '\0';
|
||||||
|
name = NULL;
|
||||||
|
name_max = 0;
|
||||||
|
}
|
||||||
|
rc = message_name_get(buf, buf_len, pointer,
|
||||||
|
name != NULL ? &name[name_len] : NULL,
|
||||||
|
name_max > name_len ? name_max - name_len : 0);
|
||||||
|
if (rc == 0) return 0;
|
||||||
|
/* Pointer is always the last. */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* The 10 and 01 combinations are reserved for future use. */
|
/* The 10 and 01 combinations are reserved for future use. */
|
||||||
@@ -98,8 +135,21 @@ static unsigned message_name_get(const unsigned char *buf, size_t buf_len,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (label_len == 0 && name != NULL)
|
if (label_len == 0) {
|
||||||
name[name_len] = '\0';
|
if (name_len == 0) name_len = 1;
|
||||||
|
/*
|
||||||
|
* At this point name_len is length of the resulting name,
|
||||||
|
* including '\0'. This value can be exported to allocate buffer
|
||||||
|
* of precise size.
|
||||||
|
*/
|
||||||
|
if (name != NULL && name_max > 0) {
|
||||||
|
/*
|
||||||
|
* Overwrite leading '.' with a '\0'. If the resulting name is
|
||||||
|
* bigger than name_max it is truncated.
|
||||||
|
*/
|
||||||
|
name[xmpp_min(name_len, name_max) - 1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return i - buf_offset;
|
return i - buf_offset;
|
||||||
}
|
}
|
||||||
@@ -167,6 +217,15 @@ static void resolver_srv_list_sort(resolver_srv_rr_t **srv_rr_list)
|
|||||||
*srv_rr_list = rr_head;
|
*srv_rr_list = rr_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BUF_OVERFLOW_CHECK(ptr, len) do { \
|
||||||
|
if ((ptr) >= (len)) { \
|
||||||
|
if (*srv_rr_list != NULL) \
|
||||||
|
resolver_srv_free(ctx, *srv_rr_list); \
|
||||||
|
*srv_rr_list = NULL; \
|
||||||
|
return XMPP_DOMAIN_NOT_FOUND; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
int resolver_srv_lookup_buf(xmpp_ctx_t *ctx, const unsigned char *buf,
|
int resolver_srv_lookup_buf(xmpp_ctx_t *ctx, const unsigned char *buf,
|
||||||
size_t len, resolver_srv_rr_t **srv_rr_list)
|
size_t len, resolver_srv_rr_t **srv_rr_list)
|
||||||
{
|
{
|
||||||
@@ -200,17 +259,20 @@ int resolver_srv_lookup_buf(xmpp_ctx_t *ctx, const unsigned char *buf,
|
|||||||
|
|
||||||
/* skip question section */
|
/* skip question section */
|
||||||
for (i = 0; i < header.qdcount; ++i) {
|
for (i = 0; i < header.qdcount; ++i) {
|
||||||
|
BUF_OVERFLOW_CHECK(j, len);
|
||||||
name_len = message_name_len(buf, len, j);
|
name_len = message_name_len(buf, len, j);
|
||||||
if (name_len == 0) {
|
/* error in name format */
|
||||||
/* error in name format */
|
if (name_len == 0) return XMPP_DOMAIN_NOT_FOUND;
|
||||||
return XMPP_DOMAIN_NOT_FOUND;
|
|
||||||
}
|
|
||||||
j += name_len + 4;
|
j += name_len + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < header.ancount; ++i) {
|
for (i = 0; i < header.ancount; ++i) {
|
||||||
|
BUF_OVERFLOW_CHECK(j, len);
|
||||||
name_len = message_name_len(buf, len, j);
|
name_len = message_name_len(buf, len, j);
|
||||||
|
/* error in name format */
|
||||||
|
if (name_len == 0) return XMPP_DOMAIN_NOT_FOUND;
|
||||||
j += name_len;
|
j += name_len;
|
||||||
|
BUF_OVERFLOW_CHECK(j + 16, len);
|
||||||
type = xmpp_ntohs_ptr(&buf[j]);
|
type = xmpp_ntohs_ptr(&buf[j]);
|
||||||
class = xmpp_ntohs_ptr(&buf[j + 2]);
|
class = xmpp_ntohs_ptr(&buf[j + 2]);
|
||||||
rdlength = xmpp_ntohs_ptr(&buf[j + 8]);
|
rdlength = xmpp_ntohs_ptr(&buf[j + 8]);
|
||||||
|
|||||||
@@ -65,4 +65,5 @@ int resolver_srv_lookup(xmpp_ctx_t *ctx, const char *service, const char *proto,
|
|||||||
* @param srv_rr_list a list allocated by lookup functions
|
* @param srv_rr_list a list allocated by lookup functions
|
||||||
*/
|
*/
|
||||||
void resolver_srv_free(xmpp_ctx_t *ctx, resolver_srv_rr_t *srv_rr_list);
|
void resolver_srv_free(xmpp_ctx_t *ctx, resolver_srv_rr_t *srv_rr_list);
|
||||||
|
|
||||||
#endif /* __LIBSTROPHE_RESOLVER_H__ */
|
#endif /* __LIBSTROPHE_RESOLVER_H__ */
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
#include "ostypes.h"
|
#include "ostypes.h"
|
||||||
|
|
||||||
|
/* TODO evaluate x and y only once */
|
||||||
|
#define xmpp_min(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
||||||
/* string functions */
|
/* string functions */
|
||||||
char *xmpp_strtok_r(char *s, const char *delim, char **saveptr);
|
char *xmpp_strtok_r(char *s, const char *delim, char **saveptr);
|
||||||
|
|
||||||
|
|||||||
@@ -10,27 +10,34 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <check.h>
|
#include "strophe.h"
|
||||||
|
|
||||||
#include <strophe.h>
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
START_TEST(create_destroy)
|
#define fail_unless(expr) do { \
|
||||||
|
int result = (expr); \
|
||||||
|
if (!result) { \
|
||||||
|
printf("%s:%d: Assertion failed: %s\n", \
|
||||||
|
__FILE__, __LINE__, #expr); \
|
||||||
|
exit(1); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static void create_destroy(void)
|
||||||
{
|
{
|
||||||
xmpp_ctx_t *ctx;
|
xmpp_ctx_t *ctx;
|
||||||
parser_t *parser;
|
parser_t *parser;
|
||||||
|
|
||||||
ctx = xmpp_ctx_new(NULL, NULL);
|
ctx = xmpp_ctx_new(NULL, NULL);
|
||||||
parser = parser_new(ctx, NULL, NULL, NULL, NULL);
|
parser = parser_new(ctx, NULL, NULL, NULL, NULL);
|
||||||
fail_unless(parser != NULL, "Parser creation failed.");
|
fail_unless(parser != NULL);
|
||||||
parser_free(parser);
|
parser_free(parser);
|
||||||
xmpp_ctx_free(ctx);
|
xmpp_ctx_free(ctx);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
int cbtest_got_start = 0;
|
int cbtest_got_start = 0;
|
||||||
void cbtest_handle_start(char *name, char **attrs, void *userdata)
|
void cbtest_handle_start(char *name, char **attrs, void *userdata)
|
||||||
@@ -53,7 +60,7 @@ void cbtest_handle_stanza(xmpp_stanza_t *stanza, void *userdata)
|
|||||||
cbtest_got_stanza = 1;
|
cbtest_got_stanza = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(callbacks)
|
static void callbacks(void)
|
||||||
{
|
{
|
||||||
xmpp_ctx_t *ctx;
|
xmpp_ctx_t *ctx;
|
||||||
parser_t *parser;
|
parser_t *parser;
|
||||||
@@ -79,16 +86,18 @@ START_TEST(callbacks)
|
|||||||
parser_free(parser);
|
parser_free(parser);
|
||||||
xmpp_ctx_free(ctx);
|
xmpp_ctx_free(ctx);
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
Suite *parser_suite(void)
|
int main()
|
||||||
{
|
{
|
||||||
Suite *s = suite_create("Parser");
|
printf("XML parser tests.\n");
|
||||||
TCase *tc_core = tcase_create("Core");
|
|
||||||
tcase_add_test(tc_core, create_destroy);
|
|
||||||
tcase_add_test(tc_core, callbacks);
|
|
||||||
suite_add_tcase(s, tc_core);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_MAIN
|
printf("create-destroy: ");
|
||||||
|
create_destroy();
|
||||||
|
printf("ok\n");
|
||||||
|
|
||||||
|
printf("callbacks: ");
|
||||||
|
callbacks();
|
||||||
|
printf("ok\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "strophe.h"
|
#include "strophe.h"
|
||||||
|
#include "rand.h"
|
||||||
#include "resolver.h"
|
#include "resolver.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
@@ -84,7 +85,6 @@ static const unsigned char data3[] = {
|
|||||||
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f,
|
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f,
|
||||||
0x6d, 0x00,
|
0x6d, 0x00,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* res_query("_xmpp-client._tcp.jabber.calyxinstitute.org", C_IN, T_SRV, ...) */
|
/* res_query("_xmpp-client._tcp.jabber.calyxinstitute.org", C_IN, T_SRV, ...) */
|
||||||
static const unsigned char data4[] = {
|
static const unsigned char data4[] = {
|
||||||
0x8d, 0x58, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // .X........
|
0x8d, 0x58, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // .X........
|
||||||
@@ -103,6 +103,34 @@ static const unsigned char data4[] = {
|
|||||||
0x61, 0x6c, 0x79, 0x78, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, // alyxinstit
|
0x61, 0x6c, 0x79, 0x78, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, // alyxinstit
|
||||||
0x75, 0x74, 0x65, 0x03, 0x6f, 0x72, 0x67, 0x00, // ute.org.
|
0x75, 0x74, 0x65, 0x03, 0x6f, 0x72, 0x67, 0x00, // ute.org.
|
||||||
};
|
};
|
||||||
|
/* res_query("_xmpp-client._tcp.jabber.org", C_IN, T_SRV, ...) with pointers */
|
||||||
|
static const unsigned char data5[] = {
|
||||||
|
0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // ..........
|
||||||
|
0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, // ..._xmpp-c
|
||||||
|
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, // lient._tcp
|
||||||
|
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72, // .jabber.or
|
||||||
|
0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x21, // g..!.....!
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x01, 0x9e, 0x00, 0x12, 0x00, 0x1f, // ..........
|
||||||
|
0x00, 0x1e, 0x14, 0x66, 0x09, 0x68, 0x65, 0x72, 0x6d, 0x65, // ...f.herme
|
||||||
|
0x73, 0x32, 0x76, 0x36, 0xc0, 0x1e, 0xc0, 0x0c, 0x00, 0x21, // s2v6.....!
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x01, 0x9e, 0x00, 0x10, 0x00, 0x1e, // ..........
|
||||||
|
0x00, 0x1e, 0x14, 0x66, 0x07, 0x68, 0x65, 0x72, 0x6d, 0x65, // ...f.herme
|
||||||
|
0x73, 0x32, 0xc0, 0x1e, // s2..
|
||||||
|
};
|
||||||
|
/* hacked data2 with two empty-string targets. */
|
||||||
|
static const unsigned char data6[] = {
|
||||||
|
0xf2, 0x98, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d,
|
||||||
|
0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||||
|
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a,
|
||||||
|
0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72,
|
||||||
|
0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c,
|
||||||
|
0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, 0x83,
|
||||||
|
0x00, 0x07, 0x00, 0x1e, 0x00, 0x1e, 0x14, 0x66,
|
||||||
|
0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00,
|
||||||
|
0x00, 0x03, 0x83, 0x00, 0x08, 0x00, 0x1f, 0x00,
|
||||||
|
0x1e, 0x14, 0x66, 0xc0, 0x40,
|
||||||
|
};
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const unsigned char *data;
|
const unsigned char *data;
|
||||||
@@ -139,13 +167,27 @@ static const struct {
|
|||||||
.port = 5222,
|
.port = 5222,
|
||||||
.target_nr = 2,
|
.target_nr = 2,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.data = data5,
|
||||||
|
.len = sizeof(data5),
|
||||||
|
.target = "hermes2.jabber.org",
|
||||||
|
.port = 5222,
|
||||||
|
.target_nr = 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.data = data6,
|
||||||
|
.len = sizeof(data6),
|
||||||
|
.target = "",
|
||||||
|
.port = 5222,
|
||||||
|
.target_nr = 2,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int srv_rr_list_len(resolver_srv_rr_t *list)
|
static int srv_rr_list_len(resolver_srv_rr_t *list)
|
||||||
{
|
{
|
||||||
int nr;
|
int nr;
|
||||||
|
|
||||||
for(nr = 0; list != NULL; ++nr, list = list->next);
|
for (nr = 0; list != NULL; ++nr, list = list->next);
|
||||||
|
|
||||||
return nr;
|
return nr;
|
||||||
}
|
}
|
||||||
@@ -153,8 +195,10 @@ static int srv_rr_list_len(resolver_srv_rr_t *list)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
xmpp_ctx_t *ctx;
|
xmpp_ctx_t *ctx;
|
||||||
|
xmpp_rand_t *rand;
|
||||||
resolver_srv_rr_t *srv_rr_list;
|
resolver_srv_rr_t *srv_rr_list;
|
||||||
char *domain;
|
char *domain;
|
||||||
|
unsigned char *buf;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -187,6 +231,25 @@ int main(int argc, char **argv)
|
|||||||
resolver_srv_free(ctx, srv_rr_list);
|
resolver_srv_free(ctx, srv_rr_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The next test case must not crash and is supposed to be checked
|
||||||
|
* under valgrind.
|
||||||
|
*/
|
||||||
|
printf("Test of a broken message: ");
|
||||||
|
rand = xmpp_rand_new(ctx);
|
||||||
|
assert(rand != NULL);
|
||||||
|
assert(sizeof(data2) > 64);
|
||||||
|
buf = xmpp_alloc(ctx, sizeof(data2));
|
||||||
|
assert(buf != NULL);
|
||||||
|
memcpy(buf, data2, 64);
|
||||||
|
xmpp_rand_bytes(rand, &buf[64], sizeof(data2) - 64);
|
||||||
|
ret = resolver_srv_lookup_buf(ctx, buf, sizeof(data2), &srv_rr_list);
|
||||||
|
if (ret == XMPP_DOMAIN_FOUND && srv_rr_list != NULL)
|
||||||
|
resolver_srv_free(ctx, srv_rr_list);
|
||||||
|
xmpp_free(ctx, buf);
|
||||||
|
xmpp_rand_free(ctx, rand);
|
||||||
|
printf("ok\n");
|
||||||
|
|
||||||
xmpp_ctx_free(ctx);
|
xmpp_ctx_free(ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user