From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8552 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Results of static analysis with clang static analyser Date: Wed, 23 Sep 2015 22:34:21 +0200 Message-ID: <20150923203421.GG10551@port70.net> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="jCrbxBqMcLqd4mOl" X-Trace: ger.gmane.org 1443040479 27962 80.91.229.3 (23 Sep 2015 20:34:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Sep 2015 20:34:39 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8564-gllmg-musl=m.gmane.org@lists.openwall.com Wed Sep 23 22:34:35 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 1ZeqkN-0003bK-4T for gllmg-musl@m.gmane.org; Wed, 23 Sep 2015 22:34:35 +0200 Original-Received: (qmail 22117 invoked by uid 550); 23 Sep 2015 20:34:33 -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 22093 invoked from network); 23 Sep 2015 20:34:33 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:8552 Archived-At: --jCrbxBqMcLqd4mOl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Khem Raj [2015-09-22 22:58:55 -0700]: > I have run scan-build on musl-git and here are results > > http://busybox.net/~kraj/scan-build-2015-09-22-224330-15962-1/ not a bug, but i'd fix this one: http://busybox.net/~kraj/scan-build-2015-09-22-224330-15962-1/report-15c463.html#EndPath --jCrbxBqMcLqd4mOl Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-cosmetic-fix-avoid-reading-uninitialized-memory-in-_.patch" >From da5379205664d62b56acd8f40c405f2b91703afd Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Wed, 23 Sep 2015 20:22:33 +0000 Subject: [PATCH] cosmetic fix: avoid reading uninitialized memory in __map_file The value of *size is not relevant in case of failure, but it's better not to copy garbage from the stack into it. (The compiler cannot see through the syscall, so optimization was not affected by the unspecified value). --- src/time/__map_file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/time/__map_file.c b/src/time/__map_file.c index d06a581..b91eb8e 100644 --- a/src/time/__map_file.c +++ b/src/time/__map_file.c @@ -11,9 +11,10 @@ const char unsigned *__map_file(const char *pathname, size_t *size) const unsigned char *map = MAP_FAILED; int fd = __sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK); if (fd < 0) return 0; - if (!__syscall(SYS_fstat, fd, &st)) + if (!__syscall(SYS_fstat, fd, &st)) { map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + *size = st.st_size; + } __syscall(SYS_close, fd); - *size = st.st_size; return map == MAP_FAILED ? 0 : map; } -- 2.4.1 --jCrbxBqMcLqd4mOl--