[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-bugs] #22259 [Core Tor/Tor]: Stop ignoring hours when using months for bandwidth accounting



#22259: Stop ignoring hours when using months for bandwidth accounting
------------------------------+--------------------------------
     Reporter:  teor          |      Owner:
         Type:  defect        |     Status:  new
     Priority:  Medium        |  Milestone:  Tor: 0.3.1.x-final
    Component:  Core Tor/Tor  |    Version:
     Severity:  Normal        |   Keywords:
Actual Points:                |  Parent ID:
       Points:  0.5           |   Reviewer:
      Sponsor:                |
------------------------------+--------------------------------
 The current monthly accounting code ignores hours when checking the
 monthly accounting start date/time.

 The fix is:
 {{{
 -        (tm.tm_mday < cfg_start_day && before)) {
 +        (tm.tm_mday == cfg_start_day && before)) {
 }}}

 For bonus points, write a unit test that catches the error.

 The original bug report was:
 {{{
 I could note just one warning out of all of them, which indicates an
 error. Let's consider the following code fragment:

 static time_t
 edge_of_accounting_period_containing(time_t now, int get_end)
 {
   ....
   case UNIT_MONTH: {
     if (tm.tm_mday < cfg_start_day ||
         (tm.tm_mday < cfg_start_day && before)) {
       --tm.tm_mon;
     }
   ....
 }

 PVS-Studio warning: V686 A pattern was detected: (tm.tm_mday <
 cfg_start_day) || ((tm.tm_mday < cfg_start_day) && ...). The expression is
 excessive or contains a logical error. hibernate.c 333

 The check can be simplified to:

 if (tm.tm_mday < cfg_start_day) {

 Perhaps, there is a typo or a logical error in this condition.
 }}}

 Reported by Andrey Karpov
 https://www.viva64.com/en/b/0507/

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/22259>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs