<div dir="ltr"><div>Previously, `toybox taskset` used the high bits of an overlong mask, but util-linux</div><div>used the low bits.  Use the low bits.</div><div><br></div><div>% ./toybox taskset $( printf %99999s | tr ' ' 0 )f echo ok<br>taskset: failed to set pid 1580999's affinity: Invalid argument<br>% taskset $( printf %99999s | tr ' ' 0 )f echo ok<br>ok</div><div><br></div><div>Reported in</div><div><a href="http://lists.landley.net/pipermail/toybox-landley.net/2025-June/030734.html">http://lists.landley.net/pipermail/toybox-landley.net/2025-June/030734.html</a></div><div><br></div>diff --git a/tests/taskset.test b/tests/taskset.test<br>index acd2869fbc..bfb52e282a 100755<br>--- a/tests/taskset.test<br>+++ b/tests/taskset.test<br>@@ -35,5 +35,7 @@<br> <br> testing "long mask doesn't segfault" \<br>   'taskset $(printf %99999s | tr \  f) echo; echo $?' '\n0\n' '' ''<br>+testing "long mask uses low bits" \<br>+  'taskset $(printf %99999s | tr \  0)1 echo; echo $?' '\n0\n' '' ''<br> testing "taskset error checking" \<br>   'taskset 0 echo nope 2>/dev/null; echo $?' '1\n' '' ''<br>diff --git a/toys/other/taskset.c b/toys/other/taskset.c<br>index cc33d94e3b..458fbeffef 100644<br>--- a/toys/other/taskset.c<br>+++ b/toys/other/taskset.c<br>@@ -66,10 +66,11 @@<br> <br>     if (i || toys.optc < 2) return;<br> <br>-    // Convert hex strong to mask[] bits<br>+    // Convert hex string to mask[] bits<br>     memset(toybuf, 0, sizeof(toybuf));<br>-    k = minof(strlen(s = *toys.optargs), 2*sizeof(toybuf));<br>+    k = strlen(s = *toys.optargs);<br>     s += k;<br>+    k = minof(k, 2*sizeof(toybuf));<br>     for (j = 0; j<k; j++) {<br>       unsigned long digit = *(--s) - '0';<br> </div>