7
7
"fmt"
8
8
"io"
9
9
"os"
10
+ "path/filepath"
10
11
11
12
"github.com/btcsuite/btcd/btcutil"
12
13
"github.com/btcsuite/btcd/chaincfg"
@@ -119,6 +120,9 @@ func CreateTimestampTx(
119
120
}
120
121
fundingTxHash := fundingTx .TxHash ()
121
122
fundingInput := wire .NewTxIn (
123
+ //#nosec G115 - in theory this function can be called with bogus transactions
124
+ // with more than math.MaxUint32 outputs, but in practic caller would be shoting
125
+ // himself in the foot.
122
126
wire .NewOutPoint (& fundingTxHash , uint32 (fundingOutputIdx )),
123
127
nil ,
124
128
nil ,
@@ -151,7 +155,9 @@ func CreateTimestampTx(
151
155
}
152
156
153
157
func txOutTimestampFile (filePath string ) (txOut * wire.TxOut , fileHash []byte , err error ) {
154
- fileHash , err = hashFromFile (filePath )
158
+ fileHash , err = hashFromFile (
159
+ filepath .Clean (filePath ),
160
+ )
155
161
if err != nil {
156
162
return nil , nil , fmt .Errorf ("failed to generate hash from file %s: %w" , filePath , err )
157
163
}
@@ -167,7 +173,9 @@ func txOutTimestampFile(filePath string) (txOut *wire.TxOut, fileHash []byte, er
167
173
func hashFromFile (filePath string ) ([]byte , error ) {
168
174
h := sha256 .New ()
169
175
170
- f , err := os .Open (filePath )
176
+ f , err := os .Open (
177
+ filepath .Clean (filePath ),
178
+ )
171
179
if err != nil {
172
180
return nil , fmt .Errorf ("failed to open the file %s: %w" , filePath , err )
173
181
}
0 commit comments