* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
#include <babeltrace/ctf/types.h>
#include <babeltrace/compat/uuid.h>
#include <babeltrace/compat/utc.h>
#include <babeltrace/ctf/types.h>
#include <babeltrace/compat/uuid.h>
#include <babeltrace/compat/utc.h>
ret = sscanf(VERSION, "%u.%u", &major, &minor);
if (ret != 2)
fprintf(stderr, "[warning] Incorrect babeltrace version format\n.");
ret = sscanf(VERSION, "%u.%u", &major, &minor);
if (ret != 2)
fprintf(stderr, "[warning] Incorrect babeltrace version format\n.");
- ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
- ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
+ if (!ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT))
+ goto error;
+ if (!ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT))
+ goto error;
- ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
- ctf_move_pos(&dummy, 16 * CHAR_BIT);
+ if (!ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT))
+ goto error;
+ if (!ctf_move_pos(&dummy, 16 * CHAR_BIT))
+ goto error;
- ctf_move_pos(pos, BABELTRACE_UUID_LEN * CHAR_BIT);
+ if (!ctf_move_pos(pos, BABELTRACE_UUID_LEN * CHAR_BIT))
+ goto error;
+ return;
+
+error:
+ fprintf(stderr, "[error] Out of packet bounds when writing packet header\n");
+ abort();
- ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
- ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
+ if (!ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
+ goto error;
+ if (!ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
+ goto error;
*(uint64_t *) ctf_get_pos_addr(pos) = ~0ULL; /* Not known yet */
pos->content_size_loc = (uint64_t *) ctf_get_pos_addr(pos);
*(uint64_t *) ctf_get_pos_addr(pos) = ~0ULL; /* Not known yet */
pos->content_size_loc = (uint64_t *) ctf_get_pos_addr(pos);
- ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
- ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
+ if (!ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
+ goto error;
+ if (!ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT))
+ goto error;
- ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT);
+ if (!ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT))
+ goto error;
+ return;
+
+error:
+ fprintf(stderr, "[error] Out of packet bounds when writing packet context\n");
+ abort();
- ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT);
+ if (!ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT))
+ goto error;
+ return;
+
+error:
+ fprintf(stderr, "[error] Out of packet bounds when writing event header\n");
+ abort();
ctf_dummy_pos(pos, &dummy);
write_event_header(&dummy, line, &tline, len, &tlen, &ts);
ctf_dummy_pos(pos, &dummy);
write_event_header(&dummy, line, &tline, len, &tlen, &ts);
- ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT);
- ctf_move_pos(&dummy, tlen * CHAR_BIT);
- if (ctf_pos_packet(&dummy)) {
+ if (!ctf_align_pos(&dummy, sizeof(uint8_t) * CHAR_BIT))
+ packet_filled = 1;
+ if (!ctf_move_pos(&dummy, tlen * CHAR_BIT))
+ packet_filled = 1;
+ if (packet_filled || ctf_pos_packet(&dummy)) {
ctf_pos_pad_packet(pos);
write_packet_header(pos, s_uuid);
write_packet_context(pos);
ctf_pos_pad_packet(pos);
write_packet_header(pos, s_uuid);
write_packet_context(pos);
}
write_event_header(pos, line, &tline, len, &tlen, &ts);
}
write_event_header(pos, line, &tline, len, &tlen, &ts);
- ctf_move_pos(pos, tlen * CHAR_BIT);
+ if (!ctf_move_pos(pos, tlen * CHAR_BIT))
+ goto error;
+ return;
+
+error:
+ fprintf(stderr, "[error] Out of packet bounds when writing event payload\n");
+ abort();
write_packet_header(&pos, s_uuid);
write_packet_context(&pos);
for (;;) {
write_packet_header(&pos, s_uuid);
write_packet_context(&pos);
for (;;) {