Harden the OLLAMA_HOST lookup for quotes

This commit is contained in:
Daniel Hiltgen 2024-02-15 13:46:56 -08:00
parent fefb3e77d1
commit 4a10e7a7fa

View file

@ -685,7 +685,7 @@ func generate(cmd *cobra.Command, opts runOptions) error {
} }
func RunServer(cmd *cobra.Command, _ []string) error { func RunServer(cmd *cobra.Command, _ []string) error {
host, port, err := net.SplitHostPort(os.Getenv("OLLAMA_HOST")) host, port, err := net.SplitHostPort(strings.Trim(os.Getenv("OLLAMA_HOST"), "\"'"))
if err != nil { if err != nil {
host, port = "127.0.0.1", "11434" host, port = "127.0.0.1", "11434"
if ip := net.ParseIP(strings.Trim(os.Getenv("OLLAMA_HOST"), "[]")); ip != nil { if ip := net.ParseIP(strings.Trim(os.Getenv("OLLAMA_HOST"), "[]")); ip != nil {