Coverity fix for games/monopoly

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

Coverity fix for games/monopoly

Jasper Lievisse Adriaanse
----------------------------8<----------------------------
Coverity CID 1005
Index: misc.c
===================================================================
RCS file: /cvs/src/games/monop/misc.c,v
retrieving revision 1.8
diff -u -r1.8 misc.c
--- misc.c 16 Dec 2003 19:26:44 -0000 1.8
+++ misc.c 22 Mar 2006 15:53:04 -0000
@@ -209,13 +209,17 @@
  printf("player # %d\n", pl+1);
  printhold(pl);
  printf("orig_op = %p\n", orig_op);
- printf("orig_op->sqr->type = %d (PRPTY)\n", op->sqr->type);
- printf("orig_op->next = %p\n", op->next);
- printf("orig_op->sqr->desc = %p\n", op->sqr->desc);
+ if (orig_op) {
+ printf("orig_op->sqr->type = %d (PRPTY)\n", orig_op->sqr->type);
+ printf("orig_op->next = %p\n", op->next);
+ printf("orig_op->sqr->desc = %p\n", orig_op->sqr->desc);
+ }
  printf("op = %p\n", op);
- printf("op->sqr->type = %d (PRPTY)\n", op->sqr->type);
- printf("op->next = %p\n", op->next);
- printf("op->sqr->desc = %p\n", op->sqr->desc);
+ if (op) {
+ printf("op->sqr->type = %d (PRPTY)\n", op->sqr->type);
+ printf("op->next = %p\n", op->next);
+ printf("op->sqr->desc = %p\n", op->sqr->desc);
+ }
  printf("num = %d\n", num);
  }
 #ifdef DEBUG
----------------------------8<----------------------------

Cheers,
Jasper

--
Humppa is a serious thing!

[demime 1.01d removed an attachment of type application/pgp-signature]

Reply | Threaded
Open this post in threaded view
|

Re: Coverity fix for games/monopoly

Jeff Quast
speaking of monop, I was able to do a transfer of money/trade with a
negative number, which rolled an integer or similar in such a fashion
that it resulted in something like this:

That puts you on Oriental Ave. (L) Owned by dingo
with -21 houses, rent is 1006647888
That leaves you $1006647673 in debt
How are you going to fix it up?
(..)

I thought about fixing this and submitting a patch, but after some
consideration, I assumed the games/* were there for nostalgia, bugs
and all. Am I wrong?

btw, my girlfriend will only play the cardboard game since :)

On 3/22/06, Jasper Lievisse Adriaanse <[hidden email]> wrote:

> RCS file: /cvs/src/games/monop/misc.c,v

Reply | Threaded
Open this post in threaded view
|

Re: Coverity fix for games/monopoly

Jeff Quast
For this one in particular,

--- src/games/monop/houses.c.orig       Sat Mar 25 20:49:07 2006
+++ src/games/monop/houses.c    Sat Mar 25 23:42:30 2006
@@ -152,7 +152,7 @@
                        mp->sq[i]->name, pp->houses);
                input[i] = get_int(cur_prop);
                temp[i] = input[i] + pp->houses;
-               if (temp[i] > 5) {
+               if (temp[i] > 5 || temp[i] < 0) {
                        printf("That's too many.  The most you can buy is %d\n",
                                5 - pp->houses);
                                goto over;

Its trivial, I know.

player 1 (1) (cash $911) on St. James Pl. (O)
-- Command: buy houses
Pacific Ave. (G) (0) N. Carolina Ave. (G) (0) Pennsylvania Ave. (G) (0)
Houses will cost $200
How many houses do you wish to buy for
Pacific Ave. (G) (0): 99999
N. Carolina Ave. (G) (0): 99999
Pennsylvania Ave. (G) (0): 99999
You asked for -291 houses and 0 hotels for $-58200
Is that ok? yes

player 1 (1) (cash $59111) on St. James Pl. (O)

and after patch:

player 1 (1) (cash $445) on B&O RR
-- Command: buy houses
Park Place (D) (0) Boardwalk (D) (0)
Houses will cost $200
How many houses do you wish to buy for
Park Place (D) (0): 9999
That's too many.  The most you can buy is 5

I might be the only person out there who still plays these oldies but
goodies, but I'll work on a patch to overhaul the archaic and unsafe
methods used in games/ without changing game behavior, time
permitting.

On 3/25/06, Theo de Raadt <[hidden email]> wrote:

> We still want them fixed...
>
> >
> > That puts you on Oriental Ave. (L) Owned by dingo
> > with -21 houses, rent is 1006647888
> > That leaves you $1006647673 in debt
> > How are you going to fix it up?
> > (..)
> >
> > I thought about fixing this and submitting a patch, but after some
> > consideration, I assumed the games/* were there for nostalgia, bugs
> > and all. Am I wrong?

Reply | Threaded
Open this post in threaded view
|

Re: Coverity fix for games/monopoly

Jasper Lievisse Adriaanse
Op 26/3/2006 schreef "Jeff Quast" <[hidden email]>:

>For this one in particular,
>
>--- src/games/monop/houses.c.orig       Sat Mar 25 20:49:07 2006
>+++ src/games/monop/houses.c    Sat Mar 25 23:42:30 2006
>@@ -152,7 +152,7 @@
>                        mp->sq[i]->name, pp->houses);
>                input[i] = get_int(cur_prop);
>                temp[i] = input[i] + pp->houses;
>-               if (temp[i] > 5) {
>+               if (temp[i] > 5 || temp[i] < 0) {
>                        printf("That's too many.  The most you can buy is %d\n",
>                                5 - pp->houses);
>                                goto over;
>
>Its trivial, I know.
>
>player 1 (1) (cash $911) on St. James Pl. (O)
>-- Command: buy houses
>Pacific Ave. (G) (0) N. Carolina Ave. (G) (0) Pennsylvania Ave. (G) (0)
>Houses will cost $200
>How many houses do you wish to buy for
>Pacific Ave. (G) (0): 99999
>N. Carolina Ave. (G) (0): 99999
>Pennsylvania Ave. (G) (0): 99999
>You asked for -291 houses and 0 hotels for $-58200
>Is that ok? yes
>
>player 1 (1) (cash $59111) on St. James Pl. (O)
>
>and after patch:
>
>player 1 (1) (cash $445) on B&O RR
>-- Command: buy houses
>Park Place (D) (0) Boardwalk (D) (0)
>Houses will cost $200
>How many houses do you wish to buy for
>Park Place (D) (0): 9999
>That's too many.  The most you can buy is 5
>
>I might be the only person out there who still plays these oldies but
>goodies, but I'll work on a patch to overhaul the archaic and unsafe
>methods used in games/ without changing game behavior, time
>permitting.
I have some diffs here for clean -Wall, for games/*. There not yet
finished,b ut I'm still working on it.

>
>On 3/25/06, Theo de Raadt <[hidden email]> wrote:
>> We still want them fixed...
>>
>> >
>> > That puts you on Oriental Ave. (L) Owned by dingo
>> > with -21 houses, rent is 1006647888
>> > That leaves you $1006647673 in debt
>> > How are you going to fix it up?
>> > (..)
>> >
>> > I thought about fixing this and submitting a patch, but after some
>> > consideration, I assumed the games/* were there for nostalgia, bugs
>> > and all. Am I wrong?