forked from loafle/openapi-generator-original
[Go] Address Gosec vulnerabilities in Go client mustache template (#12540)
* Fix potential file inclusion via variable * Fix deferring unsafe method "Close" on type "*os.File" * Update samples * Correction to use existing variable * Correction generated samples
This commit is contained in:
parent
45f430f5c8
commit
aeb40ab0ae
@ -457,11 +457,14 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
|
|
||||||
// Add a file to the multipart request
|
// Add a file to the multipart request
|
||||||
func addFile(w *multipart.Writer, fieldName, path string) error {
|
func addFile(w *multipart.Writer, fieldName, path string) error {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(filepath.Clean(path))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -417,11 +417,14 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
|
|
||||||
// Add a file to the multipart request
|
// Add a file to the multipart request
|
||||||
func addFile(w *multipart.Writer, fieldName, path string) error {
|
func addFile(w *multipart.Writer, fieldName, path string) error {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(filepath.Clean(path))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -402,11 +402,14 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
|
|
||||||
// Add a file to the multipart request
|
// Add a file to the multipart request
|
||||||
func addFile(w *multipart.Writer, fieldName, path string) error {
|
func addFile(w *multipart.Writer, fieldName, path string) error {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(filepath.Clean(path))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -430,11 +430,14 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
|
|
||||||
// Add a file to the multipart request
|
// Add a file to the multipart request
|
||||||
func addFile(w *multipart.Writer, fieldName, path string) error {
|
func addFile(w *multipart.Writer, fieldName, path string) error {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(filepath.Clean(path))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
part, err := w.CreateFormFile(fieldName, filepath.Base(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user