Add file-size limit

This commit is contained in:
odyseusz 2024-10-06 16:24:46 +02:00
parent 97b006259b
commit 4b871b50c6

View File

@ -75,7 +75,7 @@ func userData(username, usersonline, ops string) UserInfo {
} }
crdstr := strings.TrimSuffix(string(crd), "\n") crdstr := strings.TrimSuffix(string(crd), "\n")
filename := "/home/" + username + "/meta-info.toml" filename := "/home/" + username + "/meta-info.toml"
_, error := os.Stat(filename) filestat, error := os.Stat(filename)
if error != nil { if error != nil {
if os.IsNotExist(error) { if os.IsNotExist(error) {
UserError("user doesn't have a meta-info.toml", username, error) UserError("user doesn't have a meta-info.toml", username, error)
@ -95,6 +95,23 @@ func userData(username, usersonline, ops string) UserInfo {
return user return user
} }
} }
// Check file size of meta-info.toml. If it's over 100 kB, bail
if filestat.Size() > 100_000 {
log.Error("user's meta-info.toml is above the 100 kB file size limit", "user", username)
user := UserInfo{
Name: username,
Online: false,
Op: false,
}
user.Created, _ = strconv.Atoi(crdstr)
if isonline {
user.Online = true
}
if isop {
user.Op = true
}
return user
}
viper.SetConfigFile(filename) viper.SetConfigFile(filename)
if err := viper.ReadInConfig(); err != nil { if err := viper.ReadInConfig(); err != nil {
log.Error("message", "couldn't read a users meta-info.toml file.", "error", log.Any("err", err), "user", username) log.Error("message", "couldn't read a users meta-info.toml file.", "error", log.Any("err", err), "user", username)