aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tuexen <tuexen@fh-muenster.de>2020-05-19 09:42:15 +0200
committerMichael Tuexen <tuexen@fh-muenster.de>2020-05-19 09:42:15 +0200
commitedd369d6a0544ee865ef3678c0c68ccf3a98a57c (patch)
treed23ebe4c9e19b5d0ff3a415364dfb00029370f6d
parentc6c994c79bfddc8c58306bed20e3f15343eecea0 (diff)
downloadusrsctp-edd369d6a0544ee865ef3678c0c68ccf3a98a57c.tar.gz
Use SCTP_SNPRINTF().
-rwxr-xr-xusrsctplib/netinet/sctp_asconf.c6
-rwxr-xr-xusrsctplib/netinet/sctp_bsd_addr.c4
-rwxr-xr-xusrsctplib/netinet/sctp_indata.c170
-rwxr-xr-xusrsctplib/netinet/sctp_input.c22
-rwxr-xr-xusrsctplib/netinet/sctp_os_userspace.h17
-rwxr-xr-xusrsctplib/netinet/sctp_output.c24
-rwxr-xr-xusrsctplib/netinet/sctp_pcb.c22
7 files changed, 104 insertions, 161 deletions
diff --git a/usrsctplib/netinet/sctp_asconf.c b/usrsctplib/netinet/sctp_asconf.c
index 782d0916..b3e5c399 100755
--- a/usrsctplib/netinet/sctp_asconf.c
+++ b/usrsctplib/netinet/sctp_asconf.c
@@ -34,7 +34,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 361222 2020-05-18 18:32:58Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 361243 2020-05-19 07:23:35Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -1743,9 +1743,7 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
char msg[SCTP_DIAG_INFO_LEN];
SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
- if (snprintf(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
*abort_no_unlock = 1;
diff --git a/usrsctplib/netinet/sctp_bsd_addr.c b/usrsctplib/netinet/sctp_bsd_addr.c
index e94da25e..228eccf8 100755
--- a/usrsctplib/netinet/sctp_bsd_addr.c
+++ b/usrsctplib/netinet/sctp_bsd_addr.c
@@ -542,9 +542,7 @@ sctp_init_ifns_for_vrf(int vrfid)
} else {
ifa_flags = 0;
}
- if (snprintf(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn)) < 0) {
- name[0] = '\0';
- }
+ SCTP_SNPRINTF(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn));
sctp_ifa = sctp_add_addr_to_vrf(vrfid,
(void *)ifn, /* XXX */
ifnet_index(ifn),
diff --git a/usrsctplib/netinet/sctp_indata.c b/usrsctplib/netinet/sctp_indata.c
index ff1d045e..88fc4301 100755
--- a/usrsctplib/netinet/sctp_indata.c
+++ b/usrsctplib/netinet/sctp_indata.c
@@ -34,7 +34,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.c 361209 2020-05-18 10:07:01Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.c 361243 2020-05-19 07:23:35Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -450,26 +450,22 @@ sctp_abort_in_reasm(struct sctp_tcb *stcb,
struct mbuf *oper;
if (stcb->asoc.idata_supported) {
- if (snprintf(msg, sizeof(msg),
- "Reass %x,CF:%x,TSN=%8.8x,SID=%4.4x,FSN=%8.8x,MID:%8.8x",
- opspot,
- control->fsn_included,
- chk->rec.data.tsn,
- chk->rec.data.sid,
- chk->rec.data.fsn, chk->rec.data.mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "Reass %x,CF:%x,TSN=%8.8x,SID=%4.4x,FSN=%8.8x,MID:%8.8x",
+ opspot,
+ control->fsn_included,
+ chk->rec.data.tsn,
+ chk->rec.data.sid,
+ chk->rec.data.fsn, chk->rec.data.mid);
} else {
- if (snprintf(msg, sizeof(msg),
- "Reass %x,CI:%x,TSN=%8.8x,SID=%4.4x,FSN=%4.4x,SSN:%4.4x",
- opspot,
- control->fsn_included,
- chk->rec.data.tsn,
- chk->rec.data.sid,
- chk->rec.data.fsn,
- (uint16_t)chk->rec.data.mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "Reass %x,CI:%x,TSN=%8.8x,SID=%4.4x,FSN=%4.4x,SSN:%4.4x",
+ opspot,
+ control->fsn_included,
+ chk->rec.data.tsn,
+ chk->rec.data.sid,
+ chk->rec.data.fsn,
+ (uint16_t)chk->rec.data.mid);
}
oper = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
sctp_m_freem(chk->data);
@@ -552,19 +548,15 @@ sctp_queue_data_to_stream(struct sctp_tcb *stcb,
*/
TAILQ_INSERT_HEAD(&strm->inqueue, control, next_instrm);
if (asoc->idata_supported) {
- if (snprintf(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x",
- strm->last_mid_delivered, control->sinfo_tsn,
- control->sinfo_stream, control->mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x",
+ strm->last_mid_delivered, control->sinfo_tsn,
+ control->sinfo_stream, control->mid);
} else {
- if (snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
- (uint16_t)strm->last_mid_delivered,
- control->sinfo_tsn,
- control->sinfo_stream,
- (uint16_t)control->mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ (uint16_t)strm->last_mid_delivered,
+ control->sinfo_tsn,
+ control->sinfo_stream,
+ (uint16_t)control->mid);
}
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2;
@@ -671,10 +663,8 @@ sctp_queue_data_to_stream(struct sctp_tcb *stcb,
* to put it on the queue.
*/
if (sctp_place_control_in_stream(strm, asoc, control)) {
- if (snprintf(msg, sizeof(msg),
- "Queue to str MID: %u duplicate", control->mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "Queue to str MID: %u duplicate", control->mid);
sctp_clean_up_control(stcb, control);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3;
@@ -1882,9 +1872,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
* XXX: This can happen in case of a wrap around.
* Ignore is for now.
*/
- if (snprintf(msg, sizeof(msg), "FSN zero for MID=%8.8x, but flags=%2.2x", mid, chk_flags) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "FSN zero for MID=%8.8x, but flags=%2.2x", mid, chk_flags);
goto err_out;
}
control = sctp_find_reasm_entry(&asoc->strmin[sid], mid, ordered, asoc->idata_supported);
@@ -1895,9 +1883,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
if (control != NULL) {
/* We found something, does it belong? */
if (ordered && (mid != control->mid)) {
- if (snprintf(msg, sizeof(msg), "Reassembly problem (MID=%8.8x)", mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Reassembly problem (MID=%8.8x)", mid);
err_out:
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16;
@@ -1907,20 +1893,16 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
}
if (ordered && ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED)) {
/* We can't have a switched order with an unordered chunk */
- if (snprintf(msg, sizeof(msg),
- "All fragments of a user message must be ordered or unordered (TSN=%8.8x)",
- tsn) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "All fragments of a user message must be ordered or unordered (TSN=%8.8x)",
+ tsn);
goto err_out;
}
if (!ordered && (((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) == 0)) {
/* We can't have a switched unordered with a ordered chunk */
- if (snprintf(msg, sizeof(msg),
+ SCTP_SNPRINTF(msg, sizeof(msg),
"All fragments of a user message must be ordered or unordered (TSN=%8.8x)",
- tsn) < 0) {
- msg[0] = '\0';
- }
+ tsn);
goto err_out;
}
}
@@ -1934,18 +1916,14 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
if (ordered || asoc->idata_supported) {
SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x dup detected on MID: %u\n",
chk_flags, mid);
- if (snprintf(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", mid);
goto err_out;
} else {
if ((tsn == control->fsn_included + 1) &&
(control->end_added == 0)) {
- if (snprintf(msg, sizeof(msg),
- "Illegal message sequence, missing end for MID: %8.8x",
- control->fsn_included) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "Illegal message sequence, missing end for MID: %8.8x",
+ control->fsn_included);
goto err_out;
} else {
control = NULL;
@@ -2042,21 +2020,17 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
mid, asoc->strmin[sid].last_mid_delivered);
if (asoc->idata_supported) {
- if (snprintf(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x",
- asoc->strmin[sid].last_mid_delivered,
- tsn,
- sid,
- mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x",
+ asoc->strmin[sid].last_mid_delivered,
+ tsn,
+ sid,
+ mid);
} else {
- if (snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
- (uint16_t)asoc->strmin[sid].last_mid_delivered,
- tsn,
- sid,
- (uint16_t)mid) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ (uint16_t)asoc->strmin[sid].last_mid_delivered,
+ tsn,
+ sid,
+ (uint16_t)mid);
}
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_17;
@@ -2784,9 +2758,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "%s", "I-DATA chunk received when DATA was negotiated") < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "%s", "I-DATA chunk received when DATA was negotiated");
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_20;
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
@@ -2797,9 +2769,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "%s", "DATA chunk received when I-DATA was negotiated") < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "%s", "DATA chunk received when I-DATA was negotiated");
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_21;
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
@@ -2822,11 +2792,9 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "%s chunk of length %u",
- ch->chunk_type == SCTP_DATA ? "DATA" : "I-DATA",
- chk_length) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "%s chunk of length %u",
+ ch->chunk_type == SCTP_DATA ? "DATA" : "I-DATA",
+ chk_length);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_22;
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
@@ -2893,10 +2861,8 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "DATA chunk followed by chunk of type %2.2x",
- ch->chunk_type) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "DATA chunk followed by chunk of type %2.2x",
+ ch->chunk_type);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
return (2);
@@ -2914,9 +2880,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "Chunk of length %u", chk_length) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "Chunk of length %u", chk_length);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_23;
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
@@ -4047,11 +4011,9 @@ sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack,
*abort_now = 1;
/* XXX */
- if (snprintf(msg, sizeof(msg),
- "Cum ack %8.8x greater or equal than TSN %8.8x",
- cumack, send_s) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "Cum ack %8.8x greater or equal than TSN %8.8x",
+ cumack, send_s);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24;
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
@@ -4610,11 +4572,9 @@ sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup,
hopeless_peer:
*abort_now = 1;
/* XXX */
- if (snprintf(msg, sizeof(msg),
- "Cum ack %8.8x greater or equal than TSN %8.8x",
- cum_ack, send_s) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "Cum ack %8.8x greater or equal than TSN %8.8x",
+ cum_ack, send_s);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_28;
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
@@ -5669,11 +5629,9 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb,
* give out). This must be an attacker.
*/
*abort_flag = 1;
- if (snprintf(msg, sizeof(msg),
- "New cum ack %8.8x too high, highest TSN %8.8x",
- new_cum_tsn, asoc->highest_tsn_inside_map) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "New cum ack %8.8x too high, highest TSN %8.8x",
+ new_cum_tsn, asoc->highest_tsn_inside_map);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_36;
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
diff --git a/usrsctplib/netinet/sctp_input.c b/usrsctplib/netinet/sctp_input.c
index 6cba2891..5ab56a50 100755
--- a/usrsctplib/netinet/sctp_input.c
+++ b/usrsctplib/netinet/sctp_input.c
@@ -34,7 +34,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 361209 2020-05-18 10:07:01Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.c 361243 2020-05-19 07:23:35Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -4871,9 +4871,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
}
}
if (stcb == NULL) {
- if (snprintf(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
/* no association, so it's out of the blue... */
@@ -4917,9 +4915,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
if (stcb != NULL) {
SCTP_TCB_UNLOCK(stcb);
}
- if (snprintf(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] ='\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_handle_ootb(m, iphlen, *offset, src, dst,
@@ -5891,9 +5887,7 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt
#if defined(__FreeBSD__)
SCTP_PROBE5(receive, NULL, stcb, m, stcb, sh);
#endif
- if (snprintf(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_handle_ootb(m, iphlen, offset, src, dst, sh, inp, op_err,
@@ -5976,9 +5970,7 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt
#if defined(__FreeBSD__)
SCTP_PROBE5(receive, NULL, NULL, m, NULL, sh);
#endif
- if (snprintf(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_handle_ootb(m, iphlen, offset, src, dst, sh, inp, op_err,
@@ -6064,9 +6056,7 @@ sctp_common_input_processing(struct mbuf **mm, int iphlen, int offset, int lengt
/*
* We consider OOTB any data sent during asoc setup.
*/
- if (snprintf(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_handle_ootb(m, iphlen, offset, src, dst, sh, inp, op_err,
diff --git a/usrsctplib/netinet/sctp_os_userspace.h b/usrsctplib/netinet/sctp_os_userspace.h
index 3524a26d..c4fba935 100755
--- a/usrsctplib/netinet/sctp_os_userspace.h
+++ b/usrsctplib/netinet/sctp_os_userspace.h
@@ -221,9 +221,19 @@ typedef char* caddr_t;
#define bzero(buf, len) memset(buf, 0, len)
#define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len)
+
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(__MINGW32__)
-#define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__)
+#define SCTP_SNPRINTF(data, size, format, ...) \
+ if (_snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__) < 0) { \
+ data[0] = '\0'; \
+ }
+#else
+#define SCTP_SNPRINTF(data, ...) \
+ if (snprintf(data, __VA_ARGS__) < 0 ) { \
+ data[0] = '\0'; \
+ }
#endif
+
#define inline __inline
#define __inline__ __inline
#define MSG_EOR 0x8 /* data completes record */
@@ -830,6 +840,11 @@ sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
M_ALIGN(m, len); \
}
+#define SCTP_SNPRINTF(data, ...) \
+ if (snprintf(data, __VA_ARGS__) < 0) { \
+ data[0] = '\0'; \
+ }
+
/* We make it so if you have up to 4 threads
* writting based on the default size of
* the packet log 65 k, that would be
diff --git a/usrsctplib/netinet/sctp_output.c b/usrsctplib/netinet/sctp_output.c
index 786b0183..b1b12fa9 100755
--- a/usrsctplib/netinet/sctp_output.c
+++ b/usrsctplib/netinet/sctp_output.c
@@ -34,7 +34,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.c 361209 2020-05-18 10:07:01Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.c 361243 2020-05-19 07:23:35Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -6065,9 +6065,7 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if (op_err == NULL) {
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "%s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "%s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
}
@@ -7306,10 +7304,8 @@ sctp_sendall_iterator(struct sctp_inpcb *inp, struct sctp_tcb *stcb, void *ptr,
char msg[SCTP_DIAG_INFO_LEN];
abort_anyway:
- if (snprintf(msg, sizeof(msg),
- "%s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "%s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
atomic_add_int(&stcb->asoc.refcnt, 1);
@@ -10210,10 +10206,8 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp,
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- if (snprintf(msg, sizeof(msg), "TSN %8.8x retransmitted %d times, giving up",
- chk->rec.data.tsn, chk->snd_count) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg), "TSN %8.8x retransmitted %d times, giving up",
+ chk->rec.data.tsn, chk->snd_count);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
atomic_add_int(&stcb->asoc.refcnt, 1);
@@ -14815,10 +14809,8 @@ dataless_eof:
atomic_add_int(&stcb->asoc.refcnt, -1);
free_cnt_applied = 0;
}
- if (snprintf(msg, sizeof(msg),
- "%s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "%s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
#if defined(__FreeBSD__)
diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c
index ea0d7e55..5fa47088 100755
--- a/usrsctplib/netinet/sctp_pcb.c
+++ b/usrsctplib/netinet/sctp_pcb.c
@@ -34,7 +34,7 @@
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.c 361224 2020-05-18 18:42:43Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.c 361243 2020-05-19 07:23:35Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@@ -606,13 +606,9 @@ sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index,
atomic_add_int(&vrf->refcount, 1);
sctp_ifnp->ifn_mtu = SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, addr->sa_family);
if (if_name != NULL) {
- if (snprintf(sctp_ifnp->ifn_name, SCTP_IFNAMSIZ, "%s", if_name) < 0) {
- sctp_ifnp->ifn_name[0] = '\0';
- }
+ SCTP_SNPRINTF(sctp_ifnp->ifn_name, SCTP_IFNAMSIZ, "%s", if_name);
} else {
- if (snprintf(sctp_ifnp->ifn_name, SCTP_IFNAMSIZ, "%s", "unknown") < 0) {
- sctp_ifnp->ifn_name[0] = '\0';
- }
+ SCTP_SNPRINTF(sctp_ifnp->ifn_name, SCTP_IFNAMSIZ, "%s", "unknown");
}
hash_ifn_head = &SCTP_BASE_INFO(vrf_ifn_hash)[(ifn_index & SCTP_BASE_INFO(vrf_ifn_hashmark))];
LIST_INIT(&sctp_ifnp->ifalist);
@@ -7298,10 +7294,8 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
char msg[SCTP_DIAG_INFO_LEN];
/* in setup state we abort this guy */
- if (snprintf(msg, sizeof(msg),
- "%s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "%s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_abort_an_association(stcb_tmp->sctp_ep,
@@ -7394,10 +7388,8 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
char msg[SCTP_DIAG_INFO_LEN];
/* in setup state we abort this guy */
- if (snprintf(msg, sizeof(msg),
- "%s:%d at %s", __FILE__, __LINE__, __func__) < 0) {
- msg[0] = '\0';
- }
+ SCTP_SNPRINTF(msg, sizeof(msg),
+ "%s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_abort_an_association(stcb_tmp->sctp_ep,