1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

feat: add feature file size limit

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
AhmedGrati 2023-09-06 10:03:13 +01:00
parent ade5833ee3
commit 026534e355
2 changed files with 217 additions and 0 deletions

View file

@ -45,6 +45,9 @@ const ExpiryTimeKey = "expiry-time"
// DirectivePrefix defines the prefix of directives that should be parsed
const DirectivePrefix = "# +"
// MaxFeatureFileSize defines the maximum size of a feature file size
const MaxFeatureFileSize = 64000
// Config
var (
featureFilesDir = "/etc/kubernetes/node-feature-discovery/features.d/"
@ -321,6 +324,23 @@ func getFeaturesFromFiles() (map[string]string, error) {
for _, file := range files {
fileName := file.Name()
fileInfo, err := file.Info()
if err != nil {
klog.ErrorS(err, "failed to get file info", "fileName", fileName)
continue
}
fileSize := fileInfo.Size()
if fileSize > MaxFeatureFileSize {
klog.ErrorS(
fmt.Errorf("invalid file size: %d bytes > %d bytes", fileSize, MaxFeatureFileSize),
"skipping file with invalid size",
"fileName", fileName, "fileSize", fileSize,
)
continue
}
lines, err := getFileContent(fileName)
if err != nil {
klog.ErrorS(err, "failed to read file", "fileName", fileName)

File diff suppressed because one or more lines are too long