mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-21 12:01:00 +00:00

Currently we have unix permissions for new files/dirs hardcoded throughout the code base. Some places use 0644, some - 0640, some - 0600 and a variety of other constants. Introduce osutil.MkdirAll/WriteFile that use the default permissions and use them throughout the code base. This makes permissions consistent and also allows to easily change the permissions later if we change our minds. Also merge pkg/fileutil into pkg/osutil as they become dependent on each other. The line between them was poorly defined anyway as both operate on files.
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
// Copyright 2015 syzkaller project authors. All rights reserved.
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
// upgrade upgrades corpus from an old format to a new format.
|
|
// Upgrade is not fully automatic. You need to update prog.Serialize.
|
|
// Run the tool. Then update prog.Deserialize. And run the tool again that
|
|
// the corpus is not changed this time.
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha1"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/google/syzkaller/pkg/osutil"
|
|
"github.com/google/syzkaller/prog"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) != 2 {
|
|
fatalf("usage: syz-upgrage corpus_dir")
|
|
}
|
|
files, err := ioutil.ReadDir(os.Args[1])
|
|
if err != nil {
|
|
fatalf("failed to read corpus dir: %v", err)
|
|
}
|
|
for _, f := range files {
|
|
fname := filepath.Join(os.Args[1], f.Name())
|
|
data, err := ioutil.ReadFile(fname)
|
|
if err != nil {
|
|
fatalf("failed to read program: %v", err)
|
|
}
|
|
p, err := prog.Deserialize(data)
|
|
if err != nil {
|
|
fatalf("failed to deserialize program: %v", err)
|
|
}
|
|
data1 := p.Serialize()
|
|
if bytes.Equal(data, data1) {
|
|
continue
|
|
}
|
|
fmt.Printf("upgrading:\n%s\nto:\n%s\n\n", data, data1)
|
|
hash := sha1.Sum(data1)
|
|
fname1 := filepath.Join(os.Args[1], hex.EncodeToString(hash[:]))
|
|
if err := osutil.WriteFile(fname1, data1); err != nil {
|
|
fatalf("failed to write program: %v", err)
|
|
}
|
|
if err := os.Remove(fname); err != nil {
|
|
fatalf("failed to remove program: %v", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func fatalf(msg string, args ...interface{}) {
|
|
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
|
os.Exit(1)
|
|
}
|