XS: Ensure created Perl strings are nul-terminated
Most of these are binary strings and shouldn't be interpreted as C strings in the first place, but better be safe in case they are, anyway. The lack of nul-termination of FU::Pg `$hex` strings was more likely to be problematic.
This commit is contained in:
parent
7c765f33bb
commit
0925ae79a1
3 changed files with 5 additions and 0 deletions
|
|
@ -87,6 +87,7 @@ static SV *fugz_compress_ld(pTHX_ int level, const char *bytes, size_t inlen) {
|
|||
size_t len = libdeflate_gzip_compress(fugz_ld_ctx, bytes, inlen, SvPVX(out), outlen);
|
||||
if (!len) fu_confess("Libdeflate compression failed"); /* Shouldn't happen */
|
||||
SvCUR_set(out, len);
|
||||
SvPVX(out)[len] = 0;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -110,6 +111,7 @@ static SV *fugz_compress_zlib(pTHX_ int level, const char *bytes, size_t inlen)
|
|||
if ((r = deflate(&stream, 4)) != 1) fu_confess("Zlib compression failed (%d)", r);
|
||||
|
||||
SvCUR_set(out, stream.total_out);
|
||||
SvPVX(out)[stream.total_out] = 0;
|
||||
deflateEnd(&stream);
|
||||
return out;
|
||||
}
|
||||
|
|
@ -157,5 +159,6 @@ static SV *fubr_compress(pTHX_ IV level, SV *in) {
|
|||
if (!BrotliEncoderCompress(level, 22, BROTLI_MODE_GENERIC, inlen, bytes, &outlen, SvPVX(out)))
|
||||
fu_confess("Brotli compression failed");
|
||||
SvCUR_set(out, outlen);
|
||||
SvPVX(out)[outlen] = 0;
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ static int fufdpass_recv(pTHX_ I32 ax, int socket, size_t len) {
|
|||
}
|
||||
|
||||
SvCUR_set(buf, r);
|
||||
SvPVX(buf)[r] = 0;
|
||||
ST(1) = buf;
|
||||
return 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,6 +166,7 @@ RECVFN(hex) {
|
|||
*out++ = PL_hexdigit[(in[i] >> 4) & 0x0f];
|
||||
*out++ = PL_hexdigit[in[i] & 0x0f];
|
||||
}
|
||||
*out = 0;
|
||||
SvCUR_set(r, len * 2);
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue