[PATCH] Cygwin: Fix size of a buffer in the ps utility

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Cygwin: Fix size of a buffer in the ps utility

Jon TURNEY
Fix the size of a temporary buffer used in the ps utility, reported as a
new warning by gcc-9.2.0

../../../../src/winsup/utils/ps.cc: In function 'const char* ttynam(int)':
../../../../src/winsup/utils/ps.cc:101:23: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
../../../../src/winsup/utils/ps.cc:101:11: note: 'sprintf' output between 9 and 10 bytes into a destination of size 9
---
 winsup/utils/ps.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc
index 2307f7955..63b92319e 100644
--- a/winsup/utils/ps.cc
+++ b/winsup/utils/ps.cc
@@ -90,7 +90,7 @@ to_time_t (FILETIME *ptr)
 static const char *
 ttynam (int ntty)
 {
-  static char buf[9];
+  static char buf[10];
   char buf0[9];
   if (ntty < 0)
     strcpy (buf0, "?");
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: Fix size of a buffer in the ps utility

Corinna Vinschen-2
On Feb 26 20:08, Jon Turney wrote:
> Fix the size of a temporary buffer used in the ps utility, reported as a
> new warning by gcc-9.2.0
>
> ../../../../src/winsup/utils/ps.cc: In function 'const char* ttynam(int)':
> ../../../../src/winsup/utils/ps.cc:101:23: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
> ../../../../src/winsup/utils/ps.cc:101:11: note: 'sprintf' output between 9 and 10 bytes into a destination of size 9
> ---
>  winsup/utils/ps.cc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

This is already fixed in git.


Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment