klibc-bot for Harald van Dijk
2019-Jan-25 03:15 UTC
[klibc] [klibc:update-dash] [JOBS] Fix off-by-one error for multiple of four job numbers
Commit-ID: f81d1584a063044567d4e530fdc4aa242e907637 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=f81d1584a063044567d4e530fdc4aa242e907637 Author: Harald van Dijk <harald at gigawatt.nl> AuthorDate: Fri, 26 Sep 2014 22:27:13 +0800 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Fri, 25 Jan 2019 02:57:21 +0000 [klibc] [JOBS] Fix off-by-one error for multiple of four job numbers On 29/07/13 23:44, Luigi Tarenga wrote:> hi list, > while writing a script to execute parallel ssh command on many host I found > a strange behavior of dash. I can replicate it with a very simple script but > didn't find any documentation about dash or POSIX that can explain it. > > tested on centos 6.4 (dash 0.5.5.1) and wih dash compiled from source (0.5.7) > the following script reports error: > > #!/bin/dash > > sleep 3 & > sleep 3 & > sleep 3 & > sleep 3 & > > #/bin/true > jobs -l > > wait %1 > wait %2 > wait %3 > wait %4 > > [vortex at lizard ~]$ ./dash-0.5.7/src/dash test.sh > [4] + 4569 Running > [3] - 4568 Running > [2] 4567 Running > [1] 4566 Running > prova: 14: wait: No such job: %4 > [vortex at lizard ~]$ echo $? > 2Yes, this looks like a bug to me. The number of allocated jobs is always kept as a multiple of four, and the first check in considering whether the job number is valid is "if it's greater than or equal to the number of allocated job, it's invalid". That doesn't look right. That would only be right if jobs were zero-based, but they aren't. If it's exactly equal to the number of available jobs, it can still be valid. It works when adding /bin/true, because four more more jobs end up allocated internally. Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/dash/jobs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/dash/jobs.c b/usr/dash/jobs.c index 009bbfee..1c6c6fbd 100644 --- a/usr/dash/jobs.c +++ b/usr/dash/jobs.c @@ -698,7 +698,7 @@ check: if (is_number(p)) { num = atoi(p); - if (num < njobs) { + if (num <= njobs) { jp = jobtab + num - 1; if (jp->used) goto gotit;
Seemingly Similar Threads
- [klibc:update-dash] dash: [JOBS] Fix off-by-one error for multiple of four job numbers
- [klibc:update-dash] jobs: Don't attempt to access job table for job %0
- [klibc:update-dash] dash: jobs: Don't attempt to access job table for job %0
- Shift the normal curve to the top or near to the top of the histogram
- Shift the normal curve to the top or near to the top of the histogram