Skip to content

Commit a5d63f9

Browse files
Xstouditargos
authored andcommitted
buffer: use size_t instead of uint32_t to avoid segmentation fault
Fixes: #46836 PR-URL: #48033 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent 75004d3 commit a5d63f9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/string_bytes.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,11 @@ size_t StringBytes::hex_encode(
627627
char* dst,
628628
size_t dlen) {
629629
// We know how much we'll write, just make sure that there's space.
630-
CHECK(dlen >= slen * 2 &&
631-
"not enough space provided for hex encode");
630+
CHECK(dlen >= MultiplyWithOverflowCheck<size_t>(slen, 2u) &&
631+
"not enough space provided for hex encode");
632632

633633
dlen = slen * 2;
634-
for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) {
634+
for (size_t i = 0, k = 0; k < dlen; i += 1, k += 2) {
635635
static const char hex[] = "0123456789abcdef";
636636
uint8_t val = static_cast<uint8_t>(src[i]);
637637
dst[k + 0] = hex[val >> 4];

0 commit comments

Comments
 (0)