loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Listening on abstract domain sockets (#7020)

When passed a socket name that starts with @, go will listen on an
abstract unix domain socket. Forgejo breaks this by assuming the socket
name is a file path and normalizing it to an absolute path.

This small commit prevents treating the socket name as a filesystem path
if it starts with @.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7020
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Mewp <codeberg.org@mewp.pl>
Co-committed-by: Mewp <codeberg.org@mewp.pl>

authored by

Mewp
Mewp
and committed by
Gusted
377052c9 584c504e

+35 -4
+6 -3
modules/graceful/net_unix.go
··· 9 9 "fmt" 10 10 "net" 11 11 "os" 12 + "path/filepath" 12 13 "strconv" 13 14 "strings" 14 15 "sync" ··· 235 236 return nil, err 236 237 } 237 238 238 - fileMode := os.FileMode(setting.UnixSocketPermission) 239 - if err = os.Chmod(address.Name, fileMode); err != nil { 240 - return nil, fmt.Errorf("Failed to set permission of unix socket to %s: %w", fileMode.String(), err) 239 + if filepath.IsAbs(address.Name) { 240 + fileMode := os.FileMode(setting.UnixSocketPermission) 241 + if err = os.Chmod(address.Name, fileMode); err != nil { 242 + return nil, fmt.Errorf("Failed to set permission of unix socket to %s: %w", fileMode.String(), err) 243 + } 241 244 } 242 245 243 246 activeListeners = append(activeListeners, l)
+15
modules/graceful/net_unix_linux_test.go
··· 1 + // Copyright 2025 The Forgejo Authors. All rights reserved. 2 + // SPDX-License-Identifier: GPL-3.0-or-later 3 + 4 + package graceful 5 + 6 + import ( 7 + "testing" 8 + 9 + "github.com/stretchr/testify/require" 10 + ) 11 + 12 + func TestAbstractUnixSocket(t *testing.T) { 13 + _, err := DefaultGetListener("unix", "@abc") 14 + require.NoError(t, err) 15 + }
+1 -1
modules/setting/server.go
··· 265 265 } 266 266 267 267 UnixSocketPermission = uint32(UnixSocketPermissionParsed) 268 - if !filepath.IsAbs(HTTPAddr) { 268 + if HTTPAddr[0] != '@' && !filepath.IsAbs(HTTPAddr) { 269 269 HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr) 270 270 } 271 271 }
+13
modules/setting/server_test.go
··· 73 73 assert.EqualValues(t, 3, Service.UsernameCooldownPeriod) 74 74 assert.EqualValues(t, 8, Service.MaxUserRedirects) 75 75 } 76 + 77 + func TestUnixSocketAbstractNamespace(t *testing.T) { 78 + iniStr := ` 79 + [server] 80 + PROTOCOL=http+unix 81 + HTTP_ADDR=@forgejo 82 + ` 83 + cfg, err := NewConfigProviderFromData(iniStr) 84 + require.NoError(t, err) 85 + loadServerFrom(cfg) 86 + 87 + assert.EqualValues(t, "@forgejo", HTTPAddr) 88 + }