From a1412c4f95140e2060f19f18d3a11f187388c3b4 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 5 Jul 2010 12:58:44 +0200 Subject: [PATCH] Make sure print_[u]stack result is terminated. Last line shouldn't have a newline and string should always be terminated. * tapset/context-symbols.stp (sprint_stack): Terminate string. * tapset/ucontext-symbols.stp (sprint_ustack): Likewise. --- tapset/context-symbols.stp | 8 +++++++- tapset/ucontext-symbols.stp | 14 ++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tapset/context-symbols.stp b/tapset/context-symbols.stp index 091214bd7..9bb0f2479 100644 --- a/tapset/context-symbols.stp +++ b/tapset/context-symbols.stp @@ -50,7 +50,7 @@ function print_stack(stk:string) %{ * Perform a symbolic lookup of the addresses in the given string, * which is assumed to be the result of a prior call to backtrace(). * - * Prints a simple backtrace from the given hex string. One line per + * Returns a simple backtrace from the given hex string. One line per * address. Includes the symbol name (or hex address if symbol * couldn't be resolved) and module name (if found). Includes the * offset from the start of the function if found, otherwise the @@ -73,6 +73,12 @@ function sprint_stack:string(stk:string) %{ str += s; tok = strsep(&ptr, " "); } + + str--; + if (len > 0) + str[0] = '\0'; + else + THIS->__retvalue[MAXSTRINGLEN - 1] = '\0'; %} /** diff --git a/tapset/ucontext-symbols.stp b/tapset/ucontext-symbols.stp index ecc387d63..a30089953 100644 --- a/tapset/ucontext-symbols.stp +++ b/tapset/ucontext-symbols.stp @@ -85,7 +85,7 @@ function print_ustack(stk:string) %{ * which is assumed to be the result of a prior call to * ubacktrace() for the current task. * - * Prints a simple backtrace from the given hex string. One line per + * Returns a simple backtrace from the given hex string. One line per * address. Includes the symbol name (or hex address if symbol * couldn't be resolved) and module name (if found). Includes the * offset from the start of the function if found, otherwise the @@ -101,11 +101,17 @@ function sprint_ustack:string(stk:string) %{ char *str = THIS->__retvalue; size_t len = MAXSTRINGLEN - 1; while (tok && *tok && len > 0) { - int s = _stp_snprint_addr(str, len, - simple_strtol(tok, NULL, 16), - _STP_SYM_SIMPLE, current); + int s = _stp_snprint_addr(str, len, + simple_strtol(tok, NULL, 16), + _STP_SYM_SIMPLE, current); len -= s; str += s; tok = strsep(&ptr, " "); } + + str--; + if (len > 0) + str[0] = '\0'; + else + THIS->__retvalue[MAXSTRINGLEN - 1] = '\0'; %} -- 2.43.5