github-vet / github-vet/rangeloop-pointer-findings
Tencent/bk-cmdb: src/source_controller/coreservice/core/model/attribute.go; 53 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [Tencent/bk-cmdb](https://www.github.com/Tencent/bk-cmdb) at [src/source_controller/coreservice/core/model/attribute.go](https://github.com/Tencent/bk-cmdb/blob/4347923164dc5bdd2ecd166e58d00c5a394b5c10/src/source_controller/coreservice/core/model/attribute.go#L62-L114)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
>
[Click here to see the code in its original context.](https://github.com/Tencent/bk-cmdb/blob/4347923164dc5bdd2ecd166e58d00c5a394b5c10/src/source_controller/coreservice/core/model/attribute.go#L62-L114)
Click here to show the 53 line(s) of Go which triggered the analyzer.
```go
for attrIdx, attr := range inputParam.Attributes {
// fmt.Sprintf("coreservice:create:model:%s:attr:%s", objID, attr.PropertyID)
redisKey := lock.GetLockKey(lock.CreateModuleAttrFormat, objID, attr.PropertyID)
locker := lock.NewLocker(redis.Client())
looked, err := locker.Lock(redisKey, time.Second*35)
defer locker.Unlock()
if err != nil {
blog.ErrorJSON("create model error. get create look error. err:%s, input:%s, rid:%s", err.Error(), inputParam, kit.Rid)
addExceptionFunc(int64(attrIdx), kit.CCError.CCErrorf(common.CCErrCommRedisOPErr), &attr)
continue
}
if !looked {
blog.ErrorJSON("create model have same task in progress. input:%s, rid:%s", inputParam, kit.Rid)
addExceptionFunc(int64(attrIdx), kit.CCError.CCErrorf(common.CCErrCommOPInProgressErr, fmt.Sprintf("create object(%s) attribute(%s)", attr.ObjectID, attr.PropertyName)), &attr)
continue
}
if attr.IsPre {
if attr.PropertyID == common.BKInstNameField {
language := util.GetLanguage(kit.Header)
lang := m.language.CreateDefaultCCLanguageIf(language)
attr.PropertyName = util.FirstNotEmptyString(lang.Language("common_property_"+attr.PropertyID), attr.PropertyName, attr.PropertyID)
}
}
attr.OwnerID = kit.SupplierAccount
_, exists, err := m.isExists(kit, attr.ObjectID, attr.PropertyID, attr.BizID)
blog.V(5).Infof("CreateModelAttributes isExists info. property id:%s, bizID:%#v, exit:%v, rid:%s", attr.PropertyID, attr.BizID, exists, kit.Rid)
if nil != err {
blog.Errorf("CreateModelAttributes failed, attribute field propertyID(%s) exists, err: %s, rid: %s", attr.PropertyID, err.Error(), kit.Rid)
addExceptionFunc(int64(attrIdx), err.(errors.CCErrorCoder), &attr)
continue
}
if exists {
dataResult.CreateManyInfoResult.Repeated = append(dataResult.CreateManyInfoResult.Repeated, metadata.RepeatedDataResult{
OriginIndex: int64(attrIdx),
Data: mapstr.NewFromStruct(attr, "field"),
})
continue
}
id, err := m.save(kit, attr)
if nil != err {
blog.Errorf("CreateModelAttributes failed, failed to save the attribute(%#v), err: %s, rid: %s", attr, err.Error(), kit.Rid)
addExceptionFunc(int64(attrIdx), err.(errors.CCErrorCoder), &attr)
continue
}
dataResult.CreateManyInfoResult.Created = append(dataResult.CreateManyInfoResult.Created, metadata.CreatedDataResult{
OriginIndex: int64(attrIdx),
ID: id,
})
}
```
Click here to show extra information the analyzer produced.
```
No path was found through the callgraph that could lead to a function which writes a pointer argument.
No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.
root signature {addExceptionFunc 3} was not found in the callgraph; reference was passed directly to third-party code
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 4347923164dc5bdd2ecd166e58d00c5a394b5c10
Contributor guide
No contributing guide indexed for this repository
Research direction
Review src/source_controller/coreservice/core/model/attribute.go at lines 62-114, focusing on the range loop and the analyzer's pointer-capture report. Determine whether the finding is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction on this issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100