[Asterisk-code-review] res_pjsip_logger.c: correct the return value checks when writing to p... (asterisk[master])

Joshua Colp asteriskteam at digium.com
Mon Jun 1 08:54:29 CDT 2020


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14475 )

Change subject: res_pjsip_logger.c: correct the return value checks when writing to pcap files
......................................................................

res_pjsip_logger.c: correct the return value checks when writing to pcap
files

fwrite() does return the number of elements written and not the
number of bytes. However asterisk is currently comparing the return
value to the size of the written element what means that asterisk logs
five WARNING messages on every packet written to the pcap file.

This patch changes the code to check for the correct value, which will
always be 1.

ASTERISK-28921 #close

Change-Id: I2455032d9cb4c5a500692923f9e2a22e68b08fc2
---
M res/res_pjsip_logger.c
1 file changed, 5 insertions(+), 5 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved



diff --git a/res/res_pjsip_logger.c b/res/res_pjsip_logger.c
index cc79f61..8380bd6 100644
--- a/res/res_pjsip_logger.c
+++ b/res/res_pjsip_logger.c
@@ -246,19 +246,19 @@
 	/* We lock the logger session since we're writing these out in parts */
 	ao2_wrlock(session);
 	if (session->pcap_file) {
-		if (fwrite(&pcap_record_header, sizeof(struct pcap_record_header), 1, session->pcap_file) != sizeof(struct pcap_record_header)) {
+		if (fwrite(&pcap_record_header, sizeof(struct pcap_record_header), 1, session->pcap_file) != 1) {
 			ast_log(LOG_WARNING, "Writing PCAP header failed: %s\n", strerror(errno));
 		}
-		if (fwrite(&pcap_ethernet_header, sizeof(struct pcap_ethernet_header), 1, session->pcap_file) != sizeof(struct pcap_ethernet_header)) {
+		if (fwrite(&pcap_ethernet_header, sizeof(struct pcap_ethernet_header), 1, session->pcap_file) != 1) {
 			ast_log(LOG_WARNING, "Writing ethernet header to pcap failed: %s\n", strerror(errno));
 		}
-		if (fwrite(pcap_ip_header, pcap_ip_header_len, 1, session->pcap_file) != pcap_ip_header_len) {
+		if (fwrite(pcap_ip_header, pcap_ip_header_len, 1, session->pcap_file) != 1) {
 			ast_log(LOG_WARNING, "Writing IP header to pcap failed: %s\n", strerror(errno));
 		}
-		if (fwrite(&pcap_udp_header, sizeof(struct pcap_udp_header), 1, session->pcap_file) != sizeof(struct pcap_udp_header)) {
+		if (fwrite(&pcap_udp_header, sizeof(struct pcap_udp_header), 1, session->pcap_file) != 1) {
 			ast_log(LOG_WARNING, "Writing UDP header to pcap failed: %s\n", strerror(errno));
 		}
-		if (fwrite(msg, msg_len, 1, session->pcap_file) != msg_len) {
+		if (fwrite(msg, msg_len, 1, session->pcap_file) != 1) {
 			ast_log(LOG_WARNING, "Writing UDP payload to pcap failed: %s\n", strerror(errno));
 		}
 	}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14475
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I2455032d9cb4c5a500692923f9e2a22e68b08fc2
Gerrit-Change-Number: 14475
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: nappsoft <infos at nappsoft.ch>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200601/90122ceb/attachment-0001.html>


More information about the asterisk-code-review mailing list