summaryrefslogtreecommitdiff
path: root/78/bc01f386b1bf01d816bcddd231581f37a59d4e
blob: f9947ff4d8b54637c4858f8472600fda3bc1b16a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194]
	helo=mx.sourceforge.net)
	by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76)
	(envelope-from <toshi@peernova.com>) id 1WqAGI-0006Cf-5o
	for bitcoin-development@lists.sourceforge.net;
	Fri, 30 May 2014 00:01:30 +0000
Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of peernova.com
	designates 209.85.220.182 as permitted sender)
	client-ip=209.85.220.182; envelope-from=toshi@peernova.com;
	helo=mail-vc0-f182.google.com; 
Received: from mail-vc0-f182.google.com ([209.85.220.182])
	by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128)
	(Exim 4.76) id 1WqAGH-0001JN-8e
	for bitcoin-development@lists.sourceforge.net;
	Fri, 30 May 2014 00:01:30 +0000
Received: by mail-vc0-f182.google.com with SMTP id id10so1252640vcb.41
	for <bitcoin-development@lists.sourceforge.net>;
	Thu, 29 May 2014 17:01:23 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=1e100.net; s=20130820;
	h=x-gm-message-state:mime-version:date:message-id:subject:from:to
	:content-type;
	bh=DwbA6vQZCXaXq/jOP/K9NHDmkTcz2Ja5wE/jHYUK8rc=;
	b=mWvQJt9jeX6Z0P+iXny08wlYCt8coqhs9XFw9bHyIfTH4pvWIcRNUGX8VdujOO9ycC
	+xdVVDMifGL5JaiOlmjW94f1IIlXiEVyH2YEIdpGe0Si3RscR7YycR8bif4K4RtEGoQs
	edfuAidFUtlFuJVWGVaP8n8hdljScILvFEhHCUkp89tiYWLEdEV5b/cDdFA/7RyBRO/h
	o3DZll3m3eJKm7N2Hm30fmchqtj3UUwucEUsaXMykkZiFenQi2J5G3F64WDYUh04qo/m
	ZzjZ8O6/ywm0NwEHj3vVvWie7dxhNrDEBS65m9+amjqRodzWHSS363XawrEkyWODYOfy
	akmQ==
X-Gm-Message-State: ALoCoQmP4Btud92OL3JQjEOWHywgCIOWyah17aFAUsF03tOhhZum/jiRn0xYX3F2JXJqRVkCbTKj
MIME-Version: 1.0
X-Received: by 10.52.255.98 with SMTP id ap2mr8565326vdd.3.1401408083425; Thu,
	29 May 2014 17:01:23 -0700 (PDT)
Received: by 10.52.34.146 with HTTP; Thu, 29 May 2014 17:01:23 -0700 (PDT)
Date: Thu, 29 May 2014 17:01:23 -0700
Message-ID: <CANFXpYMC2hYzFx5fPkqTv2LiCrtDny3yUV5u20ckK56zVjSpGA@mail.gmail.com>
From: Toshi Morita <toshi@peernova.com>
To: bitcoin-development@lists.sourceforge.net
Content-Type: multipart/alternative; boundary=047d7bd6c722ff8f3304fa92be9c
X-Spam-Score: -0.5 (/)
X-Spam-Report: Spam Filtering performed by mx.sourceforge.net.
	See http://spamassassin.org/tag/ for more details.
	-1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for
	sender-domain
	-0.0 SPF_PASS               SPF: sender matches SPF record
	1.0 HTML_MESSAGE           BODY: HTML included in message
X-Headers-End: 1WqAGH-0001JN-8e
Subject: [Bitcoin-development] bitcoind minor bug in wallet and possible fix
X-BeenThere: bitcoin-development@lists.sourceforge.net
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: <bitcoin-development.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/bitcoin-development>,
	<mailto:bitcoin-development-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum_name=bitcoin-development>
List-Post: <mailto:bitcoin-development@lists.sourceforge.net>
List-Help: <mailto:bitcoin-development-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/bitcoin-development>,
	<mailto:bitcoin-development-request@lists.sourceforge.net?subject=subscribe>
X-List-Received-Date: Fri, 30 May 2014 00:01:30 -0000

--047d7bd6c722ff8f3304fa92be9c
Content-Type: text/plain; charset=UTF-8

I ran bitcoind under valgrind and found a place where it references an
uninitialized variable in some cases:

