From 66555dbb00a493b6e74bda6c0c54ad287389c293 Mon Sep 17 00:00:00 2001
From: fatedier <fatedier@gmail.com>
Date: Sat, 2 Feb 2019 10:49:24 +0800
Subject: [PATCH] frpc admin: not allow empty PUT /api/config body

---
 client/admin_api.go | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/client/admin_api.go b/client/admin_api.go
index 5b6e7380..b857ab59 100644
--- a/client/admin_api.go
+++ b/client/admin_api.go
@@ -280,11 +280,18 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	if len(body) == 0 {
+		res.Code = 2
+		res.Msg = "body can't be empty"
+		log.Warn("%s", res.Msg)
+		return
+	}
+
 	// get token from origin content
 	token := ""
 	b, err := ioutil.ReadFile(g.GlbClientCfg.CfgFile)
 	if err != nil {
-		res.Code = 2
+		res.Code = 3
 		res.Msg = err.Error()
 		log.Warn("load frpc config file error: %v", err)
 		return
@@ -321,7 +328,7 @@ func (svr *Service) apiPutConfig(w http.ResponseWriter, r *http.Request) {
 
 	err = ioutil.WriteFile(g.GlbClientCfg.CfgFile, []byte(content), 0644)
 	if err != nil {
-		res.Code = 3
+		res.Code = 4
 		res.Msg = fmt.Sprintf("write content to frpc config file error: %v", err)
 		log.Warn("%s", res.Msg)
 		return