9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] devdraw memory corruption
@ 2014-01-13 23:44 cinap_lenrek
  2014-01-13 23:54 ` cinap_lenrek
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: cinap_lenrek @ 2014-01-13 23:44 UTC (permalink / raw)
  To: 9fans

when user does read of exactly 12*12 bytes on draw
ctl file, the snprint() adds one more \0 byte writing
beyond the user buffer and corrupting memory.

fix this by not snprint()ing the final space and add
it manually:

--- /sys/src/9/port/devdraw.c	Wed Dec 25 13:55:16 2013 UTC
+++ /sys/src/9/port/devdraw.c	Mon Jan 13 23:22:13 2014 UTC
@@ -1187,10 +1187,11 @@
  				error(Enodrawimage);
  			i = di->image;
  		}
-		n =
sprint(a, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ",
+		n =
sprint(a, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d",
  			cl->clientid, cl->infoid, chantostr(buf, i->chan),
(i->flags&Frepl)==Frepl,
  			i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
  			i->clipr.min.x, i->clipr.min.y, i->clipr.max.x, i->clipr.max.y);
+		((char*)a)[n++] = ' ';
  		cl->infoid = -1;
  		break;

test program:

#include <u.h>
#include <libc.h>
#include <draw.h>

void
main(int argc, char *argv[])
{
	char buf[12*12+1];

	buf[12*12] = 'X';
	if(read(0, buf, 12*12) != 12*12)
		sysfatal("read: %r");
	if(buf[12*12] != 'X')
		sysfatal("corrupt");
}

term% ./8.out </dev/draw/new
corrupt

--
cinap



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] devdraw memory corruption
  2014-01-13 23:44 [9fans] devdraw memory corruption cinap_lenrek
@ 2014-01-13 23:54 ` cinap_lenrek
  2014-01-13 23:54 ` erik quanstrom
  2014-01-14  9:43 ` dexen deVries
  2 siblings, 0 replies; 4+ messages in thread
From: cinap_lenrek @ 2014-01-13 23:54 UTC (permalink / raw)
  To: 9fans

just saw, sources seems to have already fixed this
by using snprint()...

so never mind :)

--
cinap



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] devdraw memory corruption
  2014-01-13 23:44 [9fans] devdraw memory corruption cinap_lenrek
  2014-01-13 23:54 ` cinap_lenrek
@ 2014-01-13 23:54 ` erik quanstrom
  2014-01-14  9:43 ` dexen deVries
  2 siblings, 0 replies; 4+ messages in thread
From: erik quanstrom @ 2014-01-13 23:54 UTC (permalink / raw)
  To: 9fans

> +++ /sys/src/9/port/devdraw.c	Mon Jan 13 23:22:13 2014 UTC
> @@ -1187,10 +1187,11 @@
>   				error(Enodrawimage);
>   			i = di->image;
>   		}
> -		n =
> sprint(a, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d ",
> +		n =
> sprint(a, "%11d %11d %11s %11d %11d %11d %11d %11d %11d %11d %11d %11d",
>   			cl->clientid, cl->infoid, chantostr(buf, i->chan),
> (i->flags&Frepl)==Frepl,
>   			i->r.min.x, i->r.min.y, i->r.max.x, i->r.max.y,
>   			i->clipr.min.x, i->clipr.min.y, i->clipr.max.x, i->clipr.max.y);
> +		((char*)a)[n++] = ' ';
>   		cl->infoid = -1;
>   		break;

why not use a 145 byte buffer and readstr?

- erik



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] devdraw memory corruption
  2014-01-13 23:44 [9fans] devdraw memory corruption cinap_lenrek
  2014-01-13 23:54 ` cinap_lenrek
  2014-01-13 23:54 ` erik quanstrom
@ 2014-01-14  9:43 ` dexen deVries
  2 siblings, 0 replies; 4+ messages in thread
From: dexen deVries @ 2014-01-14  9:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

On Tuesday 14 of January 2014 00:44:47 cinap_lenrek@felloff.net wrote:
> when user does read of exactly 12*12 bytes on draw
> ctl file, the snprint() adds one more \0 byte writing
> beyond the user buffer and corrupting memory.

what symptoms were you getting?

i'm seeing rare, seemingly random glitches in plan9port Acme.

some windows get only partially re-drawn -- any combination of borders, 
background and text can be missing, as per attachment. the top right window 
should be showing file list, but only background was drawn.


i've ported this patch to p9p to see if the breakage stops.

-- 
dexen deVries

[[[↓][→]]]

[-- Attachment #2: borken-acme.png --]
[-- Type: image/png, Size: 28357 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-01-14  9:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-13 23:44 [9fans] devdraw memory corruption cinap_lenrek
2014-01-13 23:54 ` cinap_lenrek
2014-01-13 23:54 ` erik quanstrom
2014-01-14  9:43 ` dexen deVries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).