Browse Source

Fix potential division by zero in example server.

Kareem 1 month ago
parent
commit
4d4f4e3f30
1 changed files with 13 additions and 8 deletions
  1. 13 8
      examples/server/server.c

+ 13 - 8
examples/server/server.c

@@ -513,14 +513,19 @@ int ServerEchoData(SSL* ssl, int clientfd, int echoData, int block,
 #define SIZE_FMT "%zu"
 #define SIZE_TYPE size_t
 #endif
-        printf(
-            "wolfSSL Server Benchmark " SIZE_FMT " bytes\n"
-            "\tRX      %8.3f ms (%8.3f MBps)\n"
-            "\tTX      %8.3f ms (%8.3f MBps)\n",
-            (SIZE_TYPE)throughput,
-            rx_time * 1000, throughput / rx_time / 1024 / 1024,
-            tx_time * 1000, throughput / tx_time / 1024 / 1024
-        );
+        if (rx_time && tx_time) {
+            printf(
+                "wolfSSL Server Benchmark " SIZE_FMT " bytes\n"
+                "\tRX      %8.3f ms (%8.3f MBps)\n"
+                "\tTX      %8.3f ms (%8.3f MBps)\n",
+                (SIZE_TYPE)throughput,
+                rx_time * 1000, throughput / rx_time / 1024 / 1024,
+                tx_time * 1000, throughput / tx_time / 1024 / 1024
+            );
+        }
+        else {
+            printf("Invalid rx_time: %f or tx_time: %f\n", rx_time, tx_time);
+        }
     }
 
     return 0;