0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd: Prevent nulls in the output buffer of u2a().

This commit is contained in:
Jason Volk 2018-08-11 00:32:58 -07:00
parent de2de7a5bf
commit 2d04d51cdc

View file

@ -448,7 +448,7 @@ ircd::replace(const string_view &s,
std::string
ircd::u2a(const const_buffer &in)
{
return string(size(in) * 2 + 1, [&in]
return string(size(in) * 2, [&in]
(const mutable_buffer &out)
{
return u2a(out, in);
@ -460,8 +460,13 @@ ircd::u2a(const mutable_buffer &out,
const const_buffer &in)
{
char *p(data(out));
for(size_t i(0); i < size(in); ++i, p += 2)
::snprintf(p, end(out) - p, "%02x", in[i]);
for(size_t i(0); i < size(in) && p + 2 <= end(out); ++i)
{
char tmp[3];
::snprintf(tmp, sizeof(tmp), "%02x", in[i]);
*p++ = tmp[0];
*p++ = tmp[1];
}
return { data(out), p };
}