newContainer creates and returns a container The fuzzer decides how the container is created
(ctx context.Context, client *containerd.Client, f *fuzz.ConsumeFuzzer)
| 271 | // newContainer creates and returns a container |
| 272 | // The fuzzer decides how the container is created |
| 273 | func newContainer(ctx context.Context, client *containerd.Client, f *fuzz.ConsumeFuzzer) (containerd.Container, error) { |
| 274 | // determiner determines how we should create the container |
| 275 | determiner, err := f.GetInt() |
| 276 | if err != nil { |
| 277 | return nil, err |
| 278 | } |
| 279 | id, err := f.GetString() |
| 280 | if err != nil { |
| 281 | return nil, err |
| 282 | } |
| 283 | |
| 284 | switch remainder := determiner % 3; remainder { |
| 285 | case 0: |
| 286 | // Create a container with oci specs |
| 287 | spec := &oci.Spec{} |
| 288 | err = f.GenerateStruct(spec) |
| 289 | if err != nil { |
| 290 | return nil, err |
| 291 | } |
| 292 | container, err := client.NewContainer(ctx, id, |
| 293 | containerd.WithSpec(spec)) |
| 294 | if err != nil { |
| 295 | return nil, err |
| 296 | } |
| 297 | return container, nil |
| 298 | case 1: |
| 299 | // Create a container with fuzzed oci specs |
| 300 | // and an image |
| 301 | image, err := getImage(client, f) |
| 302 | if err != nil { |
| 303 | return nil, err |
| 304 | } |
| 305 | // Fuzz a few image APIs |
| 306 | _, _ = image.Size(ctx) |
| 307 | checkAndDoUnpack(ctx, image, f) |
| 308 | |
| 309 | spec := &oci.Spec{} |
| 310 | err = f.GenerateStruct(spec) |
| 311 | if err != nil { |
| 312 | return nil, err |
| 313 | } |
| 314 | container, err := client.NewContainer(ctx, |
| 315 | id, |
| 316 | containerd.WithImage(image), |
| 317 | containerd.WithSpec(spec)) |
| 318 | if err != nil { |
| 319 | return nil, err |
| 320 | } |
| 321 | return container, nil |
| 322 | default: |
| 323 | // Create a container with an image |
| 324 | image, err := getImage(client, f) |
| 325 | if err != nil { |
| 326 | return nil, err |
| 327 | } |
| 328 | // Fuzz a few image APIs |
| 329 | _, _ = image.Size(ctx) |
| 330 | checkAndDoUnpack(ctx, image, f) |
no test coverage detected
searching dependent graphs…