From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10505 Path: news.gmane.org!.POSTED!not-for-mail From: Laine Gholson Newsgroups: gmane.linux.lib.musl.general Subject: Re: [RFC PATCH] Add fortify _chk functions Date: Mon, 19 Sep 2016 17:45:26 -0500 Message-ID: References: <20160919224302.GE15995@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1474325159 1165 195.159.176.226 (19 Sep 2016 22:45:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 19 Sep 2016 22:45:59 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux armv7l; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 Cc: musl@lists.openwall.com To: Rich Felker Original-X-From: musl-return-10518-gllmg-musl=m.gmane.org@lists.openwall.com Tue Sep 20 00:45:54 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1bm7Jm-0006iy-Sp for gllmg-musl@m.gmane.org; Tue, 20 Sep 2016 00:45:43 +0200 Original-Received: (qmail 5304 invoked by uid 550); 19 Sep 2016 22:45:42 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 5286 invoked from network); 19 Sep 2016 22:45:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=teRHZbpYvwBZpf6kfemksV/ZIsxQR3kGYI2QG2Fdm4A=; b=dcmo0rhVT2zH4Q90YQkhdIHD/fa09m3XPGycaJ4y2mg5YzoRyEx+YQspY3yuZEg73T HtcR1RWO/HDsFjD0AYrdYqAqkxfOhIS8tfS/tT1UV/koskKpYZG1wyia+0TVGrDEp65r 4mjbj57DGG7GkESNzEAuuPkrJfVoDEL5mvsO3c1Vd2Vd4UpiP6aOqVT4H8SfaY9nAiJT L76uh0YinrvArZyJXoqtpkW5BD+8AlNw/hh4oDja5ERkIKLd2jTu7di3AmkLp3mTr2Jd 2lT0DsifPO5/ZI9afds4e2bkNMcZhkRcFF4hFVApbKUR5JXNbH/Z5uGy97GVFFkh9X15 JVZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=teRHZbpYvwBZpf6kfemksV/ZIsxQR3kGYI2QG2Fdm4A=; b=LnPwHGDQHywWxJ6Ka8sBw5OqRSioNm8yru1sEsRy3MVSMwgrrNVg6hALvzAo54Hu3i FCk/7XeJFVycYF4xylyQ3kZ6zwOMMzg/2KLLO1f3d6awvVAJA7ZzG7xuU/2vfPw25OFF kimTkbhKTBuBp9jTQyADHnV6m3tAxVLMpZpRuUi8hNruiMNBE4MmGYKvUkVx5qyH3Pnt 1p3kQ8onXquSht1Fk0mwz5YGArnS0QzPYtrwYqxJrcmbt9dpOkGxingpfKyhzpALMWc2 B1u5fxY0+uxJk/slLXXnrfS5Opcw98DfWpDQrq44peI/6q1jT+HaUPLBlo5feRpkQR2M VRgw== X-Gm-Message-State: AE9vXwOUqZjCNylvQKPvbnRJlOvR62Be5kTtyH7PGeHEYYGzwQXOfwsyYhlZwDchzq0SeQ== X-Received: by 10.36.210.68 with SMTP id z65mr644456itf.32.1474325129559; Mon, 19 Sep 2016 15:45:29 -0700 (PDT) In-Reply-To: <20160919224302.GE15995@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:10505 Archived-At: Can you send me a link to the other patch? On 09/19/16 17:43, Rich Felker wrote: > On Mon, Sep 19, 2016 at 05:38:01PM -0500, Laine Gholson wrote: >> Hello, >> >> I have attached a proof of concept patch that adds >> many of glibc's fortify *_chk functions to musl, improving >> musl's binary compatibility with glibc. >> >> Please reply. >> >> Thanks, >> Laine Gholson > > I haven't read the patch yet, but have you compared it to the > existing, long-pending patch? It had some open issues that have still > not been addressed. > > Rich > >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/asprintf_chk.c musl-git/src/fortify/asprintf_chk.c >> --- musl-git.orig/src/fortify/asprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/asprintf_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,13 @@ >> +#define _GNU_SOURCE >> +#include >> +#include >> + >> +int __asprintf_chk(char **s, int flag, const char *fmt, ...) >> +{ >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vasprintf(s, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/chk_fail.c musl-git/src/fortify/chk_fail.c >> --- musl-git.orig/src/fortify/chk_fail.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/chk_fail.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include "atomic.h" >> +#include "fortify.h" >> + >> +_Noreturn void __chk_fail(void) >> +{ >> + a_crash(); >> + // make gcc happy >> + abort(); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/confstr_chk.c musl-git/src/fortify/confstr_chk.c >> --- musl-git.orig/src/fortify/confstr_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/confstr_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __confstr_chk(int name, char *buf, size_t len, size_t buflen) >> +{ >> + if(buflen < len) __chk_fail(); >> + return confstr(name, buf, len); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/fdelt_chk.c musl-git/src/fortify/fdelt_chk.c >> --- musl-git.orig/src/fortify/fdelt_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/fdelt_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,9 @@ >> +#define _GNU_SOURCE >> +#include >> +#include "fortify.h" >> + >> +long __fdelt_chk(long d) >> +{ >> + if(0 < d || d >= FD_SETSIZE) __chk_fail(); >> + return d/NFDBITS; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/fgets_chk.c musl-git/src/fortify/fgets_chk.c >> --- musl-git.orig/src/fortify/fgets_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/fgets_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,10 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__fgets_chk(char *restrict s, size_t size, int strsize, FILE *restrict f) >> +{ >> + if(strsize < size) __chk_fail(); >> + return fgets(s, size, f); >> +} >> + >> +weak_alias(__fgets_chk, __fgets_unlocked_chk); >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/fgetws_chk.c musl-git/src/fortify/fgetws_chk.c >> --- musl-git.orig/src/fortify/fgetws_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/fgetws_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,10 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__fgetws_chk(wchar_t *restrict s, size_t size, int strsize, FILE *restrict f) >> +{ >> + if(strsize < size) __chk_fail(); >> + return fgetws(s, size, f); >> +} >> + >> +weak_alias(__fgetws_chk, __fgetws_unlocked_chk); >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/fprintf_chk.c musl-git/src/fortify/fprintf_chk.c >> --- musl-git.orig/src/fortify/fprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/fprintf_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,14 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __fprintf_chk(FILE *restrict f, int flag, const char *restrict fmt, ...) >> +{ >> + //FIXME: fortify >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vfprintf(f, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/fwprintf_chk.c musl-git/src/fortify/fwprintf_chk.c >> --- musl-git.orig/src/fortify/fwprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/fwprintf_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,14 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __fwprintf_chk(FILE *restrict f, int flag, const wchar_t *restrict fmt, ...) >> +{ >> + //FIXME: fortify >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vfwprintf(f, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/getcwd_chk.c musl-git/src/fortify/getcwd_chk.c >> --- musl-git.orig/src/fortify/getcwd_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/getcwd_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__getcwd_chk(char *buf, size_t len, size_t buflen) >> +{ >> + if(buflen < len) __chk_fail(); >> + return getcwd(buf, len); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/getgroups_chk.c musl-git/src/fortify/getgroups_chk.c >> --- musl-git.orig/src/fortify/getgroups_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/getgroups_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +int __getgroups_chk(int count, gid_t *list, size_t listlen) >> +{ >> + if(count*sizeof(gid_t) > listlen) __chk_fail(); >> + return getgroups(count, list); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/gethostname_chk.c musl-git/src/fortify/gethostname_chk.c >> --- musl-git.orig/src/fortify/gethostname_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/gethostname_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +int __gethostname_chk(char *name, size_t len, size_t maxlen) >> +{ >> + if(len > maxlen) __chk_fail(); >> + return gethostname(name, len); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/getlogin_r_chk.c musl-git/src/fortify/getlogin_r_chk.c >> --- musl-git.orig/src/fortify/getlogin_r_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/getlogin_r_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +int __getlogin_r_chk(char *name, size_t size, size_t maxlen) >> +{ >> + if(size < maxlen) __chk_fail(); >> + return getlogin_r(name, size); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/longjmp_chk.c musl-git/src/fortify/longjmp_chk.c >> --- musl-git.orig/src/fortify/longjmp_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/longjmp_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,6 @@ >> +#include >> + >> +void __longjmp_chk(jmp_buf env, int val) >> +{ >> + return longjmp(env, val); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/mbsnrtowcs_chk.c musl-git/src/fortify/mbsnrtowcs_chk.c >> --- musl-git.orig/src/fortify/mbsnrtowcs_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/mbsnrtowcs_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __mbsnrtowcs_chk(wchar_t *restrict wcs, const char **restrict src, size_t n, size_t wn, mbstate_t *restrict st, size_t dn) >> +{ >> + if(dn < wn) __chk_fail(); >> + return mbsnrtowcs(wcs, src, n, wn, st); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/mbsrtowcs_chk.c musl-git/src/fortify/mbsrtowcs_chk.c >> --- musl-git.orig/src/fortify/mbsrtowcs_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/mbsrtowcs_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __mbsrtowcs_chk(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st, size_t dn) >> +{ >> + if(dn < wn) __chk_fail(); >> + return mbsrtowcs(ws, src, wn, st); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/mbstowcs_chk.c musl-git/src/fortify/mbstowcs_chk.c >> --- musl-git.orig/src/fortify/mbstowcs_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/mbstowcs_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __mbstowcs_chk(wchar_t *restrict ws, const char *restrict s, size_t wn, size_t dn) >> +{ >> + if(dn < wn) __chk_fail(); >> + return mbstowcs(ws, s, wn); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/memcpy_chk.c musl-git/src/fortify/memcpy_chk.c >> --- musl-git.orig/src/fortify/memcpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/memcpy_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +void *__memcpy_chk(void *restrict dest, const void *restrict src, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return memcpy(dest, src, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/memmove_chk.c musl-git/src/fortify/memmove_chk.c >> --- musl-git.orig/src/fortify/memmove_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/memmove_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +void *__memmove_chk(void *dest, const void *src, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return memmove(dest, src, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/mempcpy_chk.c musl-git/src/fortify/mempcpy_chk.c >> --- musl-git.orig/src/fortify/mempcpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/mempcpy_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,9 @@ >> +#define _GNU_SOURCE >> +#include >> +#include "fortify.h" >> + >> +void *__mempcpy_chk(void *dest, const void *src, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return mempcpy(dest, src, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/memset_chk.c musl-git/src/fortify/memset_chk.c >> --- musl-git.orig/src/fortify/memset_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/memset_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +void *__memset_chk(void *dest, int c, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return memset(dest, c, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/pread_chk.c musl-git/src/fortify/pread_chk.c >> --- musl-git.orig/src/fortify/pread_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/pread_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,10 @@ >> +#include >> +#include "fortify.h" >> + >> +ssize_t __pread_chk(int fd, void *buf, size_t size, off_t ofs, size_t bufsize) >> +{ >> + if(bufsize < size) __chk_fail(); >> + return pread(fd, buf, size, ofs); >> +} >> + >> +LFS64_2(__pread_chk, __pread64_chk); >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/printf_chk.c musl-git/src/fortify/printf_chk.c >> --- musl-git.orig/src/fortify/printf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/printf_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,14 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __printf_chk(int flag, const char *restrict fmt, ...) >> +{ >> + //FIXME: fortify >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vfprintf(stdout, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/read_chk.c musl-git/src/fortify/read_chk.c >> --- musl-git.orig/src/fortify/read_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/read_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +ssize_t __read_chk(int fd, void *buf, size_t count, size_t buflen) >> +{ >> + if(buflen < count) __chk_fail(); >> + return read(fd, buf, count); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/readlink_chk.c musl-git/src/fortify/readlink_chk.c >> --- musl-git.orig/src/fortify/readlink_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/readlink_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +ssize_t __readlink_chk(const char *restrict path, char *restrict buf, size_t size, size_t bufsize) >> +{ >> + if(bufsize < size) __chk_fail(); >> + return readlink(path, buf, size); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/realpath_chk.c musl-git/src/fortify/realpath_chk.c >> --- musl-git.orig/src/fortify/realpath_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/realpath_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +char *__realpath_chk(const char *restrict filename, char *restrict resolved, size_t resolved_len) >> +{ >> + if(resolved_len < PATH_MAX) __chk_fail(); >> + return realpath(filename, resolved); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/recv_chk.c musl-git/src/fortify/recv_chk.c >> --- musl-git.orig/src/fortify/recv_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/recv_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include >> +#include "fortify.h" >> + >> +ssize_t __recv_chk(int fd, void *buf, size_t len, size_t buflen, int flags) >> +{ >> + if(buflen < len) __chk_fail(); >> + return recv(fd, buf, len, flags); >> +} >> + >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/recvfrom_chk.c musl-git/src/fortify/recvfrom_chk.c >> --- musl-git.orig/src/fortify/recvfrom_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/recvfrom_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +ssize_t __recvfrom_chk(int fd, void *restrict buf, size_t len, size_t buflen, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen) >> +{ >> + if(buflen < len) __chk_fail(); >> + return recvfrom(fd, buf, len, flags, addr, alen); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/snprintf_chk.c musl-git/src/fortify/snprintf_chk.c >> --- musl-git.orig/src/fortify/snprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/snprintf_chk.c 2016-09-18 11:23:15.119998589 -0500 >> @@ -0,0 +1,14 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __snprintf_chk(char *restrict s, size_t n, int flag, size_t sn, const char *restrict fmt, ...) >> +{ >> + if(sn < n) __chk_fail(); >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vsnprintf(s, n, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/sprintf_chk.c musl-git/src/fortify/sprintf_chk.c >> --- musl-git.orig/src/fortify/sprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/sprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,14 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __sprintf_chk(char *restrict s, int flag, size_t sn, const char *restrict fmt, ...) >> +{ >> + if(sn == 0) __chk_fail(); >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vsprintf(s, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/stpcpy_chk.c musl-git/src/fortify/stpcpy_chk.c >> --- musl-git.orig/src/fortify/stpcpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/stpcpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__stpcpy_chk(char *restrict d, const char *restrict s, size_t dn) >> +{ >> + if(dn <= strlen(s)) __chk_fail(); >> + return stpcpy(d, s); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/stpncpy_chk.c musl-git/src/fortify/stpncpy_chk.c >> --- musl-git.orig/src/fortify/stpncpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/stpncpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__stpncpy_chk(char *restrict d, const char *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return stpncpy(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/strcat_chk.c musl-git/src/fortify/strcat_chk.c >> --- musl-git.orig/src/fortify/strcat_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/strcat_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,7 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__strcat_chk(char *restrict dest, const char *restrict src, size_t destlen) >> +{ >> + return strcat(dest, src); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/strcpy_chk.c musl-git/src/fortify/strcpy_chk.c >> --- musl-git.orig/src/fortify/strcpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/strcpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__strcpy_chk(char *restrict dest, const char *restrict src, size_t destlen) >> +{ >> + if(destlen <= strlen(src)) __chk_fail(); >> + return strcpy(dest, src); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/strncat_chk.c musl-git/src/fortify/strncat_chk.c >> --- musl-git.orig/src/fortify/strncat_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/strncat_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__strncat_chk(char *restrict d, const char *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return strncat(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/strncpy_chk.c musl-git/src/fortify/strncpy_chk.c >> --- musl-git.orig/src/fortify/strncpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/strncpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +char *__strncpy_chk(char *restrict d, const char *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return strncpy(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/swprintf_chk.c musl-git/src/fortify/swprintf_chk.c >> --- musl-git.orig/src/fortify/swprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/swprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,14 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __swprintf_chk(wchar_t *restrict s, size_t n, int flag, size_t sn, const wchar_t *restrict fmt, ...) >> +{ >> + if(sn < n) __chk_fail(); >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vswprintf(s, n, fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/syslog_chk.c musl-git/src/fortify/syslog_chk.c >> --- musl-git.orig/src/fortify/syslog_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/syslog_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,13 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +void __vsyslog(int, const char *, va_list); >> + >> +void __syslog_chk(int priority, int flag, const char *message, ...) >> +{ >> + va_list ap; >> + va_start(ap, message); >> + __vsyslog(priority, message, ap); >> + va_end(ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/ttyname_r_chk.c musl-git/src/fortify/ttyname_r_chk.c >> --- musl-git.orig/src/fortify/ttyname_r_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/ttyname_r_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +int __ttyname_r_chk(int fd, char *name, size_t size, size_t nsize) >> +{ >> + if(nsize < size) __chk_fail(); >> + return ttyname_r(fd, name, size); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vasprintf_chk.c musl-git/src/fortify/vasprintf_chk.c >> --- musl-git.orig/src/fortify/vasprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vasprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#define _GNU_SOURCE >> +#include >> +#include >> + >> +int __vasprintf_chk(char **s, int flag, const char *fmt, va_list ap) >> +{ >> + return vasprintf(s, fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vfprintf_chk.c musl-git/src/fortify/vfprintf_chk.c >> --- musl-git.orig/src/fortify/vfprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vfprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vfprintf_chk(FILE *restrict f, int flag, const char *restrict fmt, va_list ap) >> +{ >> + return vfprintf(f, fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vfwprintf_chk.c musl-git/src/fortify/vfwprintf_chk.c >> --- musl-git.orig/src/fortify/vfwprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vfwprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vfwprintf_chk(FILE *restrict f, int flag, const wchar_t *restrict fmt, va_list ap) >> +{ >> + return vfwprintf(f, fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vprintf_chk.c musl-git/src/fortify/vprintf_chk.c >> --- musl-git.orig/src/fortify/vprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,7 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vprintf_chk(int flag, const char *restrict fmt, va_list ap) { >> + return vprintf(fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vsnprintf_chk.c musl-git/src/fortify/vsnprintf_chk.c >> --- musl-git.orig/src/fortify/vsnprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vsnprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vsnprintf_chk(char *restrict s, size_t n, int flag, size_t sn, const char *restrict fmt, va_list ap) >> +{ >> + if(sn < n) __chk_fail(); >> + return vsnprintf(s, n, fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vsprintf_chk.c musl-git/src/fortify/vsprintf_chk.c >> --- musl-git.orig/src/fortify/vsprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vsprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,7 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vsprintf_chk(char *restrict s, int flag, size_t sn, const char *restrict fmt, va_list ap) { >> + return vsprintf(s, fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vswprintf_chk.c musl-git/src/fortify/vswprintf_chk.c >> --- musl-git.orig/src/fortify/vswprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vswprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vswprintf_chk(wchar_t *restrict s, size_t n, int flag, size_t sn, const wchar_t *restrict fmt, va_list ap) >> +{ >> + if(sn < n) __chk_fail(); >> + return vswprintf(s, n, fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vsyslog_chk.c musl-git/src/fortify/vsyslog_chk.c >> --- musl-git.orig/src/fortify/vsyslog_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vsyslog_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,10 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +void __vsyslog(int, const char *, va_list); >> + >> +void __vsyslog_chk(int priority, int flag, const char *message, va_list ap) >> +{ >> + return __vsyslog(priority, message, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/vwprintf_chk.c musl-git/src/fortify/vwprintf_chk.c >> --- musl-git.orig/src/fortify/vwprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/vwprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include >> +#include "fortify.h" >> + >> +int __vwprintf_chk(int flag, const wchar_t *restrict fmt, va_list ap) >> +{ >> + return vwprintf(fmt, ap); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcpcpy_chk.c musl-git/src/fortify/wcpcpy_chk.c >> --- musl-git.orig/src/fortify/wcpcpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcpcpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,7 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wcpcpy_chk(wchar_t *restrict d, const wchar_t *restrict s, size_t dn) >> +{ >> + return wcpcpy(d, s); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcpncpy_chk.c musl-git/src/fortify/wcpncpy_chk.c >> --- musl-git.orig/src/fortify/wcpncpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcpncpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wcpncpy_chk(wchar_t *restrict d, const wchar_t *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wcpncpy(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcrtomb_chk.c musl-git/src/fortify/wcrtomb_chk.c >> --- musl-git.orig/src/fortify/wcrtomb_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcrtomb_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include >> +#include "locale_impl.h" >> +#include "fortify.h" >> + >> +size_t __wcrtomb_chk(char *restrict s, wchar_t wc, mbstate_t *restrict st, size_t bn) >> +{ >> + if(bn < MB_CUR_MAX) __chk_fail(); >> + return wcrtomb(s, wc, st); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcscat_chk.c musl-git/src/fortify/wcscat_chk.c >> --- musl-git.orig/src/fortify/wcscat_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcscat_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,6 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wcscat_chk(wchar_t *restrict dest, const wchar_t *restrict src, size_t destlen) { >> + return wcscat(dest, src); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcscpy_chk.c musl-git/src/fortify/wcscpy_chk.c >> --- musl-git.orig/src/fortify/wcscpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcscpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,7 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wcscpy_chk(wchar_t *restrict d, const wchar_t *restrict s, size_t dn) >> +{ >> + return wcscpy(d, s); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcsncat_chk.c musl-git/src/fortify/wcsncat_chk.c >> --- musl-git.orig/src/fortify/wcsncat_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcsncat_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wcsncat_chk(wchar_t *restrict d, const wchar_t *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wcsncat(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcsncpy_chk.c musl-git/src/fortify/wcsncpy_chk.c >> --- musl-git.orig/src/fortify/wcsncpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcsncpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wcsncpy_chk(wchar_t *restrict d, const wchar_t *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wcsncpy(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcsnrtombs_chk.c musl-git/src/fortify/wcsnrtombs_chk.c >> --- musl-git.orig/src/fortify/wcsnrtombs_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcsnrtombs_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __wcsnrtombs_chk(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wcsnrtombs(dst, wcs, wn, n, st); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcsrtombs_chk.c musl-git/src/fortify/wcsrtombs_chk.c >> --- musl-git.orig/src/fortify/wcsrtombs_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcsrtombs_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __wcsrtombs_chk(char *restrict s, const wchar_t **restrict ws, size_t n, mbstate_t *restrict st, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wcsrtombs(s, ws, n, st); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wcstombs_chk.c musl-git/src/fortify/wcstombs_chk.c >> --- musl-git.orig/src/fortify/wcstombs_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wcstombs_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +size_t __wcstombs_chk(char *restrict s, const wchar_t *restrict ws, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wcstombs(s, ws, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wctomb_chk.c musl-git/src/fortify/wctomb_chk.c >> --- musl-git.orig/src/fortify/wctomb_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wctomb_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,9 @@ >> +#include >> +#include "locale_impl.h" >> +#include "fortify.h" >> + >> +int __wctomb_chk(char *s, wchar_t wc, size_t sn) >> +{ >> + if(sn < MB_CUR_MAX) __chk_fail(); >> + return wctomb(s, wc); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wmemcpy_chk.c musl-git/src/fortify/wmemcpy_chk.c >> --- musl-git.orig/src/fortify/wmemcpy_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wmemcpy_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wmemcpy_chk(wchar_t *restrict d, const wchar_t *restrict s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wmemcpy(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wmemmove_chk.c musl-git/src/fortify/wmemmove_chk.c >> --- musl-git.orig/src/fortify/wmemmove_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wmemmove_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wmemmove_chk(wchar_t *d, const wchar_t *s, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wmemmove(d, s, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wmemset_chk.c musl-git/src/fortify/wmemset_chk.c >> --- musl-git.orig/src/fortify/wmemset_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wmemset_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,8 @@ >> +#include >> +#include "fortify.h" >> + >> +wchar_t *__wmemset_chk(wchar_t *d, wchar_t c, size_t n, size_t dn) >> +{ >> + if(dn < n) __chk_fail(); >> + return wmemset(d, c, n); >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/fortify/wprintf_chk.c musl-git/src/fortify/wprintf_chk.c >> --- musl-git.orig/src/fortify/wprintf_chk.c 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/fortify/wprintf_chk.c 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,13 @@ >> +#include >> +#include >> +#include >> + >> +int __wprintf_chk(int flag, const wchar_t *restrict fmt, ...) >> +{ >> + int ret; >> + va_list ap; >> + va_start(ap, fmt); >> + ret = vwprintf(fmt, ap); >> + va_end(ap); >> + return ret; >> +} >> diff -u --exclude .git -uprN musl-git.orig/src/internal/fortify.h musl-git/src/internal/fortify.h >> --- musl-git.orig/src/internal/fortify.h 1969-12-31 18:00:00.000000000 -0600 >> +++ musl-git/src/internal/fortify.h 2016-09-18 11:23:15.129998589 -0500 >> @@ -0,0 +1,3 @@ >> +#include "libc.h" >> + >> +_Noreturn void __chk_fail(void); >