From: Eugene Syromyatnikov Date: Mon, 3 Oct 2016 18:35:51 +0000 (+0300) Subject: keyctl: use printstr_ex for printing out buffer X-Git-Tag: v4.14~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f294b39f55daaffbfe55019455e2b5af74b28f7;p=strace keyctl: use printstr_ex for printing out buffer keyctl_read_key had subtle bug by treating out buffer in KEYCTL_READ as NUL-terminated, which is not true. We fix it by adding parameter to keyctl_read_key signalising whether buffer is NUL-terminated and using printstr_ex for printing (expectedly) NUL-terminated strings. * keyctl.c (keyctl_read_key): Add has_nul parameter. Do not use -1 as string len. Use printstr_ex for buffer output with user style depending on has_nul value. (SYS_FUNC(keyctl)): Specify has_nul parameter to keyctl_read_key by comparing cmd value with KEYCTL_READ. --- diff --git a/keyctl.c b/keyctl.c index 536fa805..73f97662 100644 --- a/keyctl.c +++ b/keyctl.c @@ -108,7 +108,8 @@ keyctl_handle_key_key(struct tcb *tcp, key_serial_t id1, key_serial_t id2) } static void -keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len) +keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len, + bool has_nul) { if (entering(tcp)) { print_keyring_serial_number(id); @@ -118,8 +119,9 @@ keyctl_read_key(struct tcb *tcp, key_serial_t id, long addr, long len) printaddr(addr); else { long rval = tcp->u_rval > len ? - len : (tcp->u_rval ? -1 : 0); - printstr(tcp, addr, rval); + len : tcp->u_rval; + printstr_ex(tcp, addr, rval, has_nul ? + QUOTE_OMIT_TRAILING_0 : 0); } tprintf(", %lu", len); } @@ -301,7 +303,8 @@ SYS_FUNC(keyctl) case KEYCTL_READ: case KEYCTL_GET_SECURITY: keyctl_read_key(tcp, tcp->u_arg[1], - tcp->u_arg[2], tcp->u_arg[3]); + tcp->u_arg[2], tcp->u_arg[3], + cmd != KEYCTL_READ); return 0; case KEYCTL_SEARCH: