Skip to content

Commit de67abb

Browse files
committed
Comments.
Signed-off-by: Peter Štibraný <[email protected]>
1 parent 31ae118 commit de67abb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/alertmanager/multitenant.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -1144,17 +1144,21 @@ func (s StatusHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
11441144
}
11451145
}
11461146

1147-
func storeTemplateFile(tenantTemplateDir, templateFileName, content string) (changed bool, _ error) {
1147+
// storeTemplateFile stores template file with given content into specific directory.
1148+
// Since templateFileName is provided by end-user, it is verified that it doesn't do any path-traversal.
1149+
// Returns true, if file content has changed (new or updated file), false if file with the same name
1150+
// and content was already stored locally.
1151+
func storeTemplateFile(dir, templateFileName, content string) (bool, error) {
11481152
if templateFileName != filepath.Base(templateFileName) {
11491153
return false, fmt.Errorf("template file name '%s' is not not valid", templateFileName)
11501154
}
11511155

1152-
err := os.MkdirAll(tenantTemplateDir, 0755)
1156+
err := os.MkdirAll(dir, 0755)
11531157
if err != nil {
1154-
return false, fmt.Errorf("unable to create Alertmanager templates directory %q: %s", tenantTemplateDir, err)
1158+
return false, fmt.Errorf("unable to create Alertmanager templates directory %q: %s", dir, err)
11551159
}
11561160

1157-
file := filepath.Join(tenantTemplateDir, templateFileName)
1161+
file := filepath.Join(dir, templateFileName)
11581162
// Check if the template file already exists and if it has changed
11591163
if tmpl, err := ioutil.ReadFile(file); err == nil && string(tmpl) == content {
11601164
return false, nil

0 commit comments

Comments
 (0)