From: Pierre Ossman Date: Wed, 4 Jan 2023 15:29:38 +0000 (+0100) Subject: Protect key variables from setjmp() X-Git-Tag: v1.13.90~97^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cdec36858eb0373fb2438f357411615c41de1125;p=tigervnc.git Protect key variables from setjmp() If we don't mark these as volatile then they might get reset on longjmp() and the code will misbehave. --- diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx index 24a62a86..efb26a77 100644 --- a/common/rfb/JpegCompressor.cxx +++ b/common/rfb/JpegCompressor.cxx @@ -155,15 +155,16 @@ JpegCompressor::~JpegCompressor(void) delete cinfo; } -void JpegCompressor::compress(const rdr::U8 *buf, int stride, const Rect& r, - const PixelFormat& pf, int quality, int subsamp) +void JpegCompressor::compress(const rdr::U8 *buf, volatile int stride, + const Rect& r, const PixelFormat& pf, + int quality, int subsamp) { int w = r.width(); int h = r.height(); int pixelsize; - rdr::U8 *srcBuf = NULL; - bool srcBufIsTemp = false; - JSAMPROW *rowPointer = NULL; + rdr::U8 * volatile srcBuf = NULL; + volatile bool srcBufIsTemp = false; + JSAMPROW * volatile rowPointer = NULL; if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx index b879ae32..ea148b94 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -150,16 +150,18 @@ JpegDecompressor::~JpegDecompressor(void) delete dinfo; } -void JpegDecompressor::decompress(const rdr::U8 *jpegBuf, int jpegBufLen, - rdr::U8 *buf, int stride, const Rect& r, const PixelFormat& pf) +void JpegDecompressor::decompress(const rdr::U8 *jpegBuf, + int jpegBufLen, rdr::U8 *buf, + volatile int stride, + const Rect& r, const PixelFormat& pf) { int w = r.width(); int h = r.height(); int pixelsize; int dstBufStride; - rdr::U8 *dstBuf = NULL; - bool dstBufIsTemp = false; - JSAMPROW *rowPointer = NULL; + rdr::U8 * volatile dstBuf = NULL; + volatile bool dstBufIsTemp = false; + JSAMPROW * volatile rowPointer = NULL; if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error