[bugfix] return 400 Bad Request on more cases of malformed AS data (#2399)

This commit is contained in:
kim
2023-11-30 16:22:34 +00:00
committed by GitHub
parent 5fd2e427bb
commit eb170003b8
47 changed files with 1493 additions and 1013 deletions

View File

@ -2,46 +2,30 @@ package errors
import (
"sync/atomic"
"unsafe"
)
// OnceError is an error structure that supports safe multi
// threaded usage and setting only once (until reset).
type OnceError struct{ err unsafe.Pointer }
// NewOnce returns a new OnceError instance.
func NewOnce() OnceError {
return OnceError{
err: nil,
}
}
type OnceError struct{ ptr atomic.Pointer[error] }
// Store will safely set the OnceError to value, no-op if nil.
func (e *OnceError) Store(err error) {
// Nothing to do
func (e *OnceError) Store(err error) bool {
if err == nil {
return
return false
}
// Only set if not already
atomic.CompareAndSwapPointer(
&e.err,
nil,
unsafe.Pointer(&err),
)
return e.ptr.CompareAndSwap(nil, &err)
}
// Load will load the currently stored error.
func (e *OnceError) Load() error {
return *(*error)(atomic.LoadPointer(&e.err))
if ptr := e.ptr.Load(); ptr != nil {
return *ptr
}
return nil
}
// IsSet returns whether OnceError has been set.
func (e *OnceError) IsSet() bool {
return (atomic.LoadPointer(&e.err) != nil)
}
func (e *OnceError) IsSet() bool { return (e.ptr.Load() != nil) }
// Reset will reset the OnceError value.
func (e *OnceError) Reset() {
atomic.StorePointer(&e.err, nil)
}
func (e *OnceError) Reset() { e.ptr.Store(nil) }