(root)/
strace-6.5/
tests/
umoven-illptr.c
       1  /*
       2   * Check decoding of invalid pointer by umoven.
       3   *
       4   * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@strace.io>
       5   * Copyright (c) 2016-2021 The strace developers.
       6   * All rights reserved.
       7   *
       8   * SPDX-License-Identifier: GPL-2.0-or-later
       9   */
      10  
      11  #include "tests.h"
      12  #include "scno.h"
      13  
      14  #ifdef __NR_nanosleep
      15  
      16  # include <stdio.h>
      17  # include <unistd.h>
      18  
      19  # include "kernel_old_timespec.h"
      20  
      21  static const char *errstr;
      22  
      23  static long
      24  k_nanosleep(const kernel_ulong_t arg1, const kernel_ulong_t arg2)
      25  {
      26  	const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
      27  	const long rc = syscall(__NR_nanosleep, arg1, arg2, bad, bad, bad, bad);
      28  	errstr = sprintrc(rc);
      29  	return rc;
      30  }
      31  
      32  int
      33  main(void)
      34  {
      35  	if (!F8ILL_KULONG_SUPPORTED)
      36  		return 77;
      37  
      38  	kernel_old_timespec_t ts = { 0, 0 };
      39  	const void *const p = tail_memdup(&ts, sizeof(ts));
      40  
      41  	k_nanosleep((unsigned long) p, 0);
      42  	printf("nanosleep({tv_sec=0, tv_nsec=0}, NULL) = %s\n", errstr);
      43  
      44  	const kernel_ulong_t ill = f8ill_ptr_to_kulong(p);
      45  	k_nanosleep(ill, 0);
      46  	printf("nanosleep(%#llx, NULL) = %s\n",
      47  	       (unsigned long long) ill, errstr);
      48  
      49  	puts("+++ exited with 0 +++");
      50  	return 0;
      51  }
      52  
      53  #else
      54  
      55  SKIP_MAIN_UNDEFINED("__NR_nanosleep")
      56  
      57  #endif