mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Prevent NPE on avatar direct rendering if federated avatars disabled (#15434)
#13649 assumed that direct avatar urls would always be libravatar urls - this leads to NPEs if federated avatar service is disabled. Fix #15421 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
		@@ -7,12 +7,14 @@ package user
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
 | 
						"path"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"code.gitea.io/gitea/models"
 | 
						"code.gitea.io/gitea/models"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/context"
 | 
						"code.gitea.io/gitea/modules/context"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/log"
 | 
						"code.gitea.io/gitea/modules/log"
 | 
				
			||||||
 | 
						"code.gitea.io/gitea/modules/setting"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Avatar redirect browser to user avatar of requested size
 | 
					// Avatar redirect browser to user avatar of requested size
 | 
				
			||||||
@@ -70,8 +72,21 @@ func AvatarByEmailHash(ctx *context.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var avatarURL *url.URL
 | 
						var avatarURL *url.URL
 | 
				
			||||||
	avatarURL, err = models.LibravatarURL(email)
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if setting.EnableFederatedAvatar && setting.LibravatarService != nil {
 | 
				
			||||||
 | 
							avatarURL, err = models.LibravatarURL(email)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								avatarURL, err = url.Parse(models.DefaultAvatarLink())
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									ctx.ServerError("invalid default avatar url", err)
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else if !setting.DisableGravatar {
 | 
				
			||||||
 | 
							copyOfGravatarSourceURL := *setting.GravatarSourceURL
 | 
				
			||||||
 | 
							avatarURL = ©OfGravatarSourceURL
 | 
				
			||||||
 | 
							avatarURL.Path = path.Join(avatarURL.Path, hash)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
		avatarURL, err = url.Parse(models.DefaultAvatarLink())
 | 
							avatarURL, err = url.Parse(models.DefaultAvatarLink())
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			ctx.ServerError("invalid default avatar url", err)
 | 
								ctx.ServerError("invalid default avatar url", err)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user