diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-09 19:01:35 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-02-01 21:17:12 +0100 |
commit | d98720b736eb908d63c1ecb3779fc2a3cd9f4914 (patch) | |
tree | 4d548eba62bcabe0892054d547b157ba1178249f /common | |
parent | 6881c895ab317bd302addac5f228b7367136017f (diff) | |
download | tigervnc-d98720b736eb908d63c1ecb3779fc2a3cd9f4914.tar.gz tigervnc-d98720b736eb908d63c1ecb3779fc2a3cd9f4914.zip |
Use std::vector for basic data arrays
Avoid our own custom types in favour of what's already included with
C++.
Diffstat (limited to 'common')
-rw-r--r-- | common/rdr/types.h | 71 | ||||
-rw-r--r-- | common/rfb/CMsgReader.cxx | 71 | ||||
-rw-r--r-- | common/rfb/CSecurityDH.cxx | 31 | ||||
-rw-r--r-- | common/rfb/CSecurityMSLogonII.cxx | 7 | ||||
-rw-r--r-- | common/rfb/Cursor.cxx | 40 | ||||
-rw-r--r-- | common/rfb/Cursor.h | 8 | ||||
-rw-r--r-- | common/rfb/SMsgReader.cxx | 11 | ||||
-rw-r--r-- | common/rfb/SMsgWriter.cxx | 17 | ||||
-rw-r--r-- | common/rfb/SSecurityRSAAES.cxx | 36 | ||||
-rw-r--r-- | common/rfb/TightDecoder.cxx | 9 |
10 files changed, 119 insertions, 182 deletions
diff --git a/common/rdr/types.h b/common/rdr/types.h deleted file mode 100644 index 1a53edf7..00000000 --- a/common/rdr/types.h +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ - -#ifndef __RDR_TYPES_H__ -#define __RDR_TYPES_H__ - -#include <stdint.h> - -namespace rdr { - - class U8Array { - public: - U8Array() : buf(0) {} - U8Array(uint8_t* a) : buf(a) {} // note: assumes ownership - U8Array(int len) : buf(new uint8_t[len]) {} - ~U8Array() { delete [] buf; } - - // Get the buffer pointer & clear it (i.e. caller takes ownership) - uint8_t* takeBuf() { uint8_t* tmp = buf; buf = 0; return tmp; } - - uint8_t* buf; - }; - - class U16Array { - public: - U16Array() : buf(0) {} - U16Array(uint16_t* a) : buf(a) {} // note: assumes ownership - U16Array(int len) : buf(new uint16_t[len]) {} - ~U16Array() { delete [] buf; } - uint16_t* takeBuf() { uint16_t* tmp = buf; buf = 0; return tmp; } - uint16_t* buf; - }; - - class U32Array { - public: - U32Array() : buf(0) {} - U32Array(uint32_t* a) : buf(a) {} // note: assumes ownership - U32Array(int len) : buf(new uint32_t[len]) {} - ~U32Array() { delete [] buf; } - uint32_t* takeBuf() { uint32_t* tmp = buf; buf = 0; return tmp; } - uint32_t* buf; - }; - - class S32Array { - public: - S32Array() : buf(0) {} - S32Array(int32_t* a) : buf(a) {} // note: assumes ownership - S32Array(int len) : buf(new int32_t[len]) {} - ~S32Array() { delete [] buf; } - int32_t* takeBuf() { int32_t* tmp = buf; buf = 0; return tmp; } - int32_t* buf; - }; - -} // end of namespace rdr - -#endif diff --git a/common/rfb/CMsgReader.cxx b/common/rfb/CMsgReader.cxx index ad063627..ba0380fc 100644 --- a/common/rfb/CMsgReader.cxx +++ b/common/rfb/CMsgReader.cxx @@ -24,9 +24,10 @@ #include <assert.h> #include <stdio.h> +#include <vector> + #include <rdr/InStream.h> #include <rdr/ZlibInStream.h> -#include <rdr/types.h> #include <rfb/msgTypes.h> #include <rfb/clipboardTypes.h> @@ -229,10 +230,10 @@ bool CMsgReader::readSetColourMapEntries() return false; is->clearRestorePoint(); - rdr::U16Array rgbs(nColours * 3); - for (int i = 0; i < nColours * 3; i++) - rgbs.buf[i] = is->readU16(); - handler->setColourMapEntries(firstColour, nColours, rgbs.buf); + std::vector<uint16_t> rgbs(nColours * 3); + for (size_t i = 0; i < rgbs.size(); i++) + rgbs[i] = is->readU16(); + handler->setColourMapEntries(firstColour, nColours, rgbs.data()); return true; } @@ -477,15 +478,15 @@ bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) if (width > maxCursorSize || height > maxCursorSize) throw Exception("Too big cursor"); - rdr::U8Array rgba(width*height*4); + std::vector<uint8_t> rgba(width*height*4); if (width * height > 0) { uint8_t pr, pg, pb; uint8_t sr, sg, sb; int data_len = ((width+7)/8) * height; int mask_len = ((width+7)/8) * height; - rdr::U8Array data(data_len); - rdr::U8Array mask(mask_len); + std::vector<uint8_t> data(data_len); + std::vector<uint8_t> mask(mask_len); int x, y; uint8_t* out; @@ -501,17 +502,17 @@ bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) sg = is->readU8(); sb = is->readU8(); - is->readBytes(data.buf, data_len); - is->readBytes(mask.buf, mask_len); + is->readBytes(data.data(), data.size()); + is->readBytes(mask.data(), mask.size()); int maskBytesPerRow = (width+7)/8; - out = rgba.buf; + out = rgba.data(); for (y = 0;y < height;y++) { for (x = 0;x < width;x++) { int byte = y * maskBytesPerRow + x / 8; int bit = 7 - x % 8; - if (data.buf[byte] & (1 << bit)) { + if (data[byte] & (1 << bit)) { out[0] = pr; out[1] = pg; out[2] = pb; @@ -521,7 +522,7 @@ bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) out[2] = sb; } - if (mask.buf[byte] & (1 << bit)) + if (mask[byte] & (1 << bit)) out[3] = 255; else out[3] = 0; @@ -531,7 +532,7 @@ bool CMsgReader::readSetXCursor(int width, int height, const Point& hotspot) } } - handler->setCursor(width, height, hotspot, rgba.buf); + handler->setCursor(width, height, hotspot, rgba.data()); return true; } @@ -543,23 +544,23 @@ bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot) int data_len = width * height * (handler->server.pf().bpp/8); int mask_len = ((width+7)/8) * height; - rdr::U8Array data(data_len); - rdr::U8Array mask(mask_len); + std::vector<uint8_t> data(data_len); + std::vector<uint8_t> mask(mask_len); int x, y; - rdr::U8Array rgba(width*height*4); + std::vector<uint8_t> rgba(width*height*4); uint8_t* in; uint8_t* out; if (!is->hasData(data_len + mask_len)) return false; - is->readBytes(data.buf, data_len); - is->readBytes(mask.buf, mask_len); + is->readBytes(data.data(), data.size()); + is->readBytes(mask.data(), mask.size()); int maskBytesPerRow = (width+7)/8; - in = data.buf; - out = rgba.buf; + in = data.data(); + out = rgba.data(); for (y = 0;y < height;y++) { for (x = 0;x < width;x++) { int byte = y * maskBytesPerRow + x / 8; @@ -567,7 +568,7 @@ bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot) handler->server.pf().rgbFromBuffer(out, in, 1); - if (mask.buf[byte] & (1 << bit)) + if (mask[byte] & (1 << bit)) out[3] = 255; else out[3] = 0; @@ -577,7 +578,7 @@ bool CMsgReader::readSetCursor(int width, int height, const Point& hotspot) } } - handler->setCursor(width, height, hotspot, rgba.buf); + handler->setCursor(width, height, hotspot, rgba.data()); return true; } @@ -660,10 +661,10 @@ bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot if (type == 0) { int len = width * height * (handler->server.pf().bpp/8); - rdr::U8Array andMask(len); - rdr::U8Array xorMask(len); + std::vector<uint8_t> andMask(len); + std::vector<uint8_t> xorMask(len); - rdr::U8Array data(width*height*4); + std::vector<uint8_t> data(width*height*4); uint8_t* andIn; uint8_t* xorIn; @@ -674,12 +675,12 @@ bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot return false; is->clearRestorePoint(); - is->readBytes(andMask.buf, len); - is->readBytes(xorMask.buf, len); + is->readBytes(andMask.data(), andMask.size()); + is->readBytes(xorMask.data(), xorMask.size()); - andIn = andMask.buf; - xorIn = xorMask.buf; - out = data.buf; + andIn = andMask.data(); + xorIn = xorMask.data(); + out = data.data(); Bpp = handler->server.pf().bpp/8; for (int y = 0;y < height;y++) { for (int x = 0;x < width;x++) { @@ -727,18 +728,18 @@ bool CMsgReader::readSetVMwareCursor(int width, int height, const Point& hotspot } } - handler->setCursor(width, height, hotspot, data.buf); + handler->setCursor(width, height, hotspot, data.data()); } else if (type == 1) { - rdr::U8Array data(width*height*4); + std::vector<uint8_t> data(width*height*4); if (!is->hasDataOrRestore(width*height*4)) return false; is->clearRestorePoint(); // FIXME: Is alpha premultiplied? - is->readBytes(data.buf, width*height*4); + is->readBytes(data.data(), data.size()); - handler->setCursor(width, height, hotspot, data.buf); + handler->setCursor(width, height, hotspot, data.data()); } else { throw Exception("Unknown cursor type"); } diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx index c9b2a2cf..aab25671 100644 --- a/common/rfb/CSecurityDH.cxx +++ b/common/rfb/CSecurityDH.cxx @@ -39,7 +39,6 @@ #include <rdr/InStream.h> #include <rdr/OutStream.h> #include <rdr/RandomStream.h> -#include <rdr/types.h> #include <rfb/Exception.h> #include <os/os.h> @@ -94,12 +93,12 @@ bool CSecurityDH::readKey() return false; is->clearRestorePoint(); mpz_set_ui(g, gen); - rdr::U8Array pBytes(keyLength); - rdr::U8Array ABytes(keyLength); - is->readBytes(pBytes.buf, keyLength); - is->readBytes(ABytes.buf, keyLength); - nettle_mpz_set_str_256_u(p, keyLength, pBytes.buf); - nettle_mpz_set_str_256_u(A, keyLength, ABytes.buf); + std::vector<uint8_t> pBytes(keyLength); + std::vector<uint8_t> ABytes(keyLength); + is->readBytes(pBytes.data(), pBytes.size()); + is->readBytes(ABytes.data(), ABytes.size()); + nettle_mpz_set_str_256_u(p, pBytes.size(), pBytes.data()); + nettle_mpz_set_str_256_u(A, ABytes.size(), ABytes.data()); return true; } @@ -110,22 +109,22 @@ void CSecurityDH::writeCredentials() rdr::RandomStream rs; (CSecurity::upg)->getUserPasswd(isSecure(), &username.buf, &password.buf); - rdr::U8Array bBytes(keyLength); + std::vector<uint8_t> bBytes(keyLength); if (!rs.hasData(keyLength)) throw ConnFailedException("failed to generate DH private key"); - rs.readBytes(bBytes.buf, keyLength); - nettle_mpz_set_str_256_u(b, keyLength, bBytes.buf); + rs.readBytes(bBytes.data(), bBytes.size()); + nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); mpz_powm(B, g, b, p); - rdr::U8Array sharedSecret(keyLength); - rdr::U8Array BBytes(keyLength); - nettle_mpz_get_str_256(keyLength, sharedSecret.buf, k); - nettle_mpz_get_str_256(keyLength, BBytes.buf, B); + std::vector<uint8_t> sharedSecret(keyLength); + std::vector<uint8_t> BBytes(keyLength); + nettle_mpz_get_str_256(sharedSecret.size(), sharedSecret.data(), k); + nettle_mpz_get_str_256(BBytes.size(), BBytes.data(), B); uint8_t key[16]; struct md5_ctx md5Ctx; md5_init(&md5Ctx); - md5_update(&md5Ctx, keyLength, sharedSecret.buf); + md5_update(&md5Ctx, sharedSecret.size(), sharedSecret.data()); md5_digest(&md5Ctx, 16, key); struct aes128_ctx aesCtx; aes128_set_encrypt_key(&aesCtx, key); @@ -146,6 +145,6 @@ void CSecurityDH::writeCredentials() rdr::OutStream* os = cc->getOutStream(); os->writeBytes(buf, 128); - os->writeBytes(BBytes.buf, keyLength); + os->writeBytes(BBytes.data(), BBytes.size()); os->flush(); } diff --git a/common/rfb/CSecurityMSLogonII.cxx b/common/rfb/CSecurityMSLogonII.cxx index bb7e27c7..45c43c3f 100644 --- a/common/rfb/CSecurityMSLogonII.cxx +++ b/common/rfb/CSecurityMSLogonII.cxx @@ -39,7 +39,6 @@ #include <rdr/InStream.h> #include <rdr/OutStream.h> #include <rdr/RandomStream.h> -#include <rdr/types.h> #include <rfb/Exception.h> #include <os/os.h> @@ -99,11 +98,11 @@ void CSecurityMSLogonII::writeCredentials() rdr::RandomStream rs; (CSecurity::upg)->getUserPasswd(isSecure(), &username.buf, &password.buf); - rdr::U8Array bBytes(8); + std::vector<uint8_t> bBytes(8); if (!rs.hasData(8)) throw ConnFailedException("failed to generate DH private key"); - rs.readBytes(bBytes.buf, 8); - nettle_mpz_set_str_256_u(b, 8, bBytes.buf); + rs.readBytes(bBytes.data(), bBytes.size()); + nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); mpz_powm(B, g, b, p); diff --git a/common/rfb/Cursor.cxx b/common/rfb/Cursor.cxx index dcb28ccb..f0c72eed 100644 --- a/common/rfb/Cursor.cxx +++ b/common/rfb/Cursor.cxx @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2014-2017 Pierre Ossman for Cendio AB + * Copyright 2014-2023 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ #include <assert.h> #include <string.h> -#include <rdr/types.h> + #include <rfb/Cursor.h> #include <rfb/LogWriter.h> #include <rfb/Exception.h> @@ -125,11 +125,11 @@ static void dither(int width, int height, int32_t* data) } } -uint8_t* Cursor::getBitmap() const +std::vector<uint8_t> Cursor::getBitmap() const { // First step is converting to luminance - rdr::S32Array luminance(width()*height()); - int32_t *lum_ptr = luminance.buf; + std::vector<int32_t> luminance(width()*height()); + int32_t *lum_ptr = luminance.data(); const uint8_t *data_ptr = data; for (int y = 0; y < height(); y++) { for (int x = 0; x < width(); x++) { @@ -148,33 +148,33 @@ uint8_t* Cursor::getBitmap() const } // Then diterhing - dither(width(), height(), luminance.buf); + dither(width(), height(), luminance.data()); // Then conversion to a bit mask - rdr::U8Array source((width()+7)/8*height()); - memset(source.buf, 0, (width()+7)/8*height()); + std::vector<uint8_t> source((width()+7)/8*height()); + memset(source.data(), 0, source.size()); int maskBytesPerRow = (width() + 7) / 8; - lum_ptr = luminance.buf; + lum_ptr = luminance.data(); data_ptr = data; for (int y = 0; y < height(); y++) { for (int x = 0; x < width(); x++) { int byte = y * maskBytesPerRow + x / 8; int bit = 7 - x % 8; if (*lum_ptr > 32767) - source.buf[byte] |= (1 << bit); + source[byte] |= (1 << bit); lum_ptr++; data_ptr += 4; } } - return source.takeBuf(); + return source; } -uint8_t* Cursor::getMask() const +std::vector<uint8_t> Cursor::getMask() const { // First step is converting to integer array - rdr::S32Array alpha(width()*height()); - int32_t *alpha_ptr = alpha.buf; + std::vector<int32_t> alpha(width()*height()); + int32_t *alpha_ptr = alpha.data(); const uint8_t *data_ptr = data; for (int y = 0; y < height(); y++) { for (int x = 0; x < width(); x++) { @@ -184,26 +184,26 @@ uint8_t* Cursor::getMask() const } // Then diterhing - dither(width(), height(), alpha.buf); + dither(width(), height(), alpha.data()); // Then conversion to a bit mask - rdr::U8Array mask((width()+7)/8*height()); - memset(mask.buf, 0, (width()+7)/8*height()); + std::vector<uint8_t> mask((width()+7)/8*height()); + memset(mask.data(), 0, mask.size()); int maskBytesPerRow = (width() + 7) / 8; - alpha_ptr = alpha.buf; + alpha_ptr = alpha.data(); data_ptr = data; for (int y = 0; y < height(); y++) { for (int x = 0; x < width(); x++) { int byte = y * maskBytesPerRow + x / 8; int bit = 7 - x % 8; if (*alpha_ptr > 32767) - mask.buf[byte] |= (1 << bit); + mask[byte] |= (1 << bit); alpha_ptr++; data_ptr += 4; } } - return mask.takeBuf(); + return mask; } // crop() determines the "busy" rectangle for the cursor - the minimum bounding diff --git a/common/rfb/Cursor.h b/common/rfb/Cursor.h index 7db0e9ba..31d6fda9 100644 --- a/common/rfb/Cursor.h +++ b/common/rfb/Cursor.h @@ -1,5 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. - * Copyright 2014-2017 Pierre Ossman for Cendio AB + * Copyright 2014-2023 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,8 @@ #ifndef __RFB_CURSOR_H__ #define __RFB_CURSOR_H__ +#include <vector> + #include <rfb/PixelBuffer.h> namespace rfb { @@ -40,9 +42,9 @@ namespace rfb { const uint8_t* getBuffer() const { return data; }; // getBitmap() returns a monochrome version of the cursor - uint8_t* getBitmap() const; + std::vector<uint8_t> getBitmap() const; // getMask() returns a simple mask version of the alpha channel - uint8_t* getMask() const; + std::vector<uint8_t> getMask() const; // crop() crops the cursor down to the smallest possible size, based on the // mask. diff --git a/common/rfb/SMsgReader.cxx b/common/rfb/SMsgReader.cxx index ba2eb175..5ff07e23 100644 --- a/common/rfb/SMsgReader.cxx +++ b/common/rfb/SMsgReader.cxx @@ -23,9 +23,10 @@ #include <stdio.h> +#include <vector> + #include <rdr/InStream.h> #include <rdr/ZlibInStream.h> -#include <rdr/types.h> #include <rfb/msgTypes.h> #include <rfb/qemuTypes.h> @@ -141,11 +142,11 @@ bool SMsgReader::readSetEncodings() return false; is->clearRestorePoint(); - rdr::S32Array encodings(nEncodings); - for (int i = 0; i < nEncodings; i++) - encodings.buf[i] = is->readU32(); + std::vector<int32_t> encodings(nEncodings); + for (size_t i = 0; i < encodings.size(); i++) + encodings[i] = is->readU32(); - handler->setEncodings(nEncodings, encodings.buf); + handler->setEncodings(nEncodings, encodings.data()); return true; } diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx index 29bd5897..1172ac4d 100644 --- a/common/rfb/SMsgWriter.cxx +++ b/common/rfb/SMsgWriter.cxx @@ -27,7 +27,6 @@ #include <rdr/OutStream.h> #include <rdr/MemOutStream.h> #include <rdr/ZlibOutStream.h> -#include <rdr/types.h> #include <rfb/msgTypes.h> #include <rfb/fenceTypes.h> @@ -443,14 +442,16 @@ void SMsgWriter::writePseudoRects() cursor.hotspot().x, cursor.hotspot().y, cursor.getBuffer()); } else if (client->supportsEncoding(pseudoEncodingCursor)) { - rdr::U8Array data(cursor.width()*cursor.height() * (client->pf().bpp/8)); - rdr::U8Array mask(cursor.getMask()); + size_t data_len = cursor.width()*cursor.height() * + (client->pf().bpp/8); + std::vector<uint8_t> data(data_len); + std::vector<uint8_t> mask(cursor.getMask()); const uint8_t* in; uint8_t* out; in = cursor.getBuffer(); - out = data.buf; + out = data.data(); for (int i = 0;i < cursor.width()*cursor.height();i++) { client->pf().bufferFromRGB(out, in, 1); in += 4; @@ -459,14 +460,14 @@ void SMsgWriter::writePseudoRects() writeSetCursorRect(cursor.width(), cursor.height(), cursor.hotspot().x, cursor.hotspot().y, - data.buf, mask.buf); + data.data(), mask.data()); } else if (client->supportsEncoding(pseudoEncodingXCursor)) { - rdr::U8Array bitmap(cursor.getBitmap()); - rdr::U8Array mask(cursor.getMask()); + std::vector<uint8_t> bitmap(cursor.getBitmap()); + std::vector<uint8_t> mask(cursor.getMask()); writeSetXCursorRect(cursor.width(), cursor.height(), cursor.hotspot().x, cursor.hotspot().y, - bitmap.buf, mask.buf); + bitmap.data(), mask.data()); } else { throw Exception("Client does not support local cursor"); } diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index 1b13397d..5ebec79f 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -28,6 +28,8 @@ #include <stdlib.h> #include <assert.h> +#include <vector> + #include <nettle/bignum.h> #include <nettle/sha1.h> #include <nettle/sha2.h> @@ -39,7 +41,6 @@ #include <rfb/Exception.h> #include <rdr/AESInStream.h> #include <rdr/AESOutStream.h> -#include <rdr/types.h> #if !defined(WIN32) && !defined(__APPLE__) #include <rfb/UnixPasswordValidator.h> #endif @@ -123,7 +124,7 @@ next: } static bool loadPEM(uint8_t* data, size_t size, const char *begin, - const char *end, uint8_t** der, size_t *derSize) + const char *end, std::vector<uint8_t> *der) { ssize_t pos1 = findSubstr(data, size, begin); if (pos1 == -1) @@ -135,13 +136,17 @@ static bool loadPEM(uint8_t* data, size_t size, const char *begin, char *derBase64 = (char *)data + pos1; if (!base64Size) return false; - *der = new uint8_t[BASE64_DECODE_LENGTH(base64Size)]; + der->resize(BASE64_DECODE_LENGTH(base64Size)); struct base64_decode_ctx ctx; + size_t derSize; base64_decode_init(&ctx); - if (!base64_decode_update(&ctx, derSize, *der, base64Size, derBase64)) + if (!base64_decode_update(&ctx, &derSize, der->data(), + base64Size, derBase64)) return false; if (!base64_decode_final(&ctx)) return false; + assert(derSize <= der->size()); + der->resize(derSize); return true; } @@ -157,25 +162,24 @@ void SSecurityRSAAES::loadPrivateKey() throw ConnFailedException("size of key file is zero or too big"); } fseek(file, 0, SEEK_SET); - rdr::U8Array data(size); - if (fread(data.buf, 1, size, file) != size) { + std::vector<uint8_t> data(size); + if (fread(data.data(), 1, data.size(), file) != size) { fclose(file); throw ConnFailedException("failed to read key"); } fclose(file); - rdr::U8Array der; - size_t derSize; - if (loadPEM(data.buf, size, "-----BEGIN RSA PRIVATE KEY-----\n", - "-----END RSA PRIVATE KEY-----", &der.buf, &derSize)) { - loadPKCS1Key(der.buf, derSize); + std::vector<uint8_t> der; + if (loadPEM(data.data(), data.size(), + "-----BEGIN RSA PRIVATE KEY-----\n", + "-----END RSA PRIVATE KEY-----", &der)) { + loadPKCS1Key(der.data(), der.size()); return; } - if (der.buf) - delete[] der.takeBuf(); - if (loadPEM(data.buf, size, "-----BEGIN PRIVATE KEY-----\n", - "-----END PRIVATE KEY-----", &der.buf, &derSize)) { - loadPKCS8Key(der.buf, derSize); + if (loadPEM(data.data(), data.size(), + "-----BEGIN PRIVATE KEY-----\n", + "-----END PRIVATE KEY-----", &der)) { + loadPKCS8Key(der.data(), der.size()); return; } throw ConnFailedException("failed to import key"); diff --git a/common/rfb/TightDecoder.cxx b/common/rfb/TightDecoder.cxx index 65c7191a..09c253bd 100644 --- a/common/rfb/TightDecoder.cxx +++ b/common/rfb/TightDecoder.cxx @@ -25,10 +25,11 @@ #include <assert.h> +#include <vector> + #include <rdr/InStream.h> #include <rdr/MemInStream.h> #include <rdr/OutStream.h> -#include <rdr/types.h> #include <rfb/ServerParams.h> #include <rfb/Exception.h> @@ -309,15 +310,15 @@ void TightDecoder::decodeRect(const Rect& r, const void* buffer, if (pf.is888()) { size_t len = palSize * 3; - rdr::U8Array tightPalette(len); + std::vector<uint8_t> tightPalette(len); assert(buflen >= len); - memcpy(tightPalette.buf, bufptr, len); + memcpy(tightPalette.data(), bufptr, len); bufptr += len; buflen -= len; - pf.bufferFromRGB(palette, tightPalette.buf, palSize); + pf.bufferFromRGB(palette, tightPalette.data(), palSize); } else { size_t len; |