signed/unsigned bug in StatBag leads to wrap-around issues with counters #327

Closed
Habbie opened this Issue Apr 26, 2013 · 2 comments

Projects

None yet

1 participant

@Habbie
Member
Habbie commented Apr 26, 2013

Just ran into an issue with our graphing of the query-cache:

/usr/bin/pdns_control show '*'

corrupt-packets=59131310,deferred-cache-inserts=44998069,deferred-cache-lookup=24040315,latency=0,packetcache-hit=725969193,packetcache-miss=1347724754,packetcache-size=136632,qsize-q=1,query-cache-hit=2209510287,query-cache-miss=2196442457,recursing-answers=0,recursing-questions=0,servfail-packets=80,tcp-answers=126456,tcp-queries=444324,timedout-packets=0,udp-answers=2082640507,udp-queries=2098925279,udp4-answers=2082640475,udp4-queries=2082641650,udp6-answers=0,udp6-queries=0,

/usr/bin/pdns_control show query-cache-hit

-2084941632

Looking at the code, the SHOW * command works because you just deref the pointer which is defined as an unsigned int. However the SHOW code doesn't work because it uses StatBag::read() which is defined as returning a signed int. I believe the attached patch will fix the issues but there may still be some other places in the StatBag code where it would be better to explicitly specify unsigned int.

Perhaps in the future the counter should be given with a typedef to prevent this from occuring again and specified as a long to ensure that we can get the full 64 bits on a 64-bit arch? (I believe an int on x86_64 arch is still only 32 bit)

Mark

@Habbie Habbie was assigned Apr 26, 2013
@Habbie Habbie closed this Apr 26, 2013
@Habbie
Member
Habbie commented Apr 26, 2013

Attachment '' (pdns-fix-unsigned-signed-issues.patch) https://gist.github.com/5466695

@Habbie
Member
Habbie commented Apr 26, 2013

Author: ahu
Fixed slightly differently in commit 2019, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment