Skip to content

Commit

Permalink
Fix handling of empty second copy of PropertySeq
Browse files Browse the repository at this point in the history
This changes the handling of PropertySeq and BinaryPropertySeq to always return the latest
one in the message.  Without this change a second (or later) empty sequence would be
ignored, but a second (or later) non-empty sequence would be returned.  The memory is
initialised to an empty sequence on allocation, so it doesn't affect the behaviour for the
first copy.  This matters insofar as being consistent with some other deserialization
functions matters.

Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson committed Apr 16, 2024
1 parent 2d0b3ec commit 2ad37f4
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/security/core/src/dds_security_serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,22 +631,20 @@ DDS_Security_Deserialize_PropertySeq(
sequence is 4+1+(3 pad)+4+1 = 13 bytes. Just use 8 because it is way faster
and just as good for checking that the length value isn't completely ridiculous. */
const uint32_t minpropsize = (uint32_t) (2 * sizeof (uint32_t));
int r = 1;
uint32_t length;

if (!DDS_Security_Deserialize_uint32_t(dser, &length)) {
return 0;
} else if (length > dser->remain / minpropsize) {
}
if (length > dser->remain / minpropsize) {
return 0;
} else if (length > 0) {
DDS_Security_PropertySeq_deinit(seq);
seq->_length = seq->_maximum = length;
seq->_buffer = DDS_Security_PropertySeq_allocbuf(seq->_length);
for (uint32_t i = 0; i < seq->_length && r; i++) {
r = DDS_Security_Deserialize_Property(dser, &seq->_buffer[i]);
}
}

DDS_Security_PropertySeq_deinit(seq);
seq->_length = seq->_maximum = length;
seq->_buffer = (seq->_length == 0) ? NULL : DDS_Security_PropertySeq_allocbuf(seq->_length);
int r = 1;
for (uint32_t i = 0; i < seq->_length && r; i++) {
r = DDS_Security_Deserialize_Property(dser, &seq->_buffer[i]);
}
return r;
}

Expand All @@ -659,22 +657,20 @@ DDS_Security_Deserialize_BinaryPropertySeq(
Just use 8 because it is way faster and just as good for checking that the length
value isn't completely ridiculous. */
const uint32_t minpropsize = (uint32_t) (2 * sizeof (uint32_t));
int r = 1;
uint32_t length;

if (!DDS_Security_Deserialize_uint32_t(dser, &length)) {
return 0;
} else if (length > dser->remain / minpropsize) {
}
if (length > dser->remain / minpropsize) {
return 0;
} else if (length > 0) {
DDS_Security_BinaryPropertySeq_deinit(seq);
seq->_length = seq->_maximum = length;
seq->_buffer = DDS_Security_BinaryPropertySeq_allocbuf(seq->_length);
for (uint32_t i = 0; i < seq->_length && r; i++) {
r = DDS_Security_Deserialize_BinaryProperty(dser, &seq->_buffer[i]);
}
}

DDS_Security_BinaryPropertySeq_deinit(seq);
seq->_length = seq->_maximum = length;
seq->_buffer = (seq->_length == 0) ? NULL : DDS_Security_BinaryPropertySeq_allocbuf(seq->_length);
int r = 1;
for (uint32_t i = 0; i < seq->_length && r; i++) {
r = DDS_Security_Deserialize_BinaryProperty(dser, &seq->_buffer[i]);
}
return r;
}

Expand Down

0 comments on commit 2ad37f4

Please sign in to comment.