Przeglądaj źródła

Fix: validate Data field type when unmarshaling notice

Rod Hynes 4 lat temu
rodzic
commit
77fe30a8cb
1 zmienionych plików z 12 dodań i 5 usunięć
  1. 12 5
      psiphon/notice.go

+ 12 - 5
psiphon/notice.go

@@ -1034,14 +1034,21 @@ func GetNotice(notice []byte) (
 	var object noticeObject
 	err = json.Unmarshal(notice, &object)
 	if err != nil {
-		return "", nil, err
+		return "", nil, errors.Trace(err)
 	}
-	var objectPayload interface{}
-	err = json.Unmarshal(object.Data, &objectPayload)
+
+	var data interface{}
+	err = json.Unmarshal(object.Data, &data)
 	if err != nil {
-		return "", nil, err
+		return "", nil, errors.Trace(err)
+	}
+
+	dataValue, ok := data.(map[string]interface{})
+	if !ok {
+		return "", nil, errors.TraceNew("invalid data value")
 	}
-	return object.NoticeType, objectPayload.(map[string]interface{}), nil
+
+	return object.NoticeType, dataValue, nil
 }
 
 // NoticeReceiver consumes a notice input stream and invokes a callback function