Home | History | Annotate | Line # | Download | only in ssp
      1 /*	$NetBSD: ssp_redirect.c,v 1.4 2026/10/07 00:51:18 riastradh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2023 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Christos Zoulas.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __RCSID("$NetBSD: ssp_redirect.c,v 1.4 2026/10/07 00:51:18 riastradh Exp $");
     34 
     35 #include <unistd.h>
     36 
     37 /*
     38  * This file provides useless wrappers for getcwd, read, and readlink,
     39  * for compatibility with programs built against buggy definitions of
     40  * the ssp wrappers.  For the gory details, see PR lib/60858:
     41  * fortuitous embarrassment: fortify is all kinds of busted
     42  * <https://gnats.NetBSD.org/60858>.
     43  *
     44  * DO NOT ADD MORE FUNCTIONS HERE.  If you are tempted to add another
     45  * __ssp_protected_* symbol, YOU ARE DOING SOMETHING WRONG AND YOU MUST
     46  * UNDERSTAND WHY IT IS WRONG.
     47  */
     48 
     49 __typeof(getcwd) __ssp_protected_getcwd;
     50 __typeof(read) __ssp_protected_read;
     51 __typeof(readlink) __ssp_protected_readlink;
     52 
     53 char *
     54 __ssp_protected_getcwd(char *buf, size_t len)
     55 {
     56 
     57 	return getcwd(buf, len);
     58 }
     59 
     60 ssize_t
     61 __ssp_protected_read(int fd, void *buf, size_t len)
     62 {
     63 
     64 	return read(fd, buf, len);
     65 }
     66 
     67 ssize_t
     68 __ssp_protected_readlink(const char *restrict path,
     69     char *restrict buf, size_t bufsiz)
     70 {
     71 
     72 	return readlink(path, buf, bufsiz);
     73 }
     74 
     75 /*
     76  * Remember: DO NOT ADD MORE FUNCTIONS HERE.  This file was a mistake;
     77  * we just can't get rid of it without breaking compatibility with
     78  * existing binaries (which don't even use the symbols, just demand
     79  * they be present).
     80  */
     81