handle xlat_styles when decoding sa_mask

Dmitry V. Levin ldv at altlinux.org
Fri Feb 8 19:32:52 UTC 2019


Hi,

On Sat, Jan 05, 2019 at 12:10:38PM -0800, shankarapailoor wrote:
> Hi,
> 
> Strace doesn't handle xlat styles properly when decoding the sa_mask
> field of the sigaction struct,  Attached is a patch which decodes the
> field as an array of bytes. Let me know what you think!
> 
> Regards,
> Shankara Pailoor

> From 41d7cac5cf000f4e8b6ee675d231038cb786d2e1 Mon Sep 17 00:00:00 2001
> From: Shankara Pailoor <shankarapailoor at gmail.com>
> Date: Sat, 5 Jan 2019 11:49:28 -0800
> Subject: [PATCH v1] properly handle xlat_styles when decoding sigaction mask
> 
> * signal.c (sprintsigmask_n): Decode sigaction mask as array of bytes under XLAT_RAW, VERBOSE.
> * tests/printsamask.c: New file.
> * tests/printsamask-Xabbrev.c: Likewise.
> * tests/printsamask-Xraw.c: Likewise.
> * tests/printsamask-Xverbose.c: Likewise.
> * tests/pure_executables.list: Add printsamask-Xabbrev, printsamask-Xraw, printsamask-Xverbose.
> * tests/gen_tests.in: Likewise.
> ---
>  signal.c                     | 32 +++++++++++++-
>  tests/.gitignore             |  3 ++
>  tests/gen_tests.in           |  3 ++
>  tests/printsamask-Xabbrev.c  |  1 +
>  tests/printsamask-Xraw.c     |  2 +
>  tests/printsamask-Xverbose.c |  2 +
>  tests/printsamask.c          | 81 ++++++++++++++++++++++++++++++++++++
>  tests/pure_executables.list  |  3 ++
>  8 files changed, 126 insertions(+), 1 deletion(-)
>  create mode 100644 tests/printsamask-Xabbrev.c
>  create mode 100644 tests/printsamask-Xraw.c
>  create mode 100644 tests/printsamask-Xverbose.c
>  create mode 100644 tests/printsamask.c
> 
> diff --git a/signal.c b/signal.c
> index 418905f0..e3c5d8c3 100644
> --- a/signal.c
> +++ b/signal.c
> @@ -166,8 +166,11 @@ sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
>  	 * Most of signal names have length 7,
>  	 * average length of signal names is less than 7.
>  	 * The length of prefix string does not exceed 16.
> +	 * Under xlat_verbose we may have at most NSIG_BYTES in
> +	 * the raw sa_mask array. We can safely allocate 8 bytes per entry
>  	 */
> -	static char outstr[128 + 8 * (NSIG_BYTES * 8 * 2 / 3)];
> +	static char outstr[128 + 8 * (NSIG_BYTES * 8 * 2 / 3)
> +				+ 8 * NSIG_BYTES];
>  
>  	char *s;
>  	const uint32_t *mask;
> @@ -178,6 +181,29 @@ sprintsigmask_n(const char *prefix, const void *sig_mask, unsigned int bytes)
>  
>  	s = stpcpy(outstr, prefix);
>  
> +	if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV) {
> +		const char *mask = (char *) sig_mask;
> +		const char *sep = "[";
> +		unsigned int i, size;
> +
> +		size = (bytes >= NSIG_BYTES) ? NSIG_BYTES : bytes;
> +		for (i = 0; i < size; i++) {
> +			s = xappendstr(outstr, s, "%s0x%02x", sep, mask[i]);
> +			sep = ", ";
> +		}

I hope you understand that the output produced by your parser
is different between big-endian and little-endian architectures.

[...]
> +int
> +main(void)
> +{
> +	unsigned int set_size = NSIG / 8;
> +	void *const k_set = tail_alloc(set_size);
> +	void *const old_set = tail_alloc(set_size);
> +	TAIL_ALLOC_OBJECT_CONST_PTR(sigset_t, libc_set);
> +
> +	memset(k_set, 0, set_size);
> +	sigemptyset(libc_set);
> +	sigaddset(libc_set, SIGHUP);
> +	memcpy(k_set, libc_set, set_size);
> +
> +	int rc = k_sigprocmask(SIG_SETMASK, k_set, old_set, set_size);
> +#if XLAT_RAW
> +	tprintf("rt_sigprocmask(0x2"
> +		", [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]"
> +		", [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]"
> +		", %u) = %s\n", set_size, sprintrc(rc));
> +#elif XLAT_VERBOSE
> +	tprintf("rt_sigprocmask(0x2 /* SIG_SETMASK */"
> +		", [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] /* [HUP] */"
> +		", [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] /* [] */, %u) = %s\n",
> +			set_size, sprintrc(rc));
> +#else /* XLAT_ABBREV */
> +	tprintf("rt_sigprocmask(SIG_SETMASK, [HUP], [], %u) = %s\n",
> +			set_size, sprintrc(rc));
> +#endif

Your test assumes that the output is produced on a big-endian
architecture, so it fails on big-endian architectures.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20190208/ad7a9261/attachment.bin>


More information about the Strace-devel mailing list