mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-14 20:29:43 +03:00
block.h: Make COAP_OPT_BLOCK_* functions safe against NULL indirects
COAP_OPT_BLOCK_LAST(opt) may return NULL, so doing *COAP_OPT_BLOCK_LAST(opt) is unsafe. Replace indirect with COAP_OPT_BLOCK_END_BYTE(opt).
This commit is contained in:
1 parent
4ef0705ccd
commit
dbf78b526f
2 files changed
+8
-3
No files matched your search
@@ -70,13 +70,18 @@ typedef struct {
|
||||
#define COAP_OPT_BLOCK_LAST(opt) \
|
||||
(coap_opt_length(opt) ? (coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
|
||||
|
||||
/** Returns the value of the last byte of @p opt. */
|
||||
#define COAP_OPT_BLOCK_END_BYTE(opt) \
|
||||
((coap_opt_length(opt) && coap_opt_value(opt)) ? \
|
||||
*(coap_opt_value(opt) + (coap_opt_length(opt)-1)) : 0)
|
||||
|
||||
/** Returns the value of the More-bit of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_MORE(opt) \
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x08) : 0)
|
||||
(coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x08) : 0)
|
||||
|
||||
/** Returns the value of the SZX-field of a Block option @p opt. */
|
||||
#define COAP_OPT_BLOCK_SZX(opt) \
|
||||
(coap_opt_length(opt) ? (*COAP_OPT_BLOCK_LAST(opt) & 0x07) : 0)
|
||||
(coap_opt_length(opt) ? (COAP_OPT_BLOCK_END_BYTE(opt) & 0x07) : 0)
|
||||
|
||||
/**
|
||||
* Returns the value of field @c num in the given block option @p block_opt.
|
||||
|
||||
Reference in new issue
Block a user