mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix out of bound slice access in Delete()
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
parent
d734bc5807
commit
82f3d55fa4
2 changed files with 27 additions and 0 deletions
|
@ -159,6 +159,10 @@ func Delete(path string, recs []Record) error {
|
|||
loop:
|
||||
for s.Scan() {
|
||||
b := s.Bytes()
|
||||
if len(b) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if b[0] == '#' {
|
||||
buf.Write(b)
|
||||
buf.Write(eol)
|
||||
|
|
|
@ -331,6 +331,29 @@ func TestDeleteEmpty(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDeleteNewline(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
b := []byte("\n")
|
||||
if _, err := file.Write(b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rec := []Record{
|
||||
{
|
||||
Hosts: "prefix",
|
||||
IP: "2.2.2.2",
|
||||
},
|
||||
}
|
||||
if err := Delete(file.Name(), rec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
file, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue