Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebServer should be clean up the tmp file. #3

Open
lenusmargin opened this issue Mar 12, 2019 · 0 comments
Open

WebServer should be clean up the tmp file. #3

lenusmargin opened this issue Mar 12, 2019 · 0 comments

Comments

@lenusmargin
Copy link

lenusmargin commented Mar 12, 2019

When I create a plugin container as web server, like "docker run -d -p 3993:3993 malice/clamav web".

I found the container always exit after submit many files.

I check the log, it looks like disk is full....

time="2019-03-11T13:25:40Z" level=info msg="web service listening on port :3993"
time="2019-03-12T04:25:23Z" level=fatal msg="write /malware/web_876481929: no space left on device"

so, I check the code of scan.go, I think this is a bug.

func webAvScan(w http.ResponseWriter, r *http.Request) {
	r.ParseMultipartForm(32 << 20)
	file, header, err := r.FormFile("malware")
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintln(w, "Please supply a valid file to scan.")
		log.Error(err)
	}
	defer file.Close()

	log.Debug("Uploaded fileName: ", header.Filename)

	tmpfile, err := ioutil.TempFile("/malware", "web_")
	if err != nil {
		log.Fatal(err)
	}
	defer os.Remove(tmpfile.Name()) // clean up

	data, err := ioutil.ReadAll(file)
	assert(err)

	if _, err = tmpfile.Write(data); err != nil {
		log.Fatal(err)
	}
	if err = tmpfile.Close(); err != nil {
		log.Fatal(err)
	}

	// Do AV scan
	path = tmpfile.Name()
	clamav := AvScan(60)

        // !!!!!!!  add remove tmp file below Scan call
        // defer os.Remove(tmpfile.Name()) // clean up
  
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)

	if err := json.NewEncoder(w).Encode(clamav); err != nil {
		log.Fatal(err)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant