Skip to content

Commit

Permalink
Prevent newline errors with Debian packages (#26332)
Browse files Browse the repository at this point in the history
Fixes #26313
  • Loading branch information
KN4CK3R authored Aug 5, 2023
1 parent 9a8af92 commit 2d3924d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions modules/packages/debian/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,10 @@ func ParseControlFile(r io.Reader) (*Package, error) {
value := strings.TrimSpace(parts[1])
switch key {
case "Package":
if !namePattern.MatchString(value) {
return nil, ErrInvalidName
}
p.Name = value
case "Version":
if !versionPattern.MatchString(value) {
return nil, ErrInvalidVersion
}
p.Version = value
case "Architecture":
if value == "" {
return nil, ErrInvalidArchitecture
}
p.Architecture = value
case "Maintainer":
a, err := mail.ParseAddress(value)
Expand All @@ -208,13 +199,23 @@ func ParseControlFile(r io.Reader) (*Package, error) {
return nil, err
}

if !namePattern.MatchString(p.Name) {
return nil, ErrInvalidName
}
if !versionPattern.MatchString(p.Version) {
return nil, ErrInvalidVersion
}
if p.Architecture == "" {
return nil, ErrInvalidArchitecture
}

dependencies := strings.Split(depends.String(), ",")
for i := range dependencies {
dependencies[i] = strings.TrimSpace(dependencies[i])
}
p.Metadata.Dependencies = dependencies

p.Control = control.String()
p.Control = strings.TrimSpace(control.String())

return p, nil
}
2 changes: 1 addition & 1 deletion services/packages/debian/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func buildPackagesIndices(ctx context.Context, ownerID int64, repoVersion *packa
}
addSeparator = true

fmt.Fprint(w, pfd.Properties.GetByName(debian_module.PropertyControl))
fmt.Fprintf(w, "%s\n", strings.TrimSpace(pfd.Properties.GetByName(debian_module.PropertyControl)))

fmt.Fprintf(w, "Filename: pool/%s/%s/%s\n", distribution, component, pfd.File.Name)
fmt.Fprintf(w, "Size: %d\n", pfd.Blob.Size)
Expand Down

0 comments on commit 2d3924d

Please sign in to comment.