Use bigger buffer to avoid stack corruption, as seen when running app built with...
[reactos.git] / reactos / apps / utils / net / ping / ping.c
index f68b263..5d2efba 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id$
- *
+/*
  * COPYRIGHT:   See COPYING in the top level directory
  * PROJECT:     ReactOS ping utility
  * FILE:        apps/net/ping/ping.c
@@ -8,15 +7,14 @@
  * REVISIONS:
  *   CSH  01/09/2000 Created
  */
-//#include <windows.h>
+
 #include <winsock2.h>
 #include <tchar.h>
 #include <stdarg.h>
 #include <string.h>
 #include <stdio.h>
-#ifndef _MSC_VER
 
-//#define DBG
+#ifndef _MSC_VER
 
 /* FIXME: Where should this be? */
 #ifdef CopyMemory
@@ -33,8 +31,11 @@ typedef long long __int64;
 
 char * _i64toa(__int64 value, char *string, int radix);
 
-#endif
+#endif /* _MSC_VER */
 
+#ifdef DBG
+#undef DBG
+#endif
 
 /* General ICMP constants */
 #define ICMP_MINSIZE           8               /* Minimum ICMP packet size */
@@ -104,7 +105,7 @@ LARGE_INTEGER       TicksPerMs; /* Ticks per millisecond */
 LARGE_INTEGER       TicksPerUs; /* Ticks per microsecond */
 BOOL                UsePerformanceCounter;
 
-
+#ifdef DBG
 /* Display the contents of a buffer */
 static VOID DisplayBuffer(
     PVOID Buffer,
@@ -123,6 +124,7 @@ static VOID DisplayBuffer(
       printf("%02X ", (p[i]) & 0xFF);
     }
 }
+#endif /* DBG */
 
 /* Display usage information on screen */
 static VOID Usage(VOID)
@@ -179,7 +181,7 @@ static ULONG GetULONG(LPSTR String)
     ULONG Value;
 
     i = 0;
-    Length = strlen(String);
+    Length = (UINT)_tcslen(String);
     while ((i < Length) && ((String[i] < '0') || (String[i] > '9'))) i++;
     if ((i >= Length) || ((String[i] < '0') || (String[i] > '9'))) {
         InvalidOption = TRUE;
@@ -406,7 +408,7 @@ static BOOL DecodeResponse(PCHAR buffer, UINT size, PSOCKADDR_IN from)
     CHAR              Time[100];
     LARGE_INTEGER     RelativeTime;
     LARGE_INTEGER     LargeTime;
-    CHAR              Sign[1];
+    CHAR              Sign[2];
 
     IpHeader = (PIPv4_HEADER)buffer;
 
@@ -450,12 +452,13 @@ static BOOL DecodeResponse(PCHAR buffer, UINT size, PSOCKADDR_IN from)
 
     printf("Reply from %s: bytes=%d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr),
       size - IphLength - sizeof(ICMP_ECHO_PACKET), Sign, Time, IpHeader->TTL);
-    if (RelativeTime.QuadPart < MinRTT.QuadPart) {
-                 MinRTT.QuadPart = RelativeTime.QuadPart;
-      MinRTTSet = TRUE;
+    if (RelativeTime.QuadPart < MinRTT.QuadPart || !MinRTTSet) {
+           MinRTT.QuadPart = RelativeTime.QuadPart;
+        MinRTTSet = TRUE;
     }
-         if (RelativeTime.QuadPart > MaxRTT.QuadPart)
-             MaxRTT.QuadPart = RelativeTime.QuadPart;
+       if (RelativeTime.QuadPart > MaxRTT.QuadPart)
+           MaxRTT.QuadPart = RelativeTime.QuadPart;
+
     SumRTT.QuadPart += RelativeTime.QuadPart;
 
        return TRUE;