How to use allocAddr method of prog Package

Best Syzkaller code snippet using prog.allocAddr

mutation.go

Source:mutation.go Github

copy

Full Screen

...121 arg.data = mutateData(r, arg.Data(), 0, maxBlobLen)122 // Update base pointer if size has increased.123 if baseSize < base.Res.Size() {124 s := analyze(ctx.ct, p, p.Calls[0])125 newArg := r.allocAddr(s, base.Type(), base.Res.Size(), base.Res)126 *base = *newArg127 }128 return true129}130func (ctx *mutator) insertCall() bool {131 p, r := ctx.p, ctx.r132 if len(p.Calls) >= ctx.ncalls {133 return false134 }135 idx := r.biasedRand(len(p.Calls)+1, 5)136 var c *Call137 if idx < len(p.Calls) {138 c = p.Calls[idx]139 }140 s := analyze(ctx.ct, p, c)141 calls := r.generateCall(s, p)142 p.insertBefore(c, calls)143 return true144}145func (ctx *mutator) removeCall() bool {146 p, r := ctx.p, ctx.r147 if len(p.Calls) == 0 {148 return false149 }150 idx := r.Intn(len(p.Calls))151 p.RemoveCall(idx)152 return true153}154func (ctx *mutator) mutateArg() bool {155 p, r := ctx.p, ctx.r156 if len(p.Calls) == 0 {157 return false158 }159 c := p.Calls[r.Intn(len(p.Calls))]160 if len(c.Args) == 0 {161 return false162 }163 s := analyze(ctx.ct, p, c)164 updateSizes := true165 for stop, ok := false, false; !stop; stop = ok && r.oneOf(3) {166 ok = true167 ma := &mutationArgs{target: p.Target}168 ForeachArg(c, ma.collectArg)169 if len(ma.args) == 0 {170 return false171 }172 idx := r.Intn(len(ma.args))173 arg, ctx := ma.args[idx], ma.ctxes[idx]174 calls, ok1 := p.Target.mutateArg(r, s, arg, ctx, &updateSizes)175 if !ok1 {176 ok = false177 continue178 }179 p.insertBefore(c, calls)180 if updateSizes {181 p.Target.assignSizesCall(c)182 }183 p.Target.SanitizeCall(c)184 }185 return true186}187func (target *Target) mutateArgForDependencyResource(r *randGen, s *state, arg Arg, ctx ArgCtx, updateSizes *bool) ([]*Call, bool) {188 var baseSize uint64189 if ctx.Base != nil {190 baseSize = ctx.Base.Res.Size()191 }192 calls, retry, preserve := arg.Type().mutate(r, s, arg, ctx)193 if retry {194 return nil, false195 }196 if preserve {197 *updateSizes = false198 }199 // Update base pointer if size has increased.200 if base := ctx.Base; base != nil && baseSize < base.Res.Size() {201 newArg := r.allocAddr(s, base.Type(), base.Res.Size(), base.Res)202 replaceArg(base, newArg)203 }204 for _, c := range calls {205 target.SanitizeCall(c)206 }207 return calls, true208}209func (target *Target) mutateArg(r *randGen, s *state, arg Arg, ctx ArgCtx, updateSizes *bool) ([]*Call, bool) {210 var baseSize uint64211 if ctx.Base != nil {212 baseSize = ctx.Base.Res.Size()213 }214 calls, retry, preserve := arg.Type().mutate(r, s, arg, ctx)215 if retry {216 return nil, false217 }218 if preserve {219 *updateSizes = false220 }221 // Update base pointer if size has increased.222 if base := ctx.Base; base != nil && baseSize < base.Res.Size() {223 newArg := r.allocAddr(s, base.Type(), base.Res.Size(), base.Res)224 replaceArg(base, newArg)225 }226 for _, c := range calls {227 target.SanitizeCall(c)228 }229 return calls, true230}231func regenerate(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve bool) {232 var newArg Arg233 newArg, calls = r.generateArg(s, arg.Type())234 replaceArg(arg, newArg)235 return236}237func mutateInt(r *randGen, s *state, arg Arg) (calls []*Call, retry, preserve bool) {238 if r.bin() {239 return regenerate(r, s, arg)240 }241 a := arg.(*ConstArg)242 switch {243 case r.nOutOf(1, 3):244 a.Val += uint64(r.Intn(4)) + 1245 case r.nOutOf(1, 2):246 a.Val -= uint64(r.Intn(4)) + 1247 default:248 a.Val ^= 1 << uint64(r.Intn(64))249 }250 return251}252func (t *IntType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {253 return mutateInt(r, s, arg)254}255func (t *FlagsType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {256 return mutateInt(r, s, arg)257}258func (t *LenType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {259 if !r.mutateSize(arg.(*ConstArg), *ctx.Parent) {260 retry = true261 return262 }263 preserve = true264 return265}266func (t *ResourceType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {267 return regenerate(r, s, arg)268}269func (t *VmaType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {270 return regenerate(r, s, arg)271}272func (t *ProcType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {273 return regenerate(r, s, arg)274}275func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {276 a := arg.(*DataArg)277 switch t.Kind {278 case BufferBlobRand, BufferBlobRange:279 data := append([]byte{}, a.Data()...)280 minLen, maxLen := uint64(0), maxBlobLen281 if t.Kind == BufferBlobRange {282 minLen, maxLen = t.RangeBegin, t.RangeEnd283 }284 a.data = mutateData(r, data, minLen, maxLen)285 case BufferString:286 data := append([]byte{}, a.Data()...)287 if r.bin() {288 minLen, maxLen := uint64(0), maxBlobLen289 if t.TypeSize != 0 {290 minLen, maxLen = t.TypeSize, t.TypeSize291 }292 a.data = mutateData(r, data, minLen, maxLen)293 } else {294 a.data = r.randString(s, t)295 }296 case BufferFilename:297 a.data = []byte(r.filename(s, t))298 case BufferText:299 data := append([]byte{}, a.Data()...)300 a.data = r.mutateText(t.Text, data)301 default:302 panic("unknown buffer kind")303 }304 return305}306func (t *ArrayType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {307 // TODO: swap elements of the array308 a := arg.(*GroupArg)309 count := uint64(0)310 switch t.Kind {311 case ArrayRandLen:312 for count == uint64(len(a.Inner)) {313 count = r.randArrayLen()314 }315 case ArrayRangeLen:316 if t.RangeBegin == t.RangeEnd {317 panic("trying to mutate fixed length array")318 }319 for count == uint64(len(a.Inner)) {320 count = r.randRange(t.RangeBegin, t.RangeEnd)321 }322 }323 if count > uint64(len(a.Inner)) {324 for count > uint64(len(a.Inner)) {325 newArg, newCalls := r.generateArg(s, t.Type)326 a.Inner = append(a.Inner, newArg)327 calls = append(calls, newCalls...)328 for _, c := range newCalls {329 s.analyze(c)330 }331 }332 } else if count < uint64(len(a.Inner)) {333 for _, arg := range a.Inner[count:] {334 removeArg(arg)335 }336 a.Inner = a.Inner[:count]337 }338 return339}340func (t *PtrType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {341 a := arg.(*PointerArg)342 if r.oneOf(1000) {343 removeArg(a.Res)344 index := r.rand(len(r.target.SpecialPointers))345 newArg := MakeSpecialPointerArg(t, index)346 replaceArg(arg, newArg)347 return348 }349 newArg := r.allocAddr(s, t, a.Res.Size(), a.Res)350 replaceArg(arg, newArg)351 return352}353func (t *StructType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []*Call, retry, preserve bool) {354 gen := r.target.SpecialTypes[t.Name()]355 if gen == nil {356 panic("bad arg returned by mutationArgs: StructType")357 }358 var newArg Arg359 newArg, calls = gen(&Gen{r, s}, t, arg)360 a := arg.(*GroupArg)361 for i, f := range newArg.(*GroupArg).Inner {362 replaceArg(a.Inner[i], f)363 }...

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import (2type prog struct {3}4func (p *prog) allocAddr() uintptr {5 return uintptr(unsafe.Pointer(p))6}7func main() {8 p := &prog{"Go", 1.12}9 fmt.Println("Address of p is", p.allocAddr())10}

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import (2type prog struct {3}4func (p *prog) allocAddr() unsafe.Pointer {5 return unsafe.Pointer(p)6}7func main() {8 p := &prog{lang: "Go"}9 fmt.Println(p.allocAddr())10}

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 size, _ := strconv.Atoi(os.Args[1])4 addr, _ := strconv.Atoi(os.Args[2])5 prog.allocAddr(size, addr)6}7import (8func main() {9 size, _ := strconv.Atoi(os.Args[1])10 addr, _ := strconv.Atoi(os.Args[2])11 prog.allocAddr(size, addr)12}13import (14func main() {15 size, _ := strconv.Atoi(os.Args[1])16 addr, _ := strconv.Atoi(os.Args[2])17 prog.allocAddr(size, addr)18}19import (20func main() {21 size, _ := strconv.Atoi(os.Args[1])22 addr, _ := strconv.Atoi(os.Args[2])23 prog.allocAddr(size, addr)24}25import (26func main() {27 size, _ := strconv.Atoi(os.Args[1])28 addr, _ := strconv.Atoi(os.Args[2])

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import (2type prog struct {3}4func main() {5 fmt.Println("Hello, playground")6 fmt.Println(p)

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p.allocAddr()4 fmt.Println(p.addr)5}6&{1 2 3 4}7import "fmt"8func main() {9 p.allocAddr()10 fmt.Println(*p.addr)11}

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3p = prog.allocAddr()4fmt.Println(*p)5}6type prog struct {7}8func (*prog) allocAddr() *int {9}10cannot use prog.allocAddr() (type *int) as type *int in assignment

Full Screen

Full Screen

allocAddr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 p := new(prog)4 p.allocAddr(100)5 p.freeAddr()6}7import "unsafe"8type prog struct {9}10func (p *prog) allocAddr(size int) {11 p.addr = uintptr(unsafe.Pointer(new([100]int)))12}13func (p *prog) freeAddr() {14}15import "fmt"16func main() {17 p := new(prog)18 p.AllocAddr(100)19 p.FreeAddr()20}21import "unsafe"22type prog struct {23}24func (p *prog) AllocAddr(size int) {25 p.addr = uintptr(unsafe.Pointer(new([100]int)))26}27func (p *prog) FreeAddr() {28}29import "fmt"30func main() {31 p := new(prog)32 p.AllocAddr(100)33 p.FreeAddr()34}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful