Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/dnthayer/fix-rdp'
Browse files Browse the repository at this point in the history
* origin/topic/dnthayer/fix-rdp:
  Fix initialization of a pointer in RDP analyzer

Conflicts:
	CHANGES
	VERSION
  • Loading branch information
rsmmr committed Aug 31, 2015
1 parent 954f479 commit 07271e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/ConvertUTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
targetEnd. Note: the end pointers are *after* the last item: e.g.
*(sourceEnd - 1) is the last item.
!!! NOTE: The source and end pointers must be aligned properly !!!
The return result indicates whether the conversion was successful,
and if not, whether the problem was in the source or target buffers.
(Only the first encountered problem is indicated.)
Expand Down Expand Up @@ -199,18 +201,22 @@ ConversionResult ConvertUTF8toUTF32(
const UTF8** sourceStart, const UTF8* sourceEnd,
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);

/* NOTE: The source and end pointers must be aligned properly. */
ConversionResult ConvertUTF16toUTF8 (
const UTF16** sourceStart, const UTF16* sourceEnd,
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);

/* NOTE: The source and end pointers must be aligned properly. */
ConversionResult ConvertUTF32toUTF8 (
const UTF32** sourceStart, const UTF32* sourceEnd,
UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);

/* NOTE: The source and end pointers must be aligned properly. */
ConversionResult ConvertUTF16toUTF32 (
const UTF16** sourceStart, const UTF16* sourceEnd,
UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);

/* NOTE: The source and end pointers must be aligned properly. */
ConversionResult ConvertUTF32toUTF16 (
const UTF32** sourceStart, const UTF32* sourceEnd,
UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
Expand Down
16 changes: 12 additions & 4 deletions src/analyzer/protocol/rdp/rdp-analyzer.pac
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ refine flow RDP_Flow += {
function utf16_to_utf8_val(utf16: bytestring): StringVal
%{
std::string resultstring;
size_t widesize = utf16.length();

size_t utf8size = 3 * widesize + 1;
size_t utf8size = (3 * utf16.length() + 1);

if ( utf8size > resultstring.max_size() )
{
Expand All @@ -20,8 +19,16 @@ refine flow RDP_Flow += {
}

resultstring.resize(utf8size, '\0');
const UTF16* sourcestart = reinterpret_cast<const UTF16*>(utf16.begin());
const UTF16* sourceend = sourcestart + widesize;

// We can't assume that the string data is properly aligned
// here, so make a copy.
UTF16 utf16_copy[utf16.length()]; // Twice as much memory than necessary.
memcpy(utf16_copy, utf16.begin(), utf16.length());

char* utf16_copy_end = reinterpret_cast<const char*>(utf16_copy) + utf16.length();
const UTF16* sourcestart = utf16_copy;
const UTF16* sourceend = reinterpret_cast<UTF16*>(utf16_copy_end);

UTF8* targetstart = reinterpret_cast<UTF8*>(&resultstring[0]);
UTF8* targetend = targetstart + utf8size;

Expand All @@ -37,6 +44,7 @@ refine flow RDP_Flow += {
}

*targetstart = 0;

// We're relying on no nulls being in the string.
return new StringVal(resultstring.c_str());
%}
Expand Down

0 comments on commit 07271e5

Please sign in to comment.