mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: Results of static analysis with clang static analyser
Date: Wed, 23 Sep 2015 22:34:21 +0200	[thread overview]
Message-ID: <20150923203421.GG10551@port70.net> (raw)
In-Reply-To: <D28EA11E-B6E9-4C71-9110-9EE6B93DC71E@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

* Khem Raj <raj.khem@gmail.com> [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


[-- Attachment #2: 0001-cosmetic-fix-avoid-reading-uninitialized-memory-in-_.patch --]
[-- Type: text/x-diff, Size: 1166 bytes --]

From da5379205664d62b56acd8f40c405f2b91703afd Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
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


      parent reply	other threads:[~2015-09-23 20:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-23  5:58 Khem Raj
2015-09-23 19:38 ` Rich Felker
2015-09-23 20:02   ` Jens Gustedt
2015-09-24  0:34     ` Rich Felker
2015-09-24  7:22       ` Jens Gustedt
2015-09-24  8:51         ` [PATCH] help static analysis by avoiding to hold state in a pointer that is subject to arithmetic Jens Gustedt
2015-09-25 15:35         ` Results of static analysis with clang static analyser Matt Avery
2015-09-25 21:37           ` Jens Gustedt
2015-09-23 20:11 ` Szabolcs Nagy
2015-09-24  6:35   ` Rich Felker
2015-09-23 20:34 ` Szabolcs Nagy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150923203421.GG10551@port70.net \
    --to=nsz@port70.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).