Skip to content

Commit

Permalink
dialog: Fix a subtle bug in parsing dialog IDs from DB
Browse files Browse the repository at this point in the history
This fixes a rare issue where the dlg_parse_db_id() macro would
right-shift a signed "long long" value, potentially leading to
implementation or compiler defined behavior.

The fact that there is a binary diff after applying this patch proves
that there was an underlying, hard-to-detect issue in there:

-   4b192:	48 c1 f8 20          	sar    $0x20,%rax
+   4b192:	48 c1 e8 20          	shr    $0x20,%rax

Credits to Nick Altmann for providing some hints on this issue!
Related to #2504

(cherry picked from commit 103bdb4)
  • Loading branch information
liviuchircu committed Jun 22, 2021
1 parent 387bfe5 commit 43ac874
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/dialog/dlg_hash.h
Expand Up @@ -655,8 +655,8 @@ void state_changed_event_destroy(void);

#define dlg_parse_db_id(_did, _h_entry, _h_id) \
do { \
(_h_entry) = (unsigned int)((_did) >> 32); \
(_h_id) = (unsigned int)((_did) & 0x00000000ffffffff); \
(_h_entry) = (unsigned int)((unsigned long long)(_did) >> 32); \
(_h_id) = (unsigned int)((unsigned long long)(_did) & 0xFFFFFFFFULL); \
} while(0)

#endif

0 comments on commit 43ac874

Please sign in to comment.