Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
10b11b03
Commit
10b11b03
authored
Dec 29, 2019
by
Deomid Ryabkov
Committed by
Cesanta Bot
Dec 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mg_dns_encode_name_s for non-NUL terminated strings
PUBLISHED_FROM=012e2939021d1b275a39632fd2982891d2c98c4e
parent
cb602f17
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
20 deletions
+39
-20
mongoose.c
mongoose.c
+14
-10
mg_dns.c
src/mg_dns.c
+14
-10
mg_dns.h
src/mg_dns.h
+1
-0
unit_test.c
test/unit_test.c
+10
-0
No files found.
mongoose.c
View file @
10b11b03
...
@@ -11616,35 +11616,39 @@ int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg) {
...
@@ -11616,35 +11616,39 @@ int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg) {
return
mbuf_append
(
io
,
begin
,
end
-
begin
);
return
mbuf_append
(
io
,
begin
,
end
-
begin
);
}
}
int
mg_dns_encode_name
(
struct
mbuf
*
io
,
const
char
*
name
,
size_t
len
)
{
int
mg_dns_encode_name
_s
(
struct
mbuf
*
io
,
struct
mg_str
name
)
{
const
char
*
s
;
const
char
*
s
;
unsigned
char
n
;
unsigned
char
n
;
size_t
pos
=
io
->
len
;
size_t
pos
=
io
->
len
;
do
{
do
{
if
((
s
=
strchr
(
name
,
'.'
))
==
NULL
)
{
if
((
s
=
mg_
strchr
(
name
,
'.'
))
==
NULL
)
{
s
=
name
+
len
;
s
=
name
.
p
+
name
.
len
;
}
}
if
(
s
-
name
>
127
)
{
if
(
s
-
name
.
p
>
127
)
{
return
-
1
;
/* TODO(mkm) cover */
return
-
1
;
/* TODO(mkm) cover */
}
}
n
=
s
-
name
;
/* chunk length */
n
=
s
-
name
.
p
;
/* chunk length */
mbuf_append
(
io
,
&
n
,
1
);
/* send length */
mbuf_append
(
io
,
&
n
,
1
);
/* send length */
mbuf_append
(
io
,
name
,
n
);
mbuf_append
(
io
,
name
.
p
,
n
);
if
(
*
s
==
'.'
)
{
if
(
n
<
name
.
len
&&
*
s
==
'.'
)
{
n
++
;
n
++
;
}
}
name
+=
n
;
name
.
p
+=
n
;
len
-=
n
;
name
.
len
-=
n
;
}
while
(
*
s
!=
'\0'
);
}
while
(
name
.
len
>
0
);
mbuf_append
(
io
,
"
\0
"
,
1
);
/* Mark end of host name */
mbuf_append
(
io
,
"
\0
"
,
1
);
/* Mark end of host name */
return
io
->
len
-
pos
;
return
io
->
len
-
pos
;
}
}
int
mg_dns_encode_name
(
struct
mbuf
*
io
,
const
char
*
name
,
size_t
len
)
{
return
mg_dns_encode_name_s
(
io
,
mg_mk_str_n
(
name
,
len
));
}
int
mg_dns_encode_record
(
struct
mbuf
*
io
,
struct
mg_dns_resource_record
*
rr
,
int
mg_dns_encode_record
(
struct
mbuf
*
io
,
struct
mg_dns_resource_record
*
rr
,
const
char
*
name
,
size_t
nlen
,
const
void
*
rdata
,
const
char
*
name
,
size_t
nlen
,
const
void
*
rdata
,
size_t
rlen
)
{
size_t
rlen
)
{
...
...
src/mg_dns.c
View file @
10b11b03
...
@@ -85,35 +85,39 @@ int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg) {
...
@@ -85,35 +85,39 @@ int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg) {
return
mbuf_append
(
io
,
begin
,
end
-
begin
);
return
mbuf_append
(
io
,
begin
,
end
-
begin
);
}
}
int
mg_dns_encode_name
(
struct
mbuf
*
io
,
const
char
*
name
,
size_t
len
)
{
int
mg_dns_encode_name
_s
(
struct
mbuf
*
io
,
struct
mg_str
name
)
{
const
char
*
s
;
const
char
*
s
;
unsigned
char
n
;
unsigned
char
n
;
size_t
pos
=
io
->
len
;
size_t
pos
=
io
->
len
;
do
{
do
{
if
((
s
=
strchr
(
name
,
'.'
))
==
NULL
)
{
if
((
s
=
mg_
strchr
(
name
,
'.'
))
==
NULL
)
{
s
=
name
+
len
;
s
=
name
.
p
+
name
.
len
;
}
}
if
(
s
-
name
>
127
)
{
if
(
s
-
name
.
p
>
127
)
{
return
-
1
;
/* TODO(mkm) cover */
return
-
1
;
/* TODO(mkm) cover */
}
}
n
=
s
-
name
;
/* chunk length */
n
=
s
-
name
.
p
;
/* chunk length */
mbuf_append
(
io
,
&
n
,
1
);
/* send length */
mbuf_append
(
io
,
&
n
,
1
);
/* send length */
mbuf_append
(
io
,
name
,
n
);
mbuf_append
(
io
,
name
.
p
,
n
);
if
(
*
s
==
'.'
)
{
if
(
n
<
name
.
len
&&
*
s
==
'.'
)
{
n
++
;
n
++
;
}
}
name
+=
n
;
name
.
p
+=
n
;
len
-=
n
;
name
.
len
-=
n
;
}
while
(
*
s
!=
'\0'
);
}
while
(
name
.
len
>
0
);
mbuf_append
(
io
,
"
\0
"
,
1
);
/* Mark end of host name */
mbuf_append
(
io
,
"
\0
"
,
1
);
/* Mark end of host name */
return
io
->
len
-
pos
;
return
io
->
len
-
pos
;
}
}
int
mg_dns_encode_name
(
struct
mbuf
*
io
,
const
char
*
name
,
size_t
len
)
{
return
mg_dns_encode_name_s
(
io
,
mg_mk_str_n
(
name
,
len
));
}
int
mg_dns_encode_record
(
struct
mbuf
*
io
,
struct
mg_dns_resource_record
*
rr
,
int
mg_dns_encode_record
(
struct
mbuf
*
io
,
struct
mg_dns_resource_record
*
rr
,
const
char
*
name
,
size_t
nlen
,
const
void
*
rdata
,
const
char
*
name
,
size_t
nlen
,
const
void
*
rdata
,
size_t
rlen
)
{
size_t
rlen
)
{
...
...
src/mg_dns.h
View file @
10b11b03
...
@@ -124,6 +124,7 @@ int mg_dns_encode_record(struct mbuf *io, struct mg_dns_resource_record *rr,
...
@@ -124,6 +124,7 @@ int mg_dns_encode_record(struct mbuf *io, struct mg_dns_resource_record *rr,
* Encodes a DNS name.
* Encodes a DNS name.
*/
*/
int
mg_dns_encode_name
(
struct
mbuf
*
io
,
const
char
*
name
,
size_t
len
);
int
mg_dns_encode_name
(
struct
mbuf
*
io
,
const
char
*
name
,
size_t
len
);
int
mg_dns_encode_name_s
(
struct
mbuf
*
io
,
struct
mg_str
name
);
/* Low-level: parses a DNS response. */
/* Low-level: parses a DNS response. */
int
mg_parse_dns
(
const
char
*
buf
,
int
len
,
struct
mg_dns_message
*
msg
);
int
mg_parse_dns
(
const
char
*
buf
,
int
len
,
struct
mg_dns_message
*
msg
);
...
...
test/unit_test.c
View file @
10b11b03
...
@@ -4590,6 +4590,15 @@ static const char *test_dns_encode(void) {
...
@@ -4590,6 +4590,15 @@ static const char *test_dns_encode(void) {
return
NULL
;
return
NULL
;
}
}
static
const
char
*
test_dns_encode_name
(
void
)
{
struct
mbuf
mb
;
mbuf_init
(
&
mb
,
0
);
ASSERT_EQ
(
mg_dns_encode_name
(
&
mb
,
"www.cesanta.com.net.org"
,
15
),
17
);
ASSERT_STREQ_NZ
(
mb
.
buf
,
"
\x03
"
"www"
"
\x07
"
"cesanta"
"
\x03
"
"com"
);
mbuf_free
(
&
mb
);
return
NULL
;
}
static
const
char
*
test_dns_uncompress
(
void
)
{
static
const
char
*
test_dns_uncompress
(
void
)
{
/*
/*
* Order or string constants is important. Names being uncompressed
* Order or string constants is important. Names being uncompressed
...
@@ -5781,6 +5790,7 @@ const char *tests_run(const char *filter) {
...
@@ -5781,6 +5790,7 @@ const char *tests_run(const char *filter) {
RUN_TEST
(
test_mqtt_broker
);
RUN_TEST
(
test_mqtt_broker
);
#endif
#endif
RUN_TEST
(
test_dns_encode
);
RUN_TEST
(
test_dns_encode
);
RUN_TEST
(
test_dns_encode_name
);
RUN_TEST
(
test_dns_uncompress
);
RUN_TEST
(
test_dns_uncompress
);
RUN_TEST
(
test_dns_decode
);
RUN_TEST
(
test_dns_decode
);
RUN_TEST
(
test_dns_decode_truncated
);
RUN_TEST
(
test_dns_decode_truncated
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment