-
Notifications
You must be signed in to change notification settings - Fork 51
Description
libember
Currently the special encoding of -0.0 as described in X.690 (Ch 8.5.9 1 byte, value 0x43) is not handled in libember (and libember-slim) for encoding and decoding and leads to a segmentation fault while decoding as the input length is not checked and the head of the empty stream buffer (which is 0) is dereferenced.
long long exponent = ber::decode<long long>(input, exponentLength);
calls
util::OctetStream::value_type byte = input.front();
with an empty input and segfaults at
return m_head->at(m_head->first());
while dereferencing m_head (nullptr).
C#
In C# the encoding ist defined https://github.com/Lawo/ember-plus-sharp/blob/1a1c2387c90288b8bae311f318b183659e22c1de/Lawo.EmberPlusSharp/Ember/EmberWriter.cs#L363 , so there is a good chance that a C# client will crash a C++ (libember) server.
The current encoding of -0.0 in C++ (libember) will lead to the C# exception https://github.com/Lawo/ember-plus-sharp/blob/1a1c2387c90288b8bae311f318b183659e22c1de/Lawo.EmberPlusSharp/Ember/EmberReader.cs#L563 .
libember_slim
In libember_slim -0.0 will be decoded as NAN
ember-plus/libember_slim/Source/ber.c
Line 734 in 678838b
| qwValue = 0x7fC00000L; |
needed fixes
-
So en/decoding of -0.0 should be handled (libember / libember_slim), but I'm not sure if -0.0 is really needed or if it shouldn't be silently converted to 0.0 to avoid crashing applications using the current lib. If the silent conversion approach is taken than it probably should also be taken in C#.
-
Length should be checked to avoid the segfault, as the standard might be enhanced in the future.
-
StreamBuffer::front should probably always check that m_head is not nullptr and throw an exception if it is, to avoid future segmentation faults where the assumptions while using it don't apply.