mirror of https://github.com/docker/cli.git
service: Avoid underflow in logs padding calculation
This command inserts a variable amount of padding in the log line: padding := strings.Repeat(" ", f.padding-getMaxLength(task.Slot)) If the service is scaled up, or the slot numbers are noncontiguous, the subtraction can underflow, causing a crash. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
a2225276af
commit
ab6bc5dce6
|
@ -204,8 +204,12 @@ func (f *taskFormatter) format(ctx context.Context, logCtx logContext) (string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
padding := strings.Repeat(" ", f.padding-getMaxLength(task.Slot))
|
paddingCount := f.padding - getMaxLength(task.Slot)
|
||||||
formatted := fmt.Sprintf("%s@%s%s", taskName, nodeName, padding)
|
padding := ""
|
||||||
|
if paddingCount > 0 {
|
||||||
|
padding = strings.Repeat(" ", paddingCount)
|
||||||
|
}
|
||||||
|
formatted := taskName + "@" + nodeName + padding
|
||||||
f.cache[logCtx] = formatted
|
f.cache[logCtx] = formatted
|
||||||
return formatted, nil
|
return formatted, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue