elements/src/script
fanquake 68ef9523d1
Merge #18413: script: prevent UB when computing abs value for num opcode serialize
2748e87932 script: prevent UB when computing abs value for num opcode serialize (pierrenn)

Pull request description:

  This was reported by practicalswift here #18046

  It seems that the original author of the line used a reference to glibc `abs`: https://github.com/lattera/glibc/blob/master/stdlib/abs.c

  However depending on some implementation details this can be undefined behavior for unusual values.

  A detailed explanation of the UB is provided here : https://stackoverflow.com/questions/17313579/is-there-a-safe-way-to-get-the-unsigned-absolute-value-of-a-signed-integer-with (by [Billy O'Neal](https://twitter.com/malwareminigun))

  Simple relevant godbolt example :  https://godbolt.org/z/yRwtCG

  Thanks!

ACKs for top commit:
  sipa:
    ACK 2748e87932
  MarcoFalke:
    ACK 2748e87932, only checked that the bitcoind binary does not change with clang -O2 🎓
  practicalswift:
    ACK 2748e87932

Tree-SHA512: 539a34c636c2674c66cb6e707d9d0dfdce63f59b5525610ed88da10c9a8d59d81466b111ad63b850660cef3750d732fc7755530c81a2d61f396be0707cd86dec
2020-05-02 21:24:05 +08:00
..
bitcoinconsensus.cpp Drop unused GetType() from CSizeComputer 2018-09-11 00:58:05 -04:00
bitcoinconsensus.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
descriptor.cpp Add IsSingleType to Descriptors 2020-04-23 13:59:48 -04:00
descriptor.h Add IsSingleType to Descriptors 2020-04-23 13:59:48 -04:00
interpreter.cpp scripted-diff: Bump copyright headers 2020-04-16 13:33:09 -04:00
interpreter.h [REFACTOR] Initialize PrecomputedTransactionData in CheckInputScripts 2020-04-11 21:32:45 -04:00
keyorigin.h Remove unused includes 2019-10-15 22:56:43 +00:00
script.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
script.h Merge #18413: script: prevent UB when computing abs value for num opcode serialize 2020-05-02 21:24:05 +08:00
script_error.cpp scripted-diff: Bump copyright headers 2020-04-16 13:33:09 -04:00
script_error.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
sigcache.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
sigcache.h Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
sign.cpp scripted-diff: Bump copyright headers 2020-04-16 13:33:09 -04:00
sign.h scripted-diff: Bump copyright headers 2020-04-16 13:33:09 -04:00
signingprovider.cpp Move WatchOnly stuff from SigningProvider to CWallet 2019-07-09 16:20:18 -04:00
signingprovider.h wallet: Improve LegacyScriptPubKeyMan::CanProvide script recognition 2020-02-12 11:48:30 -05:00
standard.cpp scripted-diff: Bump copyright of files changed in 2019 2019-12-30 10:42:20 +13:00
standard.h Merge #17924: Bug: IsUsedDestination shouldn't use key id as script id for ScriptHash 2020-01-16 19:23:33 +01:00