mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
buffer: use size_t instead of uint32_t to avoid segmentation fault
Fixes: https://github.com/nodejs/node/issues/46836 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
04fbd0d73f
commit
05a941f3f2
1 file changed
+3
-3
+3
-3
@@ -627,11 +627,11 @@ size_t StringBytes::hex_encode(
|
||||
char* dst,
|
||||
size_t dlen) {
|
||||
// We know how much we'll write, just make sure that there's space.
|
||||
CHECK(dlen >= slen * 2 &&
|
||||
"not enough space provided for hex encode");
|
||||
CHECK(dlen >= MultiplyWithOverflowCheck<size_t>(slen, 2u) &&
|
||||
"not enough space provided for hex encode");
|
||||
|
||||
dlen = slen * 2;
|
||||
for (uint32_t i = 0, k = 0; k < dlen; i += 1, k += 2) {
|
||||
for (size_t i = 0, k = 0; k < dlen; i += 1, k += 2) {
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
uint8_t val = static_cast<uint8_t>(src[i]);
|
||||
dst[k + 0] = hex[val >> 4];
|
||||
|
||||
Reference in new issue
Block a user