mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(security): slice memory allocation with excessive size value.
Signed-off-by: shuqiang-zheng <zhengshuqiang@oppo.com>
This commit is contained in:
parent
6174cfb9bd
commit
f8c677a041
@ -57,7 +57,7 @@ func (m *Server) handlePeerChange(confChange *proto.ConfChange) (err error) {
|
||||
msg = fmt.Sprintf("action[handlePeerChange] clusterID[%v] nodeAddr[%v] is invalid", m.clusterName, addr)
|
||||
break
|
||||
}
|
||||
m.raftStore.AddNodeWithPort(confChange.Peer.ID, arr[0], int(m.config.heartbeatPort), int(m.config.replicaPort))
|
||||
m.raftStore.AddNodeWithPort(confChange.Peer.ID, arr[0], m.config.heartbeatPort, m.config.replicaPort)
|
||||
AddrDatabase[confChange.Peer.ID] = string(confChange.Context)
|
||||
msg = fmt.Sprintf("clusterID[%v] peerID:%v,nodeAddr[%v] has been add", m.clusterName, confChange.Peer.ID, addr)
|
||||
case proto.ConfRemoveNode:
|
||||
|
||||
@ -42,8 +42,8 @@ const (
|
||||
type clusterConfig struct {
|
||||
peers []raftstore.PeerAddress
|
||||
peerAddrs []string
|
||||
heartbeatPort int64
|
||||
replicaPort int64
|
||||
heartbeatPort int
|
||||
replicaPort int
|
||||
}
|
||||
|
||||
// AddrDatabase is a map that stores the address of a given host (e.g., the leader)
|
||||
@ -76,7 +76,7 @@ func (cfg *clusterConfig) parsePeers(peerStr string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.peers = append(cfg.peers, raftstore.PeerAddress{Peer: proto.Peer{ID: id}, Address: ip, HeartbeatPort: int(cfg.heartbeatPort), ReplicaPort: int(cfg.replicaPort)})
|
||||
cfg.peers = append(cfg.peers, raftstore.PeerAddress{Peer: proto.Peer{ID: id}, Address: ip, HeartbeatPort: cfg.heartbeatPort, ReplicaPort: cfg.replicaPort})
|
||||
address := fmt.Sprintf("%v:%v", ip, port)
|
||||
syslog.Println(address)
|
||||
AddrDatabase[id] = address
|
||||
|
||||
@ -109,8 +109,8 @@ func (m *Server) checkConfig(cfg *config.Config) (err error) {
|
||||
if m.id, err = strconv.ParseUint(cfg.GetString(ID), 10, 64); err != nil {
|
||||
return fmt.Errorf("%v,err:%v", proto.ErrInvalidCfg, err.Error())
|
||||
}
|
||||
m.config.heartbeatPort = cfg.GetInt64(heartbeatPortKey)
|
||||
m.config.replicaPort = cfg.GetInt64(replicaPortKey)
|
||||
m.config.heartbeatPort = cfg.GetInt(heartbeatPortKey)
|
||||
m.config.replicaPort = cfg.GetInt(replicaPortKey)
|
||||
if m.config.heartbeatPort <= 1024 {
|
||||
m.config.heartbeatPort = raftstore.DefaultHeartbeatPort
|
||||
}
|
||||
@ -162,8 +162,8 @@ func (m *Server) createRaftServer(cfg *config.Config) (err error) {
|
||||
NodeID: m.id,
|
||||
RaftPath: m.walDir,
|
||||
NumOfLogsToRetain: m.retainLogs,
|
||||
HeartbeatPort: int(m.config.heartbeatPort),
|
||||
ReplicaPort: int(m.config.replicaPort),
|
||||
HeartbeatPort: m.config.heartbeatPort,
|
||||
ReplicaPort: m.config.replicaPort,
|
||||
TickInterval: m.tickInterval,
|
||||
ElectionTick: m.electionTick,
|
||||
}
|
||||
|
||||
@ -902,15 +902,15 @@ func newVolAddDPCmd(client *master.MasterClient) *cobra.Command {
|
||||
defer func() {
|
||||
errout(err)
|
||||
}()
|
||||
var count int64
|
||||
if count, err = strconv.ParseInt(number, 10, 64); err != nil {
|
||||
var count int
|
||||
if count, err = strconv.Atoi(number); err != nil {
|
||||
return
|
||||
}
|
||||
if count < 1 {
|
||||
err = fmt.Errorf("number must be larger than 0")
|
||||
return
|
||||
}
|
||||
if err = client.AdminAPI().CreateDataPartition(volume, int(count), clientIDKey); err != nil {
|
||||
if err = client.AdminAPI().CreateDataPartition(volume, count, clientIDKey); err != nil {
|
||||
return
|
||||
}
|
||||
stdout("Add dp successfully.\n")
|
||||
@ -944,15 +944,15 @@ func newVolAddMPCmd(client *master.MasterClient) *cobra.Command {
|
||||
defer func() {
|
||||
errout(err)
|
||||
}()
|
||||
var count int64
|
||||
if count, err = strconv.ParseInt(number, 10, 64); err != nil {
|
||||
var count int
|
||||
if count, err = strconv.Atoi(number); err != nil {
|
||||
return
|
||||
}
|
||||
if count < 1 {
|
||||
err = fmt.Errorf("number must be larger than 0")
|
||||
return
|
||||
}
|
||||
if err = client.AdminAPI().CreateMetaPartition(volume, int(count), clientIDKey); err != nil {
|
||||
if err = client.AdminAPI().CreateMetaPartition(volume, count, clientIDKey); err != nil {
|
||||
return
|
||||
}
|
||||
stdout("Add mp successfully.\n")
|
||||
|
||||
@ -835,7 +835,7 @@ func (s *DataNode) serveSmuxStream(stream *smux.Stream) {
|
||||
|
||||
func (s *DataNode) parseSmuxConfig(cfg *config.Config) error {
|
||||
s.enableSmuxConnPool = cfg.GetBool(ConfigKeyEnableSmuxClient)
|
||||
s.smuxPortShift = int(cfg.GetInt64(ConfigKeySmuxPortShift))
|
||||
s.smuxPortShift = cfg.GetInt(ConfigKeySmuxPortShift)
|
||||
if s.smuxPortShift == 0 {
|
||||
s.smuxPortShift = util.DefaultSmuxPortShift
|
||||
}
|
||||
|
||||
@ -306,13 +306,13 @@ func (s *DataNode) setDiskQos(w http.ResponseWriter, r *http.Request) {
|
||||
s.buildFailureResp(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
parser := func(key string) (val int64, err error, has bool) {
|
||||
parser := func(key string) (val int, err error, has bool) {
|
||||
valStr := r.FormValue(key)
|
||||
if valStr == "" {
|
||||
return 0, nil, false
|
||||
}
|
||||
has = true
|
||||
val, err = strconv.ParseInt(valStr, 10, 64)
|
||||
val, err = strconv.Atoi(valStr)
|
||||
return
|
||||
}
|
||||
|
||||
@ -332,7 +332,7 @@ func (s *DataNode) setDiskQos(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if has {
|
||||
updated = true
|
||||
*pVal = int(val)
|
||||
*pVal = val
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -428,6 +428,9 @@ func (td *TxDentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data := make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -442,6 +445,9 @@ func (td *TxDentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data = make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -513,6 +519,9 @@ func (td *TxUpdateDentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data := make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -527,6 +536,9 @@ func (td *TxUpdateDentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data = make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -541,6 +553,9 @@ func (td *TxUpdateDentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data = make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -592,6 +607,9 @@ func (d *Dentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &keyLen); err != nil {
|
||||
return
|
||||
}
|
||||
if keyLen > proto.MaxBufferSize {
|
||||
keyLen = proto.MaxBufferSize
|
||||
}
|
||||
keyBytes := make([]byte, keyLen)
|
||||
if _, err = buff.Read(keyBytes); err != nil {
|
||||
return
|
||||
@ -602,6 +620,9 @@ func (d *Dentry) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &valLen); err != nil {
|
||||
return
|
||||
}
|
||||
if valLen > proto.MaxBufferSize {
|
||||
valLen = proto.MaxBufferSize
|
||||
}
|
||||
valBytes := make([]byte, valLen)
|
||||
if _, err = buff.Read(valBytes); err != nil {
|
||||
return
|
||||
|
||||
@ -309,6 +309,9 @@ func (ti *TxInode) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data := make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -322,6 +325,9 @@ func (ti *TxInode) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &dataLen); err != nil {
|
||||
return
|
||||
}
|
||||
if dataLen > proto.MaxBufferSize {
|
||||
dataLen = proto.MaxBufferSize
|
||||
}
|
||||
data = make([]byte, int(dataLen))
|
||||
if _, err = buff.Read(data); err != nil {
|
||||
return
|
||||
@ -542,6 +548,9 @@ func (i *Inode) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &keyLen); err != nil {
|
||||
return
|
||||
}
|
||||
if keyLen > proto.MaxBufferSize {
|
||||
keyLen = proto.MaxBufferSize
|
||||
}
|
||||
keyBytes := make([]byte, keyLen)
|
||||
if _, err = buff.Read(keyBytes); err != nil {
|
||||
return
|
||||
@ -552,6 +561,9 @@ func (i *Inode) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &valLen); err != nil {
|
||||
return
|
||||
}
|
||||
if valLen > proto.MaxBufferSize {
|
||||
valLen = proto.MaxBufferSize
|
||||
}
|
||||
valBytes := make([]byte, valLen)
|
||||
if _, err = buff.Read(valBytes); err != nil {
|
||||
return
|
||||
@ -765,6 +777,9 @@ func (i *Inode) UnmarshalInodeValue(buff *bytes.Buffer) (err error) {
|
||||
return
|
||||
}
|
||||
if symSize > 0 {
|
||||
if symSize > proto.MaxBufferSize {
|
||||
symSize = proto.MaxBufferSize
|
||||
}
|
||||
i.LinkTarget = make([]byte, symSize)
|
||||
if _, err = io.ReadFull(buff, i.LinkTarget); err != nil {
|
||||
return
|
||||
@ -798,6 +813,9 @@ func (i *Inode) UnmarshalInodeValue(buff *bytes.Buffer) (err error) {
|
||||
return
|
||||
}
|
||||
if extSize > 0 {
|
||||
if extSize > proto.MaxBufferSize {
|
||||
extSize = proto.MaxBufferSize
|
||||
}
|
||||
extBytes := make([]byte, extSize)
|
||||
if _, err = io.ReadFull(buff, extBytes); err != nil {
|
||||
return
|
||||
@ -829,6 +847,9 @@ func (i *Inode) UnmarshalInodeValue(buff *bytes.Buffer) (err error) {
|
||||
return
|
||||
}
|
||||
if ObjExtSize > 0 {
|
||||
if ObjExtSize > proto.MaxBufferSize {
|
||||
ObjExtSize = proto.MaxBufferSize
|
||||
}
|
||||
objExtBytes := make([]byte, ObjExtSize)
|
||||
if _, err = io.ReadFull(buff, objExtBytes); err != nil {
|
||||
return
|
||||
|
||||
@ -90,6 +90,9 @@ func (qInode *MetaQuotaInode) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &inodeLen); err != nil {
|
||||
return
|
||||
}
|
||||
if inodeLen > proto.MaxBufferSize {
|
||||
inodeLen = proto.MaxBufferSize
|
||||
}
|
||||
inodeBytes := make([]byte, inodeLen)
|
||||
if _, err = buff.Read(inodeBytes); err != nil {
|
||||
return
|
||||
@ -142,6 +145,9 @@ func (qInode *TxMetaQuotaInode) Unmarshal(raw []byte) (err error) {
|
||||
if err = binary.Read(buff, binary.BigEndian, &inodeLen); err != nil {
|
||||
return
|
||||
}
|
||||
if inodeLen > proto.MaxBufferSize {
|
||||
inodeLen = proto.MaxBufferSize
|
||||
}
|
||||
inodeBytes := make([]byte, inodeLen)
|
||||
if _, err = buff.Read(inodeBytes); err != nil {
|
||||
return
|
||||
|
||||
@ -38,6 +38,7 @@ const (
|
||||
MinTxConflictRetryInterval = 10 // ms
|
||||
DefaultTxDeleteTime = 120
|
||||
ClearOrphanTxTime = 3600
|
||||
MaxBufferSize = 1024 * 1024 * 1024 // 1GB
|
||||
)
|
||||
|
||||
type TxOpMask uint8
|
||||
|
||||
Loading…
Reference in New Issue
Block a user