You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Ensure buffer is always null-terminated even on failure to prevent buffer over-reads
235
235
// At this point, the buffer is known to be non-empty, so it must have space for at least a null terminating byte (even if it overwrites the final output byte in the buffer)
236
-
buffer[buffer.count -1]=0
236
+
if bufferIdx < bufferLength {
237
+
// We still have space left in the buffer - if we haven't already null-terminated then add a null byte to the buffer
238
+
// Since we have space, we only want to write the null byte when/where we have to since some clients provide buffer sizes that don't match the true buffer length
239
+
if bufferIdx == buffer.startIndex || buffer[bufferIdx -1]!=0{
240
+
buffer[bufferIdx]=0
241
+
}
242
+
}else{
243
+
// The buffer is non-empty but we've completely filled it, overwrite the last written byte with a null byte to ensure null termination
// Ensure buffer is always null-terminated even on failure to prevent buffer over-reads
352
-
// At this point, the buffer is known to be non-empty, so it must have space for at least a null terminating byte (even if it overwrites the final output byte in the buffer)
353
-
buffer[buffer.count -1]=0
354
-
}
355
359
356
360
// We only allow embedded nulls if there are no non-null characters following the first null character
0 commit comments