Skip to content

Commit

Permalink
gosec cleanupc
Browse files Browse the repository at this point in the history
Signed-off-by: Sandy <sandy@sandyuraz.com>
  • Loading branch information
thecsw committed Jan 16, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 95f73cc commit 80a7f1c
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion emilia/galleries.go
Original file line number Diff line number Diff line change
@@ -148,7 +148,7 @@ func galleryVendorItem(item *GalleryItem) yunyun.FullPathFile {
}

// Open the file writer and encode the image there.
imgFile, err := os.Create(localVendoredPath)
imgFile, err := os.Create(filepath.Clean(localVendoredPath))
if err != nil {
fmt.Printf("Failed to create file %s: %s\n", localVendoredPath, err.Error())
return fallbackReturn
3 changes: 2 additions & 1 deletion emilia/imaging.go
Original file line number Diff line number Diff line change
@@ -5,14 +5,15 @@ import (
"image"
"net/http"
"os"
"path/filepath"

"github.com/disintegration/imaging"
"github.com/pkg/errors"
)

// OpenImage opens local path image and returns decoded image.
func OpenImage(path string) (image.Image, error) {
file, err := os.Open(path)
file, err := os.Open(filepath.Clean(path))
if err != nil {
return nil, errors.Wrap(err, "OpenImage: opening file "+path)
}
2 changes: 1 addition & 1 deletion emilia/syscalls.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ func FileExists(path string) bool {
// Mkdir creates a directory and reports fatal errors.
func Mkdir(path string) error {
// Make sure that the vendor directory exists.
err := os.Mkdir(string(path), 0755)
err := os.Mkdir(string(path), 0750)
// If we couldn't create the vendor directory and it doesn't
// exist, then turn off the vendor option.
if err != nil && !os.IsExist(err) {
2 changes: 1 addition & 1 deletion ichika/build.go
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ func build() {

// writeFile takes a filename and a bufio reader and writes it.
func writeFile(filename string, reader *bufio.Reader) (int64, error) {
target, err := os.Create(filename)
target, err := os.Create(filepath.Clean(filename))
if err != nil {
return -1, errors.Wrap(err, "failed to create "+filename)
}
6 changes: 3 additions & 3 deletions ichika/holoscene.go
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ const (

func updateHolosceneTitles(dryRun bool) {
if dryRun {
if err := os.Mkdir(holosceneTitlesTempDir, 0755); err != nil {
if err := os.Mkdir(holosceneTitlesTempDir, 0750); err != nil {
fmt.Printf("Failed to create temp dir: %s", err)
os.Exit(1)
}
@@ -30,7 +30,7 @@ func updateHolosceneTitles(dryRun bool) {

actuallyFound := make([]*os.File, 0, len(outputs))
for _, v := range outputs {
file, err := os.Open(v)
file, err := os.Open(filepath.Clean(v))
if err != nil {
fmt.Printf("Couldn't open %s: %s\n", v, err)
continue
@@ -60,7 +60,7 @@ func updateHolosceneTitles(dryRun bool) {
file, err = os.CreateTemp(holosceneTitlesTempDir,
filepath.Base(filename))
} else {
file, err = os.Create(filename)
file, err = os.Create(filepath.Clean(filename))
}
if err != nil {
fmt.Printf("Failed to overwrite %s: %s\n",
12 changes: 7 additions & 5 deletions ichika/rss.go
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"sort"
"time"

@@ -76,21 +77,22 @@ func rssf(dryRun bool) {
},
}

feedXml, err := os.Create(string(emilia.JoinWorkdir(rssXMLFilename)))
xmlTarget := string(emilia.JoinWorkdir(rssXMLFilename))
feedXml, err := os.Create(filepath.Clean(xmlTarget))
if err != nil {
fmt.Printf("couldn't create %s: %s\n", rssXMLFilename, err)
fmt.Printf("couldn't create %s: %s\n", xmlTarget, err)
os.Exit(1)
}
encoder := xml.NewEncoder(feedXml)
if err := encoder.Encode(feed); err != nil {
fmt.Printf("failed to encode %s: %s\n", rssXMLFilename, err)
fmt.Printf("failed to encode %s: %s\n", xmlTarget, err)
os.Exit(1)
}
if err := feedXml.Close(); err != nil {
fmt.Printf("failed to close %s: %s", rssXMLFilename, err)
fmt.Printf("failed to close %s: %s", xmlTarget, err)
os.Exit(1)
}
fmt.Printf("Created rss file in %s\n", rssXMLFilename)
fmt.Printf("Created rss file in %s\n", xmlTarget)
}

// getDate takes a page and returns its date if any found.

0 comments on commit 80a7f1c

Please sign in to comment.