Skip to content

Commit

Permalink
Fix tstring length
Browse files Browse the repository at this point in the history
The tstring area was being allocated without accounting for the NUL byte
at the end of strings.

The tstring reset code was calculating the allocation size per string at
every iteration rather than once.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Nov 20, 2021
1 parent b4baa3e commit 25d31f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions libdtrace/dt_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,23 @@ dt_bpf_gmap_create(dtrace_hdl_t *dtp)
* - size of the DTrace machine state, rounded up to the nearest
* multiple of 8
* - 8 bytes padding for trace buffer alignment purposes
* - maximum trace buffer record size, rounded up to the
* - maximum trace buffer record size, rounded up to the nearest
* multiple of 8
* - the greater of:
* + the maximum stack trace size
* + four times the maximum string size (incl. length
* and allowing round up to multiple of 8)
* plus the maximum string size (to accomodate the BPF
* verifier)
* + DT_TSTRING_SLOTS times the maximum string size (plus
* space for length and terminating '\0') rounded up to
* the nearest multiple of 8),
* plus the maximum string size plus space for '\0' (to
* accomodate the BPF verifier)
*/
memsz = roundup(sizeof(dt_mstate_t), 8) +
8 +
roundup(dtp->dt_maxreclen, 8) +
MAX(sizeof(uint64_t) * dtp->dt_options[DTRACEOPT_MAXFRAMES],
DT_TSTRING_SLOTS *
roundup(DT_STRLEN_BYTES +
dtp->dt_options[DTRACEOPT_STRSIZE], 8) +
dtp->dt_options[DTRACEOPT_STRSIZE] + 1, 8) +
dtp->dt_options[DTRACEOPT_STRSIZE] + 1
);
if (create_gmap(dtp, "mem", BPF_MAP_TYPE_PERCPU_ARRAY,
Expand Down
9 changes: 5 additions & 4 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,18 +806,19 @@ dt_cg_tstring_reset(dtrace_hdl_t *dtp)
{
int i;
dt_tstring_t *ts;
uint64_t size = roundup(DT_STRLEN_BYTES +
dtp->dt_options[DTRACEOPT_STRSIZE] + 1,
8);

if (dtp->dt_tstrings == NULL) {
dtp->dt_tstrings = dt_calloc(dtp, DT_TSTRING_SLOTS,
sizeof(dt_tstring_t));
sizeof(dt_tstring_t));
if (dtp->dt_tstrings == NULL)
longjmp(yypcb->pcb_jmpbuf, EDT_NOMEM);

ts = dtp->dt_tstrings;
for (i = 0; i < DT_TSTRING_SLOTS; i++, ts++)
ts->offset = i *
roundup(DT_STRLEN_BYTES +
dtp->dt_options[DTRACEOPT_STRSIZE], 8);
ts->offset = i * size;
}

ts = dtp->dt_tstrings;
Expand Down

0 comments on commit 25d31f8

Please sign in to comment.