Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: plan9: exit status is not passed correctly to exits syscall #53669

Closed
oridb opened this issue Jul 3, 2022 · 2 comments
Closed

runtime: plan9: exit status is not passed correctly to exits syscall #53669

oridb opened this issue Jul 3, 2022 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Plan9
Milestone

Comments

@oridb
Copy link
Contributor

oridb commented Jul 3, 2022

In commit 364ced6. the definition of exit in the plan 9 go runtime was changed like so:

-               status = append(itoa(tmp[:len(tmp)-1], uint64(e)), 0)
+               sl := itoa(tmp[:len(tmp)-1], uint64(e))
+               // Don't append, rely on the existing data being zero.
+               status = tmp[:len(sl)+1]

However, itoa only puts the converted number "somewhere" in the buffer. Specifically, it
builds it from the end of the buffer towards the start -- meaning that the first byte of the buffer
is a 0 byte, and the resulting C string that's passed to exits is empty, leading to a falsely
successful exit.

What version of Go are you using (go version)?

HEAD. It was broken in commit 364ced6,

What operating system and processor architecture are you using (go env)?

Plan 9

What did you do?

% cat test.go
package main

import "os"

func main() {
	os.Exit(2)
}
cpu% go run test.go; echo $status
cpu%

What did you expect to see?

An exit status of 2.

What did you see instead?

A successful exit status.

@gopherbot
Copy link

gopherbot commented Jul 3, 2022

Change https://go.dev/cl/415680 mentions this issue: runtime/plan9: fix exit status

@ianlancetaylor ianlancetaylor changed the title runtime/plan9: exit status is not passed correctly to exits() syscall runtime: plan9: exit status is not passed correctly to exits syscall Jul 3, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Jul 3, 2022
@ianlancetaylor ianlancetaylor added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 3, 2022
@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Jul 3, 2022

CC @dr2chase

jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
In CL 405901 the definition of exit in the Plan 9 go runtime
was changed like so:

	-               status = append(itoa(tmp[:len(tmp)-1], uint64(e)), 0)
	+               sl := itoa(tmp[:len(tmp)-1], uint64(e))
	+               // Don't append, rely on the existing data being zero.
	+               status = tmp[:len(sl)+1]

However, itoa only puts the converted number "somewhere" in the buffer.
Specifically, it builds it from the end of the buffer towards the start,
meaning the first byte of the buffer is a 0 byte, and the resulting string
that's passed to exits is empty, leading to a falsely successful exit.

This change uses the returned value from itoa, rather than the buffer
that was passed in, so that we start from the correct location in the
string.

Fixes golang#53669

Change-Id: I63f0c7641fc6f55250857dc17a1eeb12ae0c2e10
Reviewed-on: https://go-review.googlesource.com/c/go/+/415680
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Plan9
Projects
None yet
Development

No branches or pull requests

3 participants