Fri Nov 10 23:03:25 2023 UTC ()
PR/57689: RVP: getcwd() not overridable with -D_FORTIFY_SOURCE


(christos)
diff -r1.11 -r1.12 src/tests/lib/libc/ssp/Makefile
diff -r0 -r1.1 src/tests/lib/libc/ssp/h_getcwd2.c
diff -r1.7 -r1.8 src/tests/lib/libc/ssp/t_ssp.sh

cvs diff -r1.11 -r1.12 src/tests/lib/libc/ssp/Makefile (expand / switch to unified diff)

--- src/tests/lib/libc/ssp/Makefile 2023/06/03 09:09:15 1.11
+++ src/tests/lib/libc/ssp/Makefile 2023/11/10 23:03:25 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile,v 1.11 2023/06/03 09:09:15 lukem Exp $ 1# $NetBSD: Makefile,v 1.12 2023/11/10 23:03:25 christos Exp $
2 2
3NOMAN= # defined 3NOMAN= # defined
4 4
5.include <bsd.own.mk> 5.include <bsd.own.mk>
6 6
7WARNS= 4 7WARNS= 4
8 8
9CPPFLAGS+= -D_FORTIFY_SOURCE=2 9CPPFLAGS+= -D_FORTIFY_SOURCE=2
10 10
11COPTS.h_raw.c= -fstack-protector-all -Wstack-protector 11COPTS.h_raw.c= -fstack-protector-all -Wstack-protector
12COPTS.h_raw.c+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :} 12COPTS.h_raw.c+= ${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :}
13COPTS.h_raw.c+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :} 13COPTS.h_raw.c+= ${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :}
14 14
@@ -21,26 +21,27 @@ COPTS.h_raw.c+= ${${ACTIVE_CC} == "clang @@ -21,26 +21,27 @@ COPTS.h_raw.c+= ${${ACTIVE_CC} == "clang
21 21
22CLEANFILES+= libssp_nonshared.a 22CLEANFILES+= libssp_nonshared.a
23LDFLAGS+= -L. 23LDFLAGS+= -L.
24 24
25TESTSDIR= ${TESTSBASE}/lib/libc/ssp 25TESTSDIR= ${TESTSBASE}/lib/libc/ssp
26 26
27TESTS_SH+= t_ssp 27TESTS_SH+= t_ssp
28 28
29BINDIR= ${TESTSDIR} 29BINDIR= ${TESTSDIR}
30 30
31PROGS= h_fgets 31PROGS= h_fgets
32PROGS+= h_gets 32PROGS+= h_gets
33PROGS+= h_getcwd 33PROGS+= h_getcwd
 34PROGS+= h_getcwd2
34PROGS+= h_memcpy 35PROGS+= h_memcpy
35PROGS+= h_memmove 36PROGS+= h_memmove
36PROGS+= h_memset 37PROGS+= h_memset
37PROGS+= h_raw 38PROGS+= h_raw
38PROGS+= h_read 39PROGS+= h_read
39PROGS+= h_readlink 40PROGS+= h_readlink
40PROGS+= h_snprintf 41PROGS+= h_snprintf
41PROGS+= h_sprintf 42PROGS+= h_sprintf
42PROGS+= h_stpcpy 43PROGS+= h_stpcpy
43PROGS+= h_stpncpy 44PROGS+= h_stpncpy
44PROGS+= h_strcat 45PROGS+= h_strcat
45PROGS+= h_strcpy 46PROGS+= h_strcpy
46PROGS+= h_strncat 47PROGS+= h_strncat

File Added: src/tests/lib/libc/ssp/h_getcwd2.c
#include <err.h>
#include <errno.h>
#include <unistd.h>

char*
getcwd(char* buf, size_t buflen)
{
       errno = ENOSYS;
       return NULL;
}
int
main(void)
{
       char buf[256];  
       if (getcwd(buf, sizeof buf) == NULL)
               err(1, "getcwd failed");
       return 0;
}

cvs diff -r1.7 -r1.8 src/tests/lib/libc/ssp/t_ssp.sh (expand / switch to unified diff)

--- src/tests/lib/libc/ssp/t_ssp.sh 2014/04/06 19:28:59 1.7
+++ src/tests/lib/libc/ssp/t_ssp.sh 2023/11/10 23:03:25 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: t_ssp.sh,v 1.7 2014/04/06 19:28:59 christos Exp $ 1# $NetBSD: t_ssp.sh,v 1.8 2023/11/10 23:03:25 christos Exp $
2# 2#
3# Copyright (c) 2008 The NetBSD Foundation, Inc. 3# Copyright (c) 2008 The NetBSD Foundation, Inc.
4# All rights reserved. 4# All rights reserved.
5# 5#
6# Redistribution and use in source and binary forms, with or without 6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions 7# modification, are permitted provided that the following conditions
8# are met: 8# are met:
9# 1. Redistributions of source code must retain the above copyright 9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer. 10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright 11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the 12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution. 13# documentation and/or other materials provided with the distribution.
14# 14#
@@ -274,35 +274,49 @@ readlink_body() @@ -274,35 +274,49 @@ readlink_body()
274atf_test_case getcwd 274atf_test_case getcwd
275getcwd_head() 275getcwd_head()
276{ 276{
277 atf_set "descr" "Checks getcwd(3)" 277 atf_set "descr" "Checks getcwd(3)"
278} 278}
279getcwd_body() 279getcwd_body()
280{ 280{
281 prog="$(atf_get_srcdir)/h_getcwd" 281 prog="$(atf_get_srcdir)/h_getcwd"
282 282
283 h_pass "$prog 1024" 283 h_pass "$prog 1024"
284 h_fail "$prog 1025" 284 h_fail "$prog 1025"
285} 285}
286 286
 287atf_test_case getcwd2
 288getcwd2_head()
 289{
 290 atf_set "descr" "Checks getcwd(3) override"
 291}
 292getcwd2_body()
 293{
 294 prog="$(atf_get_srcdir)/h_getcwd2"
 295
 296 atf_check -s exit:1 -o ignore \
 297 -e 'match:.*getcwd failed: Function not implemented$' $prog
 298}
 299
287atf_init_test_cases() 300atf_init_test_cases()
288{ 301{
289 atf_add_test_case sprintf 302 atf_add_test_case sprintf
290 atf_add_test_case vsprintf 303 atf_add_test_case vsprintf
291 atf_add_test_case snprintf 304 atf_add_test_case snprintf
292 atf_add_test_case vsnprintf 305 atf_add_test_case vsnprintf
293 atf_add_test_case gets 306 atf_add_test_case gets
294 atf_add_test_case fgets 307 atf_add_test_case fgets
295 atf_add_test_case memcpy 308 atf_add_test_case memcpy
296 atf_add_test_case memmove 309 atf_add_test_case memmove
297 atf_add_test_case memset 310 atf_add_test_case memset
298 atf_add_test_case stpcpy 311 atf_add_test_case stpcpy
299 atf_add_test_case stpncpy 312 atf_add_test_case stpncpy
300 atf_add_test_case strcat 313 atf_add_test_case strcat
301 atf_add_test_case strcpy 314 atf_add_test_case strcpy
302 atf_add_test_case strncat 315 atf_add_test_case strncat
303 atf_add_test_case strncpy 316 atf_add_test_case strncpy
304 atf_add_test_case raw 317 atf_add_test_case raw
305 atf_add_test_case read 318 atf_add_test_case read
306 atf_add_test_case readlink 319 atf_add_test_case readlink
307 atf_add_test_case getcwd 320 atf_add_test_case getcwd
 321 atf_add_test_case getcwd2
308} 322}