games/micropolis: fix backwards memcpy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

games/micropolis: fix backwards memcpy

Theo Buehler
To reproduce, start micropolis, click "play this map" and click a few
times on different menus on the top left.  The backtrace:

#0  0x0000138f1af215ea in thrkill () at <stdin>:2
#1  0x0000138f1af27889 in *_libc_abort () at /usr/src/lib/libc/stdlib/abort.c:52
#2  0x0000138f1af816c8 in *_libc_memcpy (dst0=0x0, src0=0x6, length=0) at /usr/src/lib/libc/string/memcpy.c:65
#3  0x0000138c9a13c7f7 in Tk_UnshareEvents (tkwin=0x138f73fd2200, groupId=Variable "groupId" is not available.
) at tkshare.c:189
#4  0x0000138c9a14a9dd in MenuWidgetCmd (clientData=0x138f790e5b00, interp=0x138eeb7fdc00, argc=2, argv=0x7f7ffffda380)
    at tkmenu.c:821

Patch below makes the game playable again for me.

ok?

Index: Makefile
===================================================================
RCS file: /var/cvs/ports/games/micropolis/Makefile,v
retrieving revision 1.17
diff -u -p -r1.17 Makefile
--- Makefile 11 Mar 2013 11:07:39 -0000 1.17
+++ Makefile 18 Mar 2017 05:59:29 -0000
@@ -3,7 +3,7 @@
 COMMENT= city-building simulation
 
 DISTNAME= micropolis-20080211
-REVISION= 4
+REVISION= 5
 WRKDIST= ${WRKDIR}/micropolis
 
 CATEGORIES= games
Index: patches/patch-src_tk_tkshare_c
===================================================================
RCS file: patches/patch-src_tk_tkshare_c
diff -N patches/patch-src_tk_tkshare_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_tk_tkshare_c 18 Mar 2017 05:59:05 -0000
@@ -0,0 +1,14 @@
+$OpenBSD$
+
+fix backwards memcpy
+--- src/tk/tkshare.c.orig Sat Mar 18 06:51:20 2017
++++ src/tk/tkshare.c Sat Mar 18 06:51:40 2017
+@@ -186,7 +186,7 @@ Tk_UnshareEvents(tkwin, groupId)
+ continue;
+    }
+    if ((i+1) < groupPtr->numWindows) {
+- memcpy((VOID *) (groupPtr->windows + i),
++ memmove((VOID *) (groupPtr->windows + i),
+ (VOID *) (groupPtr->windows + i + 1),
+ (groupPtr->numWindows - (i+1))*sizeof(Tk_Window *));
+    }

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: games/micropolis: fix backwards memcpy

Theo de Raadt-2
Wonderful, it is still finding real bugs!

It's even obvious by inspection!

> To reproduce, start micropolis, click "play this map" and click a few
> times on different menus on the top left.  The backtrace:
>
> #0  0x0000138f1af215ea in thrkill () at <stdin>:2
> #1  0x0000138f1af27889 in *_libc_abort () at /usr/src/lib/libc/stdlib/abort.c:52
> #2  0x0000138f1af816c8 in *_libc_memcpy (dst0=0x0, src0=0x6, length=0) at /usr/src/lib/libc/string/memcpy.c:65
> #3  0x0000138c9a13c7f7 in Tk_UnshareEvents (tkwin=0x138f73fd2200, groupId=Variable "groupId" is not available.
> ) at tkshare.c:189
> #4  0x0000138c9a14a9dd in MenuWidgetCmd (clientData=0x138f790e5b00, interp=0x138eeb7fdc00, argc=2, argv=0x7f7ffffda380)
>     at tkmenu.c:821
>
> Patch below makes the game playable again for me.
>
> ok?
>
> Index: Makefile
> ===================================================================
> RCS file: /var/cvs/ports/games/micropolis/Makefile,v
> retrieving revision 1.17
> diff -u -p -r1.17 Makefile
> --- Makefile 11 Mar 2013 11:07:39 -0000 1.17
> +++ Makefile 18 Mar 2017 05:59:29 -0000
> @@ -3,7 +3,7 @@
>  COMMENT= city-building simulation
>  
>  DISTNAME= micropolis-20080211
> -REVISION= 4
> +REVISION= 5
>  WRKDIST= ${WRKDIR}/micropolis
>  
>  CATEGORIES= games
> Index: patches/patch-src_tk_tkshare_c
> ===================================================================
> RCS file: patches/patch-src_tk_tkshare_c
> diff -N patches/patch-src_tk_tkshare_c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_tk_tkshare_c 18 Mar 2017 05:59:05 -0000
> @@ -0,0 +1,14 @@
> +$OpenBSD$
> +
> +fix backwards memcpy
> +--- src/tk/tkshare.c.orig Sat Mar 18 06:51:20 2017
> ++++ src/tk/tkshare.c Sat Mar 18 06:51:40 2017
> +@@ -186,7 +186,7 @@ Tk_UnshareEvents(tkwin, groupId)
> + continue;
> +    }
> +    if ((i+1) < groupPtr->numWindows) {
> +- memcpy((VOID *) (groupPtr->windows + i),
> ++ memmove((VOID *) (groupPtr->windows + i),
> + (VOID *) (groupPtr->windows + i + 1),
> + (groupPtr->numWindows - (i+1))*sizeof(Tk_Window *));
> +    }
>

Loading...