Oops on invalid actor and victim arguments in nreport()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 30 Jan 2011 15:12:14 +0000 (16:12 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 13 Feb 2011 15:03:34 +0000 (16:03 +0100)
Replaces the existing, silent recovery from invalid victim argument.

src/lib/subs/nreport.c

index 91ee47832482fd6ca65e329b36f63025b2f3ea33..13216b88bf31dfb5a244590333d7577273ae8178 100644 (file)
@@ -59,12 +59,13 @@ void
 nreport(natid actor, int event, natid victim, int times)
 {
     int nice;
-    struct natstr *natp;
     struct newscache *ncp;
 
     if (CANT_HAPPEN((unsigned)event > N_MAX_VERB
                    || rpt[event].r_newstory[0] == rpt[0].r_newstory[0]))
        return;
+    if (CANT_HAPPEN(actor >= MAXNOC || victim >= MAXNOC))
+       return;
 
     ncp = ncache(actor, event, victim, times);
     putnews(ncp->id, &ncp->news);
@@ -83,9 +84,7 @@ nreport(natid actor, int event, natid victim, int times)
        return;
     if (!chance((double)-nice * times / 20.0))
        return;
-    if (!(natp = getnatp(victim)))
-       return;
-    if (getrel(natp, actor) < HOSTILE)
+    if (getrel(getnatp(victim), actor) < HOSTILE)
        return;
 
     setrel(victim, actor, HOSTILE);