Report job number and PID for async commands in interactive shell#155
Merged
Conversation
The shell now reports the job number and process ID of asynchronous commands in an interactive shell, as required by POSIX.1-2024.
| job->j_pgid = doing_job_control_now ? pgid : 0; | ||
| job->j_status = JS_RUNNING; | ||
| job->j_statuschanged = true; | ||
| job->j_statuschanged = false; |
Check failure
Code scanning / CodeQL
Potential use after free
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to ensure that job is not accessed after it has been freed. One way to achieve this is to set the job pointer to NULL immediately after freeing it. This way, any subsequent access to job can be checked against NULL, preventing the use of a dangling pointer.
The best way to fix this without changing existing functionality is to set job to NULL right after the free(job) call on line 449. Additionally, we should add a check before accessing job on line 480 to ensure it is not NULL.
Suggested changeset
1
exec.c
| @@ -449,2 +449,3 @@ | ||
| free(job); | ||
| job = NULL; | ||
| connect_pipes(&pipe); | ||
| @@ -477,9 +478,11 @@ | ||
| /* establish the job and wait for it */ | ||
| job->j_pgid = doing_job_control_now ? pgid : 0; | ||
| job->j_status = JS_RUNNING; | ||
| job->j_statuschanged = false; | ||
| job->j_legacy = false; | ||
| job->j_nonotify = false; | ||
| job->j_pcount = count; | ||
| set_active_job(job); | ||
| if (job != NULL) { | ||
| job->j_pgid = doing_job_control_now ? pgid : 0; | ||
| job->j_status = JS_RUNNING; | ||
| job->j_statuschanged = false; | ||
| job->j_legacy = false; | ||
| job->j_nonotify = false; | ||
| job->j_pcount = count; | ||
| set_active_job(job); | ||
| } | ||
| if (type != E_ASYNC) { |
Copilot is powered by AI and may make mistakes. Always verify output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The shell now reports the job number and process ID of asynchronous commands in an interactive shell, as required by POSIX.1-2024.