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

Fix nil pointer dereference if alloc has nil Job #19972

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,14 @@ func TestClient_hasLocalState(t *testing.T) {

c.stateDB = cstate.NewMemDB(c.logger)

t.Run("nil Job", func(t *testing.T) {
alloc := mock.BatchAlloc()
alloc.Job = nil
c.stateDB.PutAllocation(alloc)

require.False(t, c.hasLocalState(alloc))
cleroux marked this conversation as resolved.
Show resolved Hide resolved
})

t.Run("plain alloc", func(t *testing.T) {
alloc := mock.BatchAlloc()
c.stateDB.PutAllocation(alloc)
Expand Down
3 changes: 3 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4770,6 +4770,9 @@ func (j *Job) Warnings() error {

// LookupTaskGroup finds a task group by name
func (j *Job) LookupTaskGroup(name string) *TaskGroup {
if j == nil {
return nil
}
for _, tg := range j.TaskGroups {
if tg.Name == name {
return tg
Expand Down
Loading