소스 검색

etcdhttp: disallow empty prevValue fields

Jonathan Boulle 11 년 전
부모
커밋
2e2cd12407
2개의 변경된 파일14개의 추가작업 그리고 1개의 파일을 삭제
  1. 9 1
      etcdserver/etcdhttp/http.go
  2. 5 0
      etcdserver/etcdhttp/http_test.go

+ 9 - 1
etcdserver/etcdhttp/http.go

@@ -218,6 +218,14 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
 		)
 	}
 
+	pV := r.FormValue("prevValue")
+	if _, ok := r.Form["prevValue"]; ok && pV == "" {
+		return emptyReq, etcdErr.NewRequestError(
+			etcdErr.EcodeInvalidField,
+			`"prevValue" cannot be empty`,
+		)
+	}
+
 	// prevExist is nullable, so leave it null if not specified
 	var pe *bool
 	if _, ok := r.Form["prevExist"]; ok {
@@ -236,7 +244,7 @@ func parseRequest(r *http.Request, id int64) (etcdserverpb.Request, error) {
 		Method:    r.Method,
 		Path:      p,
 		Val:       r.FormValue("value"),
-		PrevValue: r.FormValue("prevValue"),
+		PrevValue: pV,
 		PrevIndex: pIdx,
 		PrevExist: pe,
 		Recursive: rec,

+ 5 - 0
etcdserver/etcdhttp/http_test.go

@@ -147,6 +147,11 @@ func TestBadParseRequest(t *testing.T) {
 			mustNewForm(t, "foo", url.Values{"stream": []string{"something"}}),
 			etcdErr.EcodeInvalidField,
 		},
+		// prevValue cannot be empty
+		{
+			mustNewForm(t, "foo", url.Values{"prevValue": []string{""}}),
+			etcdErr.EcodeInvalidField,
+		},
 		// wait is only valid with GET requests
 		{
 			mustNewMethodRequest(t, "HEAD", "foo?wait=true"),