tm@tm-VirtualBox:~/bitcoind/bitcoin/src$ valgrind ./bitcoind
==2337== Memcheck, a memory error detector
==2337== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==2337== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==2337== Command: ./bitcoind
==2337==
==2337== Conditional jump or move depends on uninitialised value(s)
==2337==    at 0x319176: CWallet::LoadKeyMetadata(CPubKey const&,
CKeyMetadata const&) (wallet.cpp:110)
==2337==    by 0x33645A: ReadKeyValue(CWallet*, CDataStream&, CDataStream&,
CWalletScanState&, std::string&, std::string&) (walletdb.cpp:509)
==2337==    by 0x3374F0: CWalletDB::LoadWallet(CWallet*) (walletdb.cpp:623)
==2337==    by 0x3218FD: CWallet::LoadWallet(bool&) (wallet.cpp:1485)
==2337==    by 0x157F16: AppInit2(boost::thread_group&) (init.cpp:958)
==2337==    by 0x140142: AppInit(int, char**) (bitcoind.cpp:143)
==2337==    by 0x13649E: main (bitcoind.cpp:180)
==2337==

The bug occurs here because nTimeFirstKey is not initialized when the
wallet is instantiated:

wallet.cpp:63
    if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
        nTimeFirstKey = nCreationTime;


I fixed it in my fork:

diff --git a/src/wallet.h b/src/wallet.h
index 9607415..b78045f 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -163,6 +163,7 @@ public:
         nOrderPosNext = 0;
         nNextResend = 0;
         nLastResend = 0;
+        nTimeFirstKey = 0;
     }

If this fix is ok please pull from my GitHub fork; username on GitHub is
tm314159.

Toshi

--047d7bd6c722ff8f3304fa92be9c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>I ran bitcoind under valgrind and found a place =
where it references an uninitialized variable in some cases:<br><br>tm@tm-V=
irtualBox:~/bitcoind/bitcoin/src$ valgrind ./bitcoind<br>=3D=3D2337=3D=3D M=
emcheck, a memory error detector<br>
=3D=3D2337=3D=3D Copyright (C) 2002-2012, and GNU GPL&#39;d, by Julian Sewa=
rd et al.<br>=3D=3D2337=3D=3D Using Valgrind-3.8.1 and LibVEX; rerun with -=
h for copyright info<br>=3D=3D2337=3D=3D Command: ./bitcoind<br>=3D=3D2337=
=3D=3D<br>=3D=3D2337=3D=3D Conditional jump or move depends on uninitialise=
d value(s)<br>
=3D=3D2337=3D=3D=C2=A0=C2=A0=C2=A0 at 0x319176: CWallet::LoadKeyMetadata(CP=
ubKey const&amp;, CKeyMetadata const&amp;) (wallet.cpp:110)<br>=3D=3D2337=
=3D=3D=C2=A0=C2=A0=C2=A0 by 0x33645A: ReadKeyValue(CWallet*, CDataStream&am=
p;, CDataStream&amp;, CWalletScanState&amp;, std::string&amp;, std::string&=
amp;) (walletdb.cpp:509)<br>
=3D=3D2337=3D=3D=C2=A0=C2=A0=C2=A0 by 0x3374F0: CWalletDB::LoadWallet(CWall=
et*) (walletdb.cpp:623)<br>=3D=3D2337=3D=3D=C2=A0=C2=A0=C2=A0 by 0x3218FD: =
CWallet::LoadWallet(bool&amp;) (wallet.cpp:1485)<br>=3D=3D2337=3D=3D=C2=A0=
=C2=A0=C2=A0 by 0x157F16: AppInit2(boost::thread_group&amp;) (init.cpp:958)=
<br>
=3D=3D2337=3D=3D=C2=A0=C2=A0=C2=A0 by 0x140142: AppInit(int, char**) (bitco=
ind.cpp:143)<br>=3D=3D2337=3D=3D=C2=A0=C2=A0=C2=A0 by 0x13649E: main (bitco=
ind.cpp:180)<br>=3D=3D2337=3D=3D<br><br></div>The bug occurs here because n=
TimeFirstKey is not initialized when the wallet is instantiated:<br>
<br>wallet.cpp:63<br>=C2=A0=C2=A0=C2=A0 if (!nTimeFirstKey || nCreationTime=
 &lt; nTimeFirstKey)<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nTimeFir=
stKey =3D nCreationTime;<br><br><br></div><div>I fixed it in my fork:<br><b=
r>diff --git a/src/wallet.h b/src/wallet.h<br>index 9607415..b78045f 100644=
<br>
--- a/src/wallet.h<br>+++ b/src/wallet.h<br>@@ -163,6 +163,7 @@ public:<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nOrderPosNext =3D 0;<br>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nNextResend =3D 0;<br>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nLastResend =3D 0;<br>+=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nTimeFirstKey =3D 0; <br>=C2=A0=C2=A0=
=C2=A0=C2=A0 }<br><br></div><div>
If this fix is ok please pull from my GitHub fork; username on GitHub is tm=
314159.<br><br>Toshi<br></div><div><br></div></div>

--047d7bd6c722ff8f3304fa92be9c--