1 /* Fortify tests for syslog interface.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
27 #include <support/check.h>
28 #include <support/support.h>
29 #include <support/capture_subprocess.h>
31 static const char *str2
= "F";
32 static char buf2
[10] = "%s";
34 static volatile int chk_fail_ok
;
35 static jmp_buf chk_fail_buf
;
43 longjmp (chk_fail_buf
, 1);
51 printf ("Failure on line %d\n", __LINE__); \
52 support_record_failure (); \
54 #define CHK_FAIL_START \
56 if (! setjmp (chk_fail_buf)) \
58 #define CHK_FAIL_END \
64 call_vsyslog (int priority
, const char *format
, ...)
67 va_start (va
, format
);
68 vsyslog (priority
, format
, va
);
73 run_syslog_chk (void *closure
)
77 syslog (LOG_USER
| LOG_DEBUG
, buf2
, str2
, &n1
, str2
, &n1
);
82 run_vsyslog_chk (void *closure
)
86 call_vsyslog (LOG_USER
| LOG_DEBUG
, buf2
, str2
, &n1
, str2
, &n1
);
93 set_fortify_handler (handler
);
98 syslog (LOG_USER
| LOG_DEBUG
, "%s%n%s%n", str2
, &n1
, str2
, &n2
);
100 TEST_COMPARE (n2
, 2);
103 call_vsyslog (LOG_USER
| LOG_DEBUG
, "%s%n%s%n", str2
, &n1
, str2
, &n2
);
104 TEST_COMPARE (n1
, 1);
105 TEST_COMPARE (n2
, 2);
107 strcpy (buf2
+ 2, "%n%s%n");
109 /* The wrapper tests need to be in a subprocess because the abort called by
110 printf does not unlock the internal syslog lock. */
112 struct support_capture_subprocess result
113 = support_capture_subprocess (run_syslog_chk
, NULL
);
114 support_capture_subprocess_check (&result
, "syslog", 0, sc_allow_stderr
);
115 support_capture_subprocess_free (&result
);
119 struct support_capture_subprocess result
120 = support_capture_subprocess (run_vsyslog_chk
, NULL
);
121 support_capture_subprocess_check (&result
, "syslog", 0, sc_allow_stderr
);
122 support_capture_subprocess_free (&result
);
128 #include <support/test-driver.c>