mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Avoid panic caused by broken payload when creating commit status (#23216)
When creating commit status for Actons jobs, a payload with nil `HeadCommit` will cause panic. Reported at: https://gitea.com/gitea/act_runner/issues/28#issuecomment-732166 Although the `HeadCommit` probably can not be nil after #23215, `CreateCommitStatus` should protect itself, to avoid being broken in the future. In addition, it's enough to print error log instead of returning err when `CreateCommitStatus` failed. --------- Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
		| @@ -30,6 +30,16 @@ func CreateCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er | ||||
| 		return fmt.Errorf("GetPushEventPayload: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	// Since the payload comes from json data, we should check if it's broken, or it will cause panic | ||||
| 	switch { | ||||
| 	case payload.Repo == nil: | ||||
| 		return fmt.Errorf("repo is missing in event payload") | ||||
| 	case payload.Pusher == nil: | ||||
| 		return fmt.Errorf("pusher is missing in event payload") | ||||
| 	case payload.HeadCommit == nil: | ||||
| 		return fmt.Errorf("head commit is missing in event payload") | ||||
| 	} | ||||
|  | ||||
| 	creator, err := user_model.GetUserByID(ctx, payload.Pusher.ID) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("GetUserByID: %w", err) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user