From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7951 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] Implement glibc *_chk interfaces for ABI compatibility. Date: Wed, 17 Jun 2015 11:30:56 +0200 Message-ID: <20150617093056.GD22285@port70.net> References: <1434509291-28997-1-git-send-email-josiahw@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1434533484 26170 80.91.229.3 (17 Jun 2015 09:31:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Jun 2015 09:31:24 +0000 (UTC) Cc: Josiah Worcester To: musl@lists.openwall.com Original-X-From: musl-return-7964-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 17 11:31:24 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Z59gj-0006bF-Lp for gllmg-musl@m.gmane.org; Wed, 17 Jun 2015 11:31:17 +0200 Original-Received: (qmail 20211 invoked by uid 550); 17 Jun 2015 09:31:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 20189 invoked from network); 17 Jun 2015 09:31:08 -0000 Mail-Followup-To: musl@lists.openwall.com, Josiah Worcester Content-Disposition: inline In-Reply-To: <1434509291-28997-1-git-send-email-josiahw@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:7951 Archived-At: * Josiah Worcester [2015-06-16 21:48:11 -0500]: > --- /dev/null > +++ b/src/compat/gnu_chk.c > @@ -0,0 +1,18 @@ > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include "atomic.h" > +#include "atomic.h" > + > +int __ppoll_chk(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask, size_t fdslen) > +{ > + if (fdslen / sizeof(*fds) < n) a_crash(); > + return ppoll(fds, n, to, mask); > +} > + > +void *__mempcpy_chk(void *dest, const void *src, size_t n, size_t destlen) > +{ > + if (destlen < n) a_crash(); > + return mempcpy(dest, src, n); > +} one atomic is enough > +char *__gets_chk(char *buf, size_t size) > +{ > + char *ret = buf; > + int c; > + FLOCK(stdin); > + if (!size) return NULL; > + for(;size;buf++,size--) { > + c = getc(stdin); > + if ((c == EOF && feof(stdin)) || c == '\n') { > + *buf = 0; > + FUNLOCK(stdin); > + return ret; > + } > + if (c == EOF) { > + FUNLOCK(stdin); > + return NULL; > + } > + *buf = c; > + } > + a_crash(); > +} this looks wrong if !size i think that line should be just removed > +void *__memmove_chk(void *restrict dest, const void *restrict src, size_t n, size_t destlen) > +{ > + if (n > destlen) a_crash(); > + return memmove(dest, src, n); > +} i think restrict is wrong here > +char *__strcat_chk(char *restrict dest, const char *restrict src, size_t destlen) > +{ > + size_t tot; > + tot = strnlen(src, destlen); > + if (tot > SIZE_MAX - strnlen(dest, destlen) - 1) a_crash(); > + tot += strnlen(dest, destlen) + 1; > + if (tot > destlen) a_crash(); > + return strcat(dest, src); > +} > + > +char *__strncat_chk(char *restrict dest, const char *restrict src, size_t n, size_t destlen) > +{ > + size_t tot; > + tot = strnlen(dest, destlen); > + if (tot > SIZE_MAX - strnlen(src, n) - 1) a_crash(); > + tot += strnlen(src, n) + 1; > + if (tot > destlen) a_crash(); > + return strncat(dest, src, n); > +} > + i'd store the strnlen result in a temporary var musl is built with -ffreestanding so the compiler cannot assume strnlen is a pure function. > +wchar_t *__wcscat_chk(wchar_t *restrict dest, const wchar_t *src, size_t destlen) > +{ > + size_t tot; > + tot = wcsnlen(src, destlen); > + if (tot > SIZE_MAX - wcsnlen(dest, destlen) - 1) a_crash(); > + tot += wcsnlen(dest, destlen) + 1; > + if (tot > destlen) a_crash(); > + return wcscat(dest, src); > +} > + > +wchar_t *__wcsncat_chk(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, size_t destlen) > +{ > + size_t tot; > + tot = wcsnlen(dest, destlen); > + if (tot > SIZE_MAX - wcsnlen(src, n) - 1) a_crash(); > + tot += wcsnlen(dest, destlen) + 1; > + if (tot > destlen) a_crash(); > + return wcsncat(dest, src, n); > +} > + ditto > diff --git a/src/compat/ttyname_r_chk.c b/src/compat/ttyname_r_chk.c > new file mode 100644 > index 0000000..50e70e5 > --- /dev/null > +++ b/src/compat/ttyname_r_chk.c > @@ -0,0 +1,7 @@ > +#include > + > +int __ttyname_r_chk(int fd, char *name, size_t size, size_t namelen) > +{ > + if (size > namelen) a_crash(); > + return ttyname_r(fd, name, size); > +} missing atomic.h for a_crash shouldnt this be in posix_chk.c? > +size_t __wcrtomb_chk(char *restrict s, wchar_t wc, mbstate_t *restrict st, size_t slen) > +{ > + if (slen < MB_CUR_MAX) a_crash(); > + return wcrtomb(s, wc, st); > +} i think this can cause a false positive crash but glibc seems to do the same.. (eg some api passes wchar_t* and the exact mb encoded length of a string so the output s can be safely shorter than max mb length)