github-vet / github-vet/rangeloop-pointer-findings
omegaup/quark: runner/runner.go; 228 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [omegaup/quark](https://www.github.com/omegaup/quark) at [runner/runner.go](https://github.com/omegaup/quark/blob/f599eefc3b950d049188efd89651341c528465de/runner/runner.go#L902-L1129)
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/omegaup/quark/blob/f599eefc3b950d049188efd89651341c528465de/runner/runner.go#L902-L1129)
Click here to show the 228 line(s) of Go which triggered the analyzer.
```go
for j, caseData := range group.Cases {
var runMeta *RunMetadata
var individualMeta = make(map[string]RunMetadata)
if runResult.WallTime > settings.Limits.OverallWallTimeLimit.Seconds() {
ctx.Log.Debug(
"Not even running since the wall time limit has been exceeded",
"case", caseData.Name,
"wall time", runResult.WallTime,
"limit", settings.Limits.OverallWallTimeLimit.Seconds(),
)
runMeta = &RunMetadata{
Verdict: "TLE",
}
} else if run.Language == "cat" {
outName := fmt.Sprintf("%s.out", caseData.Name)
errName := fmt.Sprintf("%s.err", caseData.Name)
metaName := fmt.Sprintf("%s.meta", caseData.Name)
outPath := path.Join(runRoot, outName)
metaPath := path.Join(runRoot, metaName)
if file, ok := outputOnlyFiles[outName]; ok {
if err := ioutil.WriteFile(outPath, []byte(file.contents), 0644); err != nil {
ctx.Log.Error(
"failed to write output file contents",
"case", caseData.Name,
"path", outPath,
"err", err,
)
}
runMeta = &RunMetadata{
Verdict: "OK",
}
if file.ole {
runMeta.Verdict = "OLE"
}
if err := ioutil.WriteFile(metaPath, []byte("status:0"), 0644); err != nil {
ctx.Log.Error(
"failed to write meta file",
"case", caseData.Name,
"path", metaPath,
"err", err,
)
}
} else {
ctx.Log.Error(
"missing an output file",
"case", caseData.Name,
"path", outPath,
)
if err := ioutil.WriteFile(outPath, []byte{}, 0644); err != nil {
ctx.Log.Error(
"failed to write output file",
"case", caseData.Name,
"path", outPath,
"err", err,
)
}
runMeta = &RunMetadata{
Verdict: "RTE",
}
if err := ioutil.WriteFile(metaPath, []byte("status:1"), 0644); err != nil {
ctx.Log.Error(
"failed to write meta file",
"case", caseData.Name,
"path", metaPath,
"err", err,
)
}
}
errPath := path.Join(runRoot, errName)
if err := ioutil.WriteFile(errPath, []byte{}, 0644); err != nil {
ctx.Log.Error(
"failed to write err file",
"case", caseData.Name,
"path", metaPath,
"err", err,
)
}
generatedFiles = append(generatedFiles, outName, errName, metaName)
} else {
singleRunEvent := ctx.EventFactory.NewCompleteEvent(caseData.Name)
metaChan := make(chan intermediateRunResult, regularBinaryCount)
for _, bin := range binaries {
if bin.binaryType == binaryValidator {
continue
}
go func(bin *binary, caseData *common.CaseSettings) {
var inputPath string
if bin.receiveInput {
inputPath = path.Join(
input.Path(),
"cases",
fmt.Sprintf("%s.in", caseData.Name),
)
} else {
inputPath = "/dev/null"
}
extraParams := make([]string, 0)
if bin.binaryType == binaryProblemsetter {
extraParams = append(extraParams, caseData.Name, run.Language)
}
singleBinary := ctx.EventFactory.NewCompleteEvent(
fmt.Sprintf("%s - %s", caseData.Name, bin.name),
)
runMeta, err := sandbox.Run(
ctx,
&bin.limits,
bin.language,
bin.binPath,
inputPath,
path.Join(
runRoot,
bin.outputPathPrefix,
fmt.Sprintf("%s.out", caseData.Name),
),
path.Join(
runRoot,
bin.outputPathPrefix,
fmt.Sprintf("%s.err", caseData.Name),
),
path.Join(
runRoot,
bin.outputPathPrefix,
fmt.Sprintf("%s.meta", caseData.Name),
),
bin.target,
nil,
nil,
nil,
extraParams,
bin.extraMountPoints,
)
if err != nil {
ctx.Log.Error(
"failed to run",
"caseName", caseData.Name,
"interface", bin.name,
"err", err,
)
}
generatedFiles := []string{
path.Join(
bin.outputPathPrefix,
fmt.Sprintf("%s.out", caseData.Name),
),
path.Join(
bin.outputPathPrefix,
fmt.Sprintf("%s.err", caseData.Name),
),
path.Join(
bin.outputPathPrefix,
fmt.Sprintf("%s.meta", caseData.Name),
),
}
ctx.EventCollector.Add(singleBinary)
metaChan <- intermediateRunResult{
bin.name,
runMeta,
bin.binaryType,
generatedFiles,
}
}(bin, &caseData)
}
var parentMetadata *RunMetadata
chosenMetadata := RunMetadata{
Verdict: "OK",
}
chosenMetadataEmpty := true
var finalVerdict = "OK"
var totalTime float64
var totalWallTime float64
var totalMemory base.Byte
for i := 0; i < regularBinaryCount; i++ {
intermediateResult := <-metaChan
generatedFiles = append(generatedFiles, intermediateResult.generatedFiles...)
if regularBinaryCount != 1 {
// Only populate invidualMeta if there is more than one binary.
individualMeta[intermediateResult.name] = *intermediateResult.runMeta
}
if intermediateResult.binaryType == binaryProblemsetter {
parentMetadata = intermediateResult.runMeta
} else {
if intermediateResult.runMeta.Verdict != "OK" {
if chosenMetadataEmpty {
chosenMetadata = *intermediateResult.runMeta
chosenMetadataEmpty = false
}
}
finalVerdict = worseVerdict(
finalVerdict,
intermediateResult.runMeta.Verdict,
)
totalTime += intermediateResult.runMeta.Time
totalWallTime = math.Max(
totalWallTime,
intermediateResult.runMeta.WallTime,
)
totalMemory += base.MaxBytes(totalMemory, intermediateResult.runMeta.Memory)
}
}
close(metaChan)
ctx.EventCollector.Add(singleRunEvent)
chosenMetadata.Verdict = finalVerdict
chosenMetadata.Time = totalTime
chosenMetadata.WallTime = totalWallTime
chosenMetadata.Memory = totalMemory
runMeta = mergeVerdict(ctx, &chosenMetadata, parentMetadata)
}
runResult.Verdict = worseVerdict(runResult.Verdict, runMeta.Verdict)
runResult.Time += runMeta.Time
runResult.WallTime += runMeta.WallTime
runResult.Memory = base.MaxBytes(runResult.Memory, runMeta.Memory)
// TODO: change CaseResult to split original metadatas and final metadata
caseResults[j] = CaseResult{
Name: caseData.Name,
Verdict: runMeta.Verdict,
Meta: *runMeta,
IndividualMeta: individualMeta,
Score: &big.Rat{},
ContestScore: &big.Rat{},
MaxScore: new(big.Rat).Mul(
runResult.MaxScore,
new(big.Rat).Mul(caseData.Weight, totalWeightFactor),
),
}
}
```
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 { 2} 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: f599eefc3b950d049188efd89651341c528465de
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.