mirror of
https://github.com/containers/podman.git
synced 2025-07-27 10:22:49 +08:00
Merge pull request #2651 from mheon/prevent_null_deref
Fix a potential segfault in podman search
This commit is contained in:
@ -83,11 +83,25 @@ func searchCmd(c *cliconfig.SearchValues) error {
|
|||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
out := formats.StdoutTemplateArray{Output: searchToGeneric(results), Template: format, Fields: genSearchOutputMap()}
|
out := formats.StdoutTemplateArray{Output: searchToGeneric(results), Template: format, Fields: searchHeaderMap()}
|
||||||
formats.Writer(out).Out()
|
formats.Writer(out).Out()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// searchHeaderMap returns the headers of a SearchResult.
|
||||||
|
func searchHeaderMap() map[string]string {
|
||||||
|
s := new(image.SearchResult)
|
||||||
|
v := reflect.Indirect(reflect.ValueOf(s))
|
||||||
|
values := make(map[string]string, v.NumField())
|
||||||
|
|
||||||
|
for i := 0; i < v.NumField(); i++ {
|
||||||
|
key := v.Type().Field(i).Name
|
||||||
|
value := key
|
||||||
|
values[key] = strings.ToUpper(splitCamelCase(value))
|
||||||
|
}
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
func genSearchFormat(format string) string {
|
func genSearchFormat(format string) string {
|
||||||
if format != "" {
|
if format != "" {
|
||||||
// "\t" from the command line is not being recognized as a tab
|
// "\t" from the command line is not being recognized as a tab
|
||||||
|
@ -2,7 +2,6 @@ package image
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -10,7 +9,6 @@ import (
|
|||||||
"github.com/containers/image/docker"
|
"github.com/containers/image/docker"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
sysreg "github.com/containers/libpod/pkg/registries"
|
sysreg "github.com/containers/libpod/pkg/registries"
|
||||||
"github.com/fatih/camelcase"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sync/semaphore"
|
"golang.org/x/sync/semaphore"
|
||||||
@ -63,24 +61,6 @@ type SearchFilter struct {
|
|||||||
IsOfficial types.OptionalBool
|
IsOfficial types.OptionalBool
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitCamelCase(src string) string {
|
|
||||||
entries := camelcase.Split(src)
|
|
||||||
return strings.Join(entries, " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// HeaderMap returns the headers of a SearchResult.
|
|
||||||
func (s *SearchResult) HeaderMap() map[string]string {
|
|
||||||
v := reflect.Indirect(reflect.ValueOf(s))
|
|
||||||
values := make(map[string]string, v.NumField())
|
|
||||||
|
|
||||||
for i := 0; i < v.NumField(); i++ {
|
|
||||||
key := v.Type().Field(i).Name
|
|
||||||
value := key
|
|
||||||
values[key] = strings.ToUpper(splitCamelCase(value))
|
|
||||||
}
|
|
||||||
return values
|
|
||||||
}
|
|
||||||
|
|
||||||
// SearchImages searches images based on term and the specified SearchOptions
|
// SearchImages searches images based on term and the specified SearchOptions
|
||||||
// in all registries.
|
// in all registries.
|
||||||
func SearchImages(term string, options SearchOptions) ([]SearchResult, error) {
|
func SearchImages(term string, options SearchOptions) ([]SearchResult, error) {
|
||||||
|
Reference in New Issue
Block a user