Always call ndo->ndo_error with a memory-allocation error if they fail.
Add WARN_UNUSED_RESULT for compilers that support it, and use it for
those routines, so that any future code that doesn't check for failure
gets a warning.
#define NORETURN_FUNCPTR
#endif
+/*
+ * WARN_UNUSED_RESULT, before a function declaration, means "the caller
+ * should use the result of this function" (even if it's just a success/
+ * failure indication).
+ */
+#if __has_attribute(warn_unused_result) \
+ || ND_IS_AT_LEAST_GNUC_VERSION(3,4) \
+ || ND_IS_AT_LEAST_HP_C_VERSION(6,25)
+ #define WARN_UNUSED_RESULT __attribute((warn_unused_result))
+#else
+ #define WARN_UNUSED_RESULT
+#endif
+
/*
* PRINTFLIKE(x,y), after a function declaration, means "this function
* does printf-style formatting, with the xth argument being the format
PRINTFLIKE_FUNCPTR(2, 3);
};
-extern int nd_push_buffer(netdissect_options *, u_char *, const u_char *,
- u_int);
-extern int nd_push_snaplen(netdissect_options *, const u_char *, u_int);
+extern WARN_UNUSED_RESULT int nd_push_buffer(netdissect_options *, u_char *,
+ const u_char *, u_int);
+extern WARN_UNUSED_RESULT int nd_push_snaplen(netdissect_options *,
+ const u_char *, u_int);
extern void nd_change_snaplen(netdissect_options *, const u_char *, u_int);
extern void nd_pop_packet_info(netdissect_options *);
extern void nd_pop_all_packet_info(netdissect_options *);
*/
if (!nd_push_buffer(ndo, pt, pt, ctlen)) {
free(pt);
- return 0;
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "%s: can't push buffer on buffer stack", __func__);
}
return 1;
* Don't put padding + padding length(1 byte) + next header(1 byte)
* in the buffer because they are not part of the plaintext to decode.
*/
- nd_push_snaplen(ndo, pt, payloadlen - (padlen + 2));
+ if (!nd_push_snaplen(ndo, pt, payloadlen - (padlen + 2))) {
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "%s: can't push snaplen on buffer stack", __func__);
+ }
/* Now dissect the plaintext. */
ip_demux_print(ndo, pt, payloadlen - (padlen + 2), ver, fragmented,
* Cut off the snapshot length to the end of the
* payload.
*/
- nd_push_snaplen(ndo, p, length);
+ if (!nd_push_snaplen(ndo, p, length)) {
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "%s: can't push snaplen on buffer stack", __func__);
+ }
if (ndo->ndo_eflag) {
ND_PRINT("802.3");
/*
* Cut off the snapshot length to the end of the IP payload.
*/
- nd_push_snaplen(ndo, bp, len);
+ if (!nd_push_snaplen(ndo, bp, len)) {
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "%s: can't push snaplen on buffer stack", __func__);
+ }
len -= hlen;
/*
* Cut off the snapshot length to the end of the IP payload.
*/
- nd_push_snaplen(ndo, bp, len);
+ if (!nd_push_snaplen(ndo, bp, len)) {
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "%s: can't push snaplen on buffer stack", __func__);
+ }
cp = (const u_char *)ip6;
advance = sizeof(struct ip6_hdr);