Merge pull request #2765 from Poor12/fix-io-readall
Add limitReader to io.ReadAll
This commit is contained in:
commit
b9612c2e83
|
@ -19,6 +19,8 @@ const (
|
|||
// A split symbol that receives multiple values from a command flag
|
||||
separator = ","
|
||||
labelSeparator = "="
|
||||
// MaxRespBodyLength is the max length of http response body
|
||||
MaxRespBodyLength = 1 << 20 // 1 MiB
|
||||
)
|
||||
|
||||
// IsExist Determine whether the path exists
|
||||
|
@ -60,7 +62,7 @@ func InternetIP() (net.IP, error) {
|
|||
|
||||
defer resp.Body.Close()
|
||||
|
||||
content, err := io.ReadAll(resp.Body)
|
||||
content, err := io.ReadAll(io.LimitReader(resp.Body, MaxRespBodyLength))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -14,6 +14,11 @@ import (
|
|||
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
|
||||
)
|
||||
|
||||
const (
|
||||
// MaxRespBodyLength is the max length of http response body
|
||||
MaxRespBodyLength = 1 << 20 // 1 MiB
|
||||
)
|
||||
|
||||
var admissionScheme = runtime.NewScheme()
|
||||
var admissionCodecs = serializer.NewCodecFactory(admissionScheme)
|
||||
|
||||
|
@ -33,7 +38,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
defer r.Body.Close()
|
||||
if body, err = io.ReadAll(r.Body); err != nil {
|
||||
if body, err = io.ReadAll(io.LimitReader(r.Body, MaxRespBodyLength)); err != nil {
|
||||
klog.Errorf("unable to read the body from the incoming request: %w", err)
|
||||
res = Errored(http.StatusBadRequest, err)
|
||||
wh.writeResponse(w, res)
|
||||
|
|
Loading…
Reference in New Issue