On Tue, Feb 14, 2017 at 03:50:05PM +0100, Federico Consoli wrote:
> Hi,
> I have a doubt about  openbsd/usr.sbin/lpr/lpr/lpr.c function "static char
> * itoa(int i)", I see that it can cause a problem for i>(999999999+1).
> I don't test the code, I made only a code analysis.
> 
> Regards
> 
> Eng. Consoli Federico

Hi,

I think you're correct. Below is a patch, with changed behaviour:


diff --git a/usr.sbin/lpr/lpr/lpr.c b/usr.sbin/lpr/lpr/lpr.c
index 1bb9eb2f95a..b04082a61fe 100644
--- a/usr.sbin/lpr/lpr/lpr.c
+++ b/usr.sbin/lpr/lpr/lpr.c
@@ -615,15 +615,11 @@ bad:
 static char *
 itoa(int i)
 {
-       static char b[10] = "########";
-       char *p;
-
-       p = &b[8];
-       do
-               *p-- = i%10 + '0';
-       while (i /= 10)
-               ;
-       return(++p);
+       static char b[12];
+
+       snprintf(b, sizeof(b), "%d", i);
+
+       return b;
 }
 
 /*


-- 
Kind regards,
Hiltjo

Reply via email to