Skip to content

Commit 158c284

Browse files
committed
rimage: fix inverted hash output buffer size check
The output-buffer guard was reversed: it rejected oversized buffers and accepted undersized ones, so a short output buffer could be overflowed by the digest write. Reject when the buffer is smaller than the digest. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 6b63cf4 commit 158c284

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

tools/rimage/src/hash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ int hash_single(const void *data, size_t size, const EVP_MD *algo, void *output,
174174
if (algo_out_size <= 0)
175175
return -EINVAL;
176176

177-
if (output_len > algo_out_size)
177+
/* EVP_Digest writes algo_out_size bytes into output, so the buffer
178+
* must be at least that large; reject an undersized output buffer
179+
*/
180+
if (output_len < (size_t)algo_out_size)
178181
return -ENOBUFS;
179182

180183
if (!EVP_Digest(data, size, output, NULL, algo, NULL)) {

0 commit comments

Comments
 (0)