Menu

#2737 Possible underflow (?) in battle criticals

open
nobody
None
2020-05-23
2020-05-23
Anonymous
No

Originally created by: pazkero

Describe the bug
In battle.c:4654 critical is defined as

        short cri = sstatus->cri;

A few lines later, the following problematic calculation is done:

#ifndef RENEWAL
        //The official equation is *2, but that only applies when sd's do critical.
        //Therefore, we use the old value 3 on cases when an sd gets attacked by a mob
        cri -= tstatus->luk*(!sd&&tsd?3:2);
#else
        cri -= status->get_lv(target) / 15 + 2 * status_get_luk(target);
#endif

Both are using "luck" stat, which is an uint16. See status.h:1059, when struct status_data is declared:

    uint16 str, agi, vit, int_, dex, luk;

This means that critical can underflow (?) here.
Because luck can go up to 65535, a monster could (in both modes) have at least 131070 crit def.
So the critical must accept at least -131070 (an int32 should do the trick)

To Reproduce

  1. Set an arbitrary monster luck to 65535 (it will be accepted - no errors)
  2. Fight with the monster.

Expected behavior
Modified monster should not receive crits, instead of always receiving crits.

System specs (please complete the following information):

  • OS: Linux 4.15.0-45-generic [#48]-Ubuntu
  • Hercules Version: stable
  • Mode: both
  • Packet version: any
  • Client type: any

Plugins used or source modifications
Evol Plugin (does not interfere)

Discussion


Log in to post a comment.

MongoDB Logo MongoDB