Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security fixes, bugfixes, anti-pattern fixes and some performance fixes. #4

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
19 changes: 19 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version = 1

[[analyzers]]
name = "java"
enabled = true

[analyzers.meta]
runtime_version = "11"

[[analyzers]]
name = "shell"
enabled = true

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
11 changes: 7 additions & 4 deletions contrib/devtools/github-merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# name $BRANCH is overwritten with the merged result, and optionally pushed.
from __future__ import division,print_function,unicode_literals
import os
from sys import stdin,stdout,stderr
from sys import stdin,stdout,stderr,exit
import argparse
import hashlib
import subprocess
Expand Down Expand Up @@ -85,7 +85,8 @@ def tree_sha512sum(commit='HEAD'):
for line in subprocess.check_output([GIT, 'ls-tree', '--full-tree', '-r', commit]).splitlines():
name_sep = line.index(b'\t')
metadata = line[:name_sep].split() # perms, 'blob', blobid
assert(metadata[1] == b'blob')
if (metadata[1] != b'blob'):
raise AssertionError
name = line[name_sep+1:]
files.append(name)
blob_by_name[name] = metadata[2]
Expand All @@ -102,7 +103,8 @@ def tree_sha512sum(commit='HEAD'):
p.stdin.flush()
# read header: blob, "blob", size
reply = p.stdout.readline().split()
assert(reply[0] == blob and reply[1] == b'blob')
if not (reply[0] == blob and reply[1] == b'blob'):
raise AssertionError
size = int(reply[2])
# hash the blob data
intern = hashlib.sha512()
Expand All @@ -116,7 +118,8 @@ def tree_sha512sum(commit='HEAD'):
raise IOError('Premature EOF reading git cat-file output')
ptr += bs
dig = intern.hexdigest()
assert(p.stdout.read(1) == b'\n') # ignore LF that follows blob data
if (p.stdout.read(1) != b'\n'):
raise AssertionError
# update overall hash with file hash
overall.update(dig.encode("utf-8"))
overall.update(" ".encode("utf-8"))
Expand Down
3 changes: 2 additions & 1 deletion contrib/devtools/security-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def check_PE_HIGH_ENTROPY_VA(executable):
if arch == 'i386:x86-64':
reqbits = IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA
else: # Unnecessary on 32-bit
assert(arch == 'i386')
if (arch != 'i386'):
raise AssertionError
reqbits = 0
return (bits & reqbits) == reqbits

Expand Down
1 change: 0 additions & 1 deletion contrib/devtools/symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt')
# Allowed NEEDED libraries
ALLOWED_LIBRARIES = {
# bitcoind and bitcoin-qt
'libgcc_s.so.1', # GCC base support
'libc.so.6', # C library
'libpthread.so.0', # threading
Expand Down
6 changes: 3 additions & 3 deletions contrib/linearize/linearize-hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from __future__ import print_function
import json
import struct
import re
import base64
import httplib
Expand Down Expand Up @@ -68,8 +67,9 @@ def get_block_hashes(settings, max_blocks_per_call=10000):
for x,resp_obj in enumerate(reply):
if rpc.response_is_error(resp_obj):
print('JSON-RPC: error at height', height+x, ': ', resp_obj['error'], file=sys.stderr)
exit(1)
assert(resp_obj['id'] == x) # assume replies are in-sequence
sys.exit(1)
if (resp_obj['id'] != x):
raise AssertionError
print(resp_obj['result'])

height += num_blocks
Expand Down
8 changes: 5 additions & 3 deletions contrib/seeds/generate-seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def name_to_ipv6(addr):
if i == 0 or i == (len(addr)-1): # skip empty component at beginning or end
continue
x += 1 # :: skips to suffix
assert(x < 2)
if (x >= 2):
raise AssertionError
else: # two bytes per component
val = int(comp, 16)
sub[x].append(val >> 8)
sub[x].append(val & 0xff)
nullbytes = 16 - len(sub[0]) - len(sub[1])
assert((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0))
if not ((x == 0 and nullbytes == 0) or (x == 1 and nullbytes > 0)):
raise AssertionError
return bytearray(sub[0] + ([0] * nullbytes) + sub[1])
elif addr.startswith('0x'): # IPv4-in-little-endian
return pchIPv4 + bytearray(reversed(a2b_hex(addr[2:])))
Expand Down Expand Up @@ -114,7 +116,7 @@ def process_nodes(g, f, structname, defaultport):
def main():
if len(sys.argv)<2:
print(('Usage: %s <path_to_nodes_txt>' % sys.argv[0]), file=sys.stderr)
exit(1)
sys.exit(1)
g = sys.stdout
indir = sys.argv[1]
g.write('#ifndef BITCOIN_CHAINPARAMSSEEDS_H\n')
Expand Down
3 changes: 1 addition & 2 deletions contrib/spendfrom/spendfrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from decimal import *
import getpass
import math
import os
import os.path
import platform
Expand Down Expand Up @@ -253,7 +252,7 @@ def main():
else:
fee = Decimal(options.fee)
amount = Decimal(options.amount)
while unlock_wallet(unigridd) == False:
while unlock_wallet(unigridd) is False:
pass # Keep asking for passphrase until they get it right
txdata = create_tx(unigridd, options.fromaddresses.split(","), options.to, amount, fee)
sanity_test_fee(unigridd, txdata, amount*Decimal("0.01"))
Expand Down
9 changes: 6 additions & 3 deletions contrib/testgen/base58.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ def get_bcaddress_version(strAddress):

if __name__ == '__main__':
# Test case (from http://gitorious.org/bitcoin/python-base58.git)
assert get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is 0
if get_bcaddress_version('15VjRaDX9zpbA8LVnbrCAFzrVzN7ixHNsC') is not 0:
raise AssertionError
_ohai = 'o hai'.encode('ascii')
_tmp = b58encode(_ohai)
assert _tmp == 'DYB3oMS'
assert b58decode(_tmp, 5) == _ohai
if _tmp != 'DYB3oMS':
raise AssertionError
if b58decode(_tmp, 5) != _ohai:
raise AssertionError
print("Tests passed")
5 changes: 3 additions & 2 deletions contrib/testgen/gen_base58_test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Released under MIT License
import os
from itertools import islice
from base58 import b58encode, b58decode, b58encode_chk, b58decode_chk, b58chars
from base58 import b58encode_chk, b58decode_chk, b58chars
import random
from binascii import b2a_hex

Expand Down Expand Up @@ -59,7 +59,8 @@ def gen_valid_vectors():
payload = os.urandom(template[1])
suffix = str(bytearray(template[2]))
rv = b58encode_chk(prefix + payload + suffix)
assert is_valid(rv)
if not is_valid(rv):
raise AssertionError
metadata = dict([(x,y) for (x,y) in zip(metadata_keys,template[3]) if y is not None])
yield (rv, b2a_hex(payload), metadata)

Expand Down
1 change: 0 additions & 1 deletion contrib/zmq/zmq_sub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

import array
import binascii
import zmq
import struct
Expand Down
1 change: 0 additions & 1 deletion daemon/test/bctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

import subprocess
import os
import json
import sys

Expand Down