mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [PATCH 1/2] fix error checking in pthread_getname_np
@ 2021-07-10  3:24 Érico Nogueira
  2021-07-10  3:25 ` [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list Érico Nogueira
  0 siblings, 1 reply; 3+ messages in thread
From: Érico Nogueira @ 2021-07-10  3:24 UTC (permalink / raw)
  To: musl; +Cc: Érico Nogueira, Michael Forney

len is unsigned and can never be smaller than 0. though unlikely, an
error in read() would have lead to an out of bounds write to name.

Reported-by: Michael Forney <mforney@mforney.org>
---
 src/thread/pthread_getname_np.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/thread/pthread_getname_np.c b/src/thread/pthread_getname_np.c
index 48d1a294..85504e45 100644
--- a/src/thread/pthread_getname_np.c
+++ b/src/thread/pthread_getname_np.c
@@ -17,7 +17,7 @@ int pthread_getname_np(pthread_t thread, char *name, size_t len)
 
 	snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
-	if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) < 0) status = errno;
+	if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
 	else name[len-1] = 0; /* remove trailing new line only if successful */
 	if (fd >= 0) close(fd);
 	pthread_setcancelstate(cs, 0);
-- 
2.32.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list
  2021-07-10  3:24 [musl] [PATCH 1/2] fix error checking in pthread_getname_np Érico Nogueira
@ 2021-07-10  3:25 ` Érico Nogueira
  2021-07-10 17:00   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Érico Nogueira @ 2021-07-10  3:25 UTC (permalink / raw)
  To: musl; +Cc: Érico Nogueira

this warning catches conditionals which are never true, such as checking
if an unsigned value is smaller than zero. this leads to two warnings in
the getgr_a.c and getpw_a.c files, which assume that the underlying type
for gid_t and uid_t might still change.
---
 configure | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure b/configure
index a5231a0e..b7beaeab 100755
--- a/configure
+++ b/configure
@@ -546,6 +546,7 @@ tryflag CFLAGS_AUTO -Winit-self
 tryflag CFLAGS_AUTO -Wreturn-type
 tryflag CFLAGS_AUTO -Wsequence-point
 tryflag CFLAGS_AUTO -Wstrict-aliasing
+tryflag CFLAGS_AUTO -Wtype-limits
 tryflag CFLAGS_AUTO -Wunused-function
 tryflag CFLAGS_AUTO -Wunused-label
 tryflag CFLAGS_AUTO -Wunused-variable
-- 
2.32.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list
  2021-07-10  3:25 ` [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list Érico Nogueira
@ 2021-07-10 17:00   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2021-07-10 17:00 UTC (permalink / raw)
  To: musl

On Sat, Jul 10, 2021 at 12:25:00AM -0300, Érico Nogueira wrote:
> this warning catches conditionals which are never true, such as checking
> if an unsigned value is smaller than zero. this leads to two warnings in
> the getgr_a.c and getpw_a.c files, which assume that the underlying type
> for gid_t and uid_t might still change.
> ---
>  configure | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/configure b/configure
> index a5231a0e..b7beaeab 100755
> --- a/configure
> +++ b/configure
> @@ -546,6 +546,7 @@ tryflag CFLAGS_AUTO -Winit-self
>  tryflag CFLAGS_AUTO -Wreturn-type
>  tryflag CFLAGS_AUTO -Wsequence-point
>  tryflag CFLAGS_AUTO -Wstrict-aliasing
> +tryflag CFLAGS_AUTO -Wtype-limits
>  tryflag CFLAGS_AUTO -Wunused-function
>  tryflag CFLAGS_AUTO -Wunused-label
>  tryflag CFLAGS_AUTO -Wunused-variable
> -- 
> 2.32.0

I probably won't adopt this, since it necessarily breaks generic
(macro) or underlying-type-agnostic code written to be safe with both
signed and unsigned types.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-10 17:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-10  3:24 [musl] [PATCH 1/2] fix error checking in pthread_getname_np Érico Nogueira
2021-07-10  3:25 ` [musl] [PATCH 2/2] add -Wtype-limits to enabled warning list Érico Nogueira
2021-07-10 17:00   ` Rich Felker

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git