From: Florian Evers <florian-evers@gmx.de>
To: linux-gpio@vger.kernel.org
Subject: [libgpiod] Integer overflow in C++ binding on 32bit systems causes wrong event timestamps
Date: Sun, 06 Sep 2020 18:52:21 +0200 [thread overview]
Message-ID: <2572959.mvXUDI8C0e@waterstation> (raw)
[-- Attachment #1: Type: text/plain, Size: 842 bytes --]
Hello,
I found a bug in the c++ bindings of libgpiod that affects 32bit systems.
Observation:
Only the c++ bindings lib is affected. For input events, the time stamp
delivered in the event object is wrong. Instead of providing a complete
"system time", it delivers time stamps of of a range "-2.1"...+2.1 seconds
(which relates to the time stamp range of a signed 32bit value, in
nanoseconds).
Cause:
The bug is in line 219 of file "/tree/bindings/cxx/line.cpp":
event.ts.tv_nsec + (event.ts.tv_sec * 1000000000));
"event.ts.tv_sec" is of type signed long, which is 32 bit on my device. Thus,
that multiplication to convert total seconds of a system time to nanoseconds
causes an overflow.
Fix:
There should be a cast to uint64_t before the multiplication.
Thank you for fixing this!
Regards,
Florian
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2020-09-06 16:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-06 16:52 Florian Evers [this message]
2020-09-09 8:05 ` [libgpiod] Integer overflow in C++ binding on 32bit systems causes wrong event timestamps Bartosz Golaszewski
2020-09-11 10:52 ` Florian Evers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2572959.mvXUDI8C0e@waterstation \
--to=florian-evers@gmx.de \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox