redfish: Fix crash when specifying a URL without a port

This commit is contained in:
Richard Hughes 2021-11-11 14:20:34 +00:00
parent 23e194413a
commit 5a95cf61d8

View File

@ -304,30 +304,33 @@ fu_plugin_redfish_startup(FuPlugin *plugin, GError **error)
if (redfish_uri != NULL) { if (redfish_uri != NULL) {
const gchar *ip_str = NULL; const gchar *ip_str = NULL;
g_auto(GStrv) split = NULL; g_auto(GStrv) split = NULL;
guint64 port; guint64 port = 0;
if (g_str_has_prefix(redfish_uri, "https://")) { if (g_str_has_prefix(redfish_uri, "https://")) {
fu_redfish_backend_set_https(data->backend, TRUE); fu_redfish_backend_set_https(data->backend, TRUE);
ip_str = redfish_uri + strlen("https://"); ip_str = redfish_uri + strlen("https://");
port = 443;
} else if (g_str_has_prefix(redfish_uri, "http://")) { } else if (g_str_has_prefix(redfish_uri, "http://")) {
fu_redfish_backend_set_https(data->backend, FALSE); fu_redfish_backend_set_https(data->backend, FALSE);
ip_str = redfish_uri + strlen("http://"); ip_str = redfish_uri + strlen("http://");
port = 80;
} else { } else {
g_set_error_literal(error, g_set_error_literal(error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"in valid scheme"); "invalid scheme");
return FALSE; return FALSE;
} }
split = g_strsplit(ip_str, ":", 2); split = g_strsplit(ip_str, ":", 2);
fu_redfish_backend_set_hostname(data->backend, split[0]); fu_redfish_backend_set_hostname(data->backend, split[0]);
port = g_ascii_strtoull(split[1], NULL, 10); if (g_strv_length(split) > 1)
if (port == 0) { port = g_ascii_strtoull(split[1], NULL, 10);
if (port == 0 || port == G_MAXUINT64) {
g_set_error_literal(error, g_set_error_literal(error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"no port specified"); "no valid port specified");
return FALSE; return FALSE;
} }
fu_redfish_backend_set_port(data->backend, port); fu_redfish_backend_set_port(data->backend, port);