[Qemu-devel] [PATCH] net/filter-rewriter.c: Fix trace_event print bug

Zhang Chen posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/1492151235-16173-1-git-send-email-zhangchen.fnst@cn.fujitsu.com
Test checkpatch passed
Test docker passed
Test s390x passed
net/filter-rewriter.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
[Qemu-devel] [PATCH] net/filter-rewriter.c: Fix trace_event print bug
Posted by Zhang Chen 7 years ago
Because of inet_ntoa() return a statically allocated buffer,
subsequent calls will overwrite, So we fix this bug.

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
---
 net/filter-rewriter.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index 91cf6b2..aad00b4 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -69,8 +69,13 @@ static int handle_primary_tcp_pkt(RewriterState *rf,
 
     tcp_pkt = (struct tcphdr *)pkt->transport_header;
     if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
+        char ip_src[20], ip_dst[20];
+
+        strcpy(ip_src, inet_ntoa(pkt->ip->ip_src));
+        strcpy(ip_dst, inet_ntoa(pkt->ip->ip_dst));
+
         trace_colo_filter_rewriter_pkt_info(__func__,
-                    inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
+                    ip_src, ip_dst,
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
         trace_colo_filter_rewriter_conn_offset(conn->offset);
@@ -144,8 +149,13 @@ static int handle_secondary_tcp_pkt(RewriterState *rf,
     tcp_pkt = (struct tcphdr *)pkt->transport_header;
 
     if (trace_event_get_state(TRACE_COLO_FILTER_REWRITER_DEBUG)) {
+        char ip_src[20], ip_dst[20];
+
+        strcpy(ip_src, inet_ntoa(pkt->ip->ip_src));
+        strcpy(ip_dst, inet_ntoa(pkt->ip->ip_dst));
+
         trace_colo_filter_rewriter_pkt_info(__func__,
-                    inet_ntoa(pkt->ip->ip_src), inet_ntoa(pkt->ip->ip_dst),
+                    ip_src, ip_dst,
                     ntohl(tcp_pkt->th_seq), ntohl(tcp_pkt->th_ack),
                     tcp_pkt->th_flags);
         trace_colo_filter_rewriter_conn_offset(conn->offset);
-- 
2.7.4