Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
c191d52c
Unverified
Commit
c191d52c
authored
6 years ago
by
Ken Bannister
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #10779 from kb2ma/gcoap/cli_buffer_size
examples/gcoap: verify buffer size
parents
6ee729bf
f1b08275
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/gcoap/gcoap_cli.c
+17
-3
17 additions, 3 deletions
examples/gcoap/gcoap_cli.c
with
17 additions
and
3 deletions
examples/gcoap/gcoap_cli.c
+
17
−
3
View file @
c191d52c
...
@@ -137,8 +137,15 @@ static ssize_t _riot_board_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, vo
...
@@ -137,8 +137,15 @@ static ssize_t _riot_board_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, vo
(
void
)
ctx
;
(
void
)
ctx
;
gcoap_resp_init
(
pdu
,
buf
,
len
,
COAP_CODE_CONTENT
);
gcoap_resp_init
(
pdu
,
buf
,
len
,
COAP_CODE_CONTENT
);
/* write the RIOT board name in the response buffer */
/* write the RIOT board name in the response buffer */
memcpy
(
pdu
->
payload
,
RIOT_BOARD
,
strlen
(
RIOT_BOARD
));
/* must be 'greater than' to account for payload marker byte */
return
gcoap_finish
(
pdu
,
strlen
(
RIOT_BOARD
),
COAP_FORMAT_TEXT
);
if
(
pdu
->
payload_len
>
strlen
(
RIOT_BOARD
))
{
memcpy
(
pdu
->
payload
,
RIOT_BOARD
,
strlen
(
RIOT_BOARD
));
return
gcoap_finish
(
pdu
,
strlen
(
RIOT_BOARD
),
COAP_FORMAT_TEXT
);
}
else
{
puts
(
"gcoap_cli: msg buffer too small"
);
return
gcoap_response
(
pdu
,
buf
,
len
,
COAP_CODE_INTERNAL_SERVER_ERROR
);
}
}
}
static
size_t
_send
(
uint8_t
*
buf
,
size_t
len
,
char
*
addr_str
,
char
*
port_str
)
static
size_t
_send
(
uint8_t
*
buf
,
size_t
len
,
char
*
addr_str
,
char
*
port_str
)
...
@@ -243,7 +250,14 @@ int gcoap_cli_cmd(int argc, char **argv)
...
@@ -243,7 +250,14 @@ int gcoap_cli_cmd(int argc, char **argv)
((
argc
==
apos
+
4
)
&&
(
code_pos
!=
0
)))
{
((
argc
==
apos
+
4
)
&&
(
code_pos
!=
0
)))
{
gcoap_req_init
(
&
pdu
,
&
buf
[
0
],
GCOAP_PDU_BUF_SIZE
,
code_pos
+
1
,
argv
[
apos
+
2
]);
gcoap_req_init
(
&
pdu
,
&
buf
[
0
],
GCOAP_PDU_BUF_SIZE
,
code_pos
+
1
,
argv
[
apos
+
2
]);
if
(
argc
==
apos
+
4
)
{
if
(
argc
==
apos
+
4
)
{
memcpy
(
pdu
.
payload
,
argv
[
apos
+
3
],
strlen
(
argv
[
apos
+
3
]));
/* must be 'greater than' to account for payload marker byte */
if
(
pdu
.
payload_len
>
strlen
(
argv
[
apos
+
3
]))
{
memcpy
(
pdu
.
payload
,
argv
[
apos
+
3
],
strlen
(
argv
[
apos
+
3
]));
}
else
{
puts
(
"gcoap_cli: msg buffer too small"
);
return
1
;
}
}
}
coap_hdr_set_type
(
pdu
.
hdr
,
msg_type
);
coap_hdr_set_type
(
pdu
.
hdr
,
msg_type
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment