(root)/
strace-6.5/
tests-mx32/
tampering-notes.c
       1  /*
       2   * Check tampering notes.
       3   *
       4   * Copyright (c) 2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  
      13  #include <limits.h>
      14  #include <stdio.h>
      15  #include <stdlib.h>
      16  #include <string.h>
      17  #include <unistd.h>
      18  
      19  #define PATH_LEN 64
      20  
      21  int
      22  main(int argc, char *argv[])
      23  {
      24  	if (argc < 2)
      25  		error_msg_and_skip("Insufficient arguments");
      26  
      27  	const char *notes = NULL;
      28  	const int notes_case = atoi(argv[1]);
      29  	switch (notes_case) {
      30  	case 1:
      31  		notes = "\\(INJECTED: args\\)";
      32  		break;
      33  	case 2:
      34  		notes = "\\(INJECTED: args\\) \\(DELAYED\\)";
      35  		break;
      36  	case 3:
      37  		notes = "\\(INJECTED: args\\) \\(DELAYED\\)";
      38  		break;
      39  	case 4:
      40  		notes = "\\(INJECTED: args, retval\\)";
      41  		break;
      42  	case 5:
      43  		notes = "\\(INJECTED: args, retval\\) \\(DELAYED\\)";
      44  		break;
      45  	case 6:
      46  		notes = "\\(INJECTED: args, retval\\) \\(DELAYED\\)";
      47  		break;
      48  	default:
      49  		error_msg_and_fail("Unsupported argument: %s", argv[1]);
      50  	}
      51  
      52  	char *const p = tail_alloc(PATH_LEN);
      53  	memset(p, '/', PATH_LEN);
      54  
      55  	if (chdir(p)) {
      56  		; /* Check the return value to pacify the compiler.  */
      57  	}
      58  	printf("chdir\\(.*\\) = .* %s\n", notes);
      59  
      60  	char *const cur_dir = tail_alloc(PATH_MAX);
      61  	long res = syscall(__NR_getcwd, cur_dir, PATH_MAX);
      62  	if (res <= 0)
      63  		perror_msg_and_fail("getcwd");
      64  	printf("getcwd\\(.*\\) = .* %s\n", notes);
      65  
      66  	return 0;
      67  }