X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Ftypes%2Finteger.c;h=719823b9ff23675aab3a0f1b787ddeb8f0af25f2;hp=3381b585cd61e203eb21a8be3adb2a717e56145a;hb=64fa3fec6c28f1d077812b4bfa06ae73b0f5999d;hpb=5385cf15115d777de4a220a164c101da0e4c3bac diff --git a/formats/ctf/types/integer.c b/formats/ctf/types/integer.c index 3381b585..719823b9 100644 --- a/formats/ctf/types/integer.c +++ b/formats/ctf/types/integer.c @@ -3,7 +3,9 @@ * * Integers read/write functions. * - * Copyright 2010 - Mathieu Desnoyers + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,8 +31,8 @@ */ static -void _aligned_integer_read(struct stream_pos *ppos, - struct definition *definition) +int _aligned_integer_read(struct stream_pos *ppos, + struct definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -40,8 +42,11 @@ void _aligned_integer_read(struct stream_pos *ppos, int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */ ctf_align_pos(pos, integer_declaration->p.alignment); - assert(!(pos->offset % CHAR_BIT)); + if (!ctf_pos_access_ok(pos, integer_declaration->len)) + return -EFAULT; + + assert(!(pos->offset % CHAR_BIT)); if (!integer_declaration->signedness) { switch (integer_declaration->len) { case 8: @@ -124,10 +129,11 @@ void _aligned_integer_read(struct stream_pos *ppos, } } ctf_move_pos(pos, integer_declaration->len); + return 0; } static -void _aligned_integer_write(struct stream_pos *ppos, +int _aligned_integer_write(struct stream_pos *ppos, struct definition *definition) { struct definition_integer *integer_definition = @@ -138,8 +144,11 @@ void _aligned_integer_write(struct stream_pos *ppos, int rbo = (integer_declaration->byte_order != BYTE_ORDER); /* reverse byte order */ ctf_align_pos(pos, integer_declaration->p.alignment); - assert(!(pos->offset % CHAR_BIT)); + if (!ctf_pos_access_ok(pos, integer_declaration->len)) + return -EFAULT; + + assert(!(pos->offset % CHAR_BIT)); if (pos->dummy) goto end; if (!integer_declaration->signedness) { @@ -191,9 +200,10 @@ void _aligned_integer_write(struct stream_pos *ppos, } end: ctf_move_pos(pos, integer_declaration->len); + return 0; } -void ctf_integer_read(struct stream_pos *ppos, struct definition *definition) +int ctf_integer_read(struct stream_pos *ppos, struct definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -203,11 +213,14 @@ void ctf_integer_read(struct stream_pos *ppos, struct definition *definition) if (!(integer_declaration->p.alignment % CHAR_BIT) && !(integer_declaration->len % CHAR_BIT)) { - _aligned_integer_read(ppos, definition); - return; + return _aligned_integer_read(ppos, definition); } ctf_align_pos(pos, integer_declaration->p.alignment); + + if (!ctf_pos_access_ok(pos, integer_declaration->len)) + return -EFAULT; + if (!integer_declaration->signedness) { if (integer_declaration->byte_order == LITTLE_ENDIAN) bt_bitfield_read_le(pos->base, unsigned long, @@ -228,9 +241,10 @@ void ctf_integer_read(struct stream_pos *ppos, struct definition *definition) &integer_definition->value._signed); } ctf_move_pos(pos, integer_declaration->len); + return 0; } -void ctf_integer_write(struct stream_pos *ppos, struct definition *definition) +int ctf_integer_write(struct stream_pos *ppos, struct definition *definition) { struct definition_integer *integer_definition = container_of(definition, struct definition_integer, p); @@ -240,11 +254,14 @@ void ctf_integer_write(struct stream_pos *ppos, struct definition *definition) if (!(integer_declaration->p.alignment % CHAR_BIT) && !(integer_declaration->len % CHAR_BIT)) { - _aligned_integer_write(ppos, definition); - return; + return _aligned_integer_write(ppos, definition); } ctf_align_pos(pos, integer_declaration->p.alignment); + + if (!ctf_pos_access_ok(pos, integer_declaration->len)) + return -EFAULT; + if (pos->dummy) goto end; if (!integer_declaration->signedness) { @@ -268,4 +285,5 @@ void ctf_integer_write(struct stream_pos *ppos, struct definition *definition) } end: ctf_move_pos(pos, integer_declaration->len); + return 0; }