diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2014-10-15 11:54:05 +0200 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2014-11-01 15:51:41 +0000 |
commit | 6a3736873831f0fd766f5a482ae01f72a4a3dc49 (patch) | |
tree | e36f264d87496e0aa64a2fa1a6aada3d23fc4aaa /wsutil/sign_ext.h | |
parent | 54ae596ed9f6127952a480835f1d18d954aaf52e (diff) | |
download | wireshark-6a3736873831f0fd766f5a482ae01f72a4a3dc49.tar.gz |
Validate no_of_bits in ws_sign_ext32 and ws_sign_ext64
The result of the '<<' expression is undefined if no_of_bits - 1 is negative.
Change-Id: I3fff09afe414bdd9d6736ee351f1c542c503b93d
Reviewed-on: https://code.wireshark.org/review/4698
Reviewed-by: Evan Huus <eapache@gmail.com>
Petri-Dish: Evan Huus <eapache@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'wsutil/sign_ext.h')
-rw-r--r-- | wsutil/sign_ext.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/wsutil/sign_ext.h b/wsutil/sign_ext.h index 26d590a693..4371cacde6 100644 --- a/wsutil/sign_ext.h +++ b/wsutil/sign_ext.h @@ -30,6 +30,11 @@ static inline guint32 ws_sign_ext32(guint32 val, int no_of_bits) { + g_assert (no_of_bits >= 0 && no_of_bits <= 32); + + if (no_of_bits == 0) + return val; + if (val & (1 << (no_of_bits-1))) val |= (-1 << no_of_bits); @@ -39,6 +44,11 @@ ws_sign_ext32(guint32 val, int no_of_bits) static inline guint64 ws_sign_ext64(guint64 val, int no_of_bits) { + g_assert (no_of_bits >= 0 && no_of_bits <= 64); + + if (no_of_bits == 0) + return val; + if (val & (G_GINT64_CONSTANT(1) << (no_of_bits-1))) val |= (G_GINT64_CONSTANT(-1) << no_of_bits); |