aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0012-fix-uninitialized-output-from-sched_getaffinity.patch
blob: 8e99597be344e60ce4dd272d383c7060f55824c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From a56e339419c1a90f8a85f86621f3c73945e07b23 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Tue, 2 Dec 2014 21:54:36 -0500
Subject: [PATCH] fix uninitialized output from sched_getaffinity

the sched_getaffinity syscall only fills a cpu set up to the set size
used/supported by the kernel. the rest is left untouched and userspace
is responsible for zero-filling it based on the return value of the
syscall.
---
 src/sched/affinity.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/sched/affinity.c b/src/sched/affinity.c
index 3b40211..737e41b 100644
--- a/src/sched/affinity.c
+++ b/src/sched/affinity.c
@@ -1,5 +1,6 @@
 #define _GNU_SOURCE
 #include <sched.h>
+#include <string.h>
 #include "pthread_impl.h"
 #include "syscall.h"
 
@@ -16,7 +17,10 @@ int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set)
 int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set)
 {
 	long ret = __syscall(SYS_sched_getaffinity, tid, size, set);
-	if (ret > 0) ret = 0;
+	if (ret > 0) {
+		if (ret < size) memset((char *)set+ret, 0, size-ret);
+		ret = 0;
+	}
 	return __syscall_ret(ret);
 }
 
-- 
2.2.0