Re: [libosinfo PATCH 2/3] os: Deal with a NULL profile on _find_install_script()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 23, 2018 at 01:49:54PM +0100, Fabiano Fidêncio wrote:
> Let's ensure we're not going to crash in case a NULL profile is passed
> for osinfo_find_install_script().
> 
> Also, document which are the expected values for @profile
> ---
>  osinfo/osinfo_os.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
> index 9328820..314b4d8 100644
> --- a/osinfo/osinfo_os.c
> +++ b/osinfo/osinfo_os.c
> @@ -956,17 +956,25 @@ void osinfo_os_add_maximum_resources(OsinfoOs *os,
>  /**
>   * osinfo_os_find_install_script:
>   * @os:      an operating system
> - * @profile: the install script profile
> + * @profile: the install script profile that must be either
> + * OSINFO_INSTALL_SCRIPT_PROFILE_DESKTOP or OSINFO_INSTALL_SCRIPT_PROFILE_JEOS
>   *
>   * Returns: (transfer full): A new #OsinfoInstallScript for the @os @profile
>   */
>  OsinfoInstallScript *osinfo_os_find_install_script(OsinfoOs *os, const gchar *profile)
>  {
> -    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
> -    GList *scripts = osinfo_list_get_elements(OSINFO_LIST(os->priv->scripts));
> -    GList *tmp = scripts;
> +    GList *scripts;
> +    GList *tmp;
>      OsinfoInstallScript *script = NULL;
>  
> +    g_return_val_if_fail(OSINFO_IS_OS(os), NULL);
> +
> +    scripts = osinfo_list_get_elements(OSINFO_LIST(os->priv->scripts));
> +    tmp = scripts;
> +
> +    if (profile == NULL)
> +        return script;
> +

Since 'NULL' is not a valid value, shouldn't this be
g_return_val_if_fail (profile != NULL, NULL);
?

>      while (tmp) {
>          script = tmp->data;
>          if (g_str_equal(profile, osinfo_install_script_get_profile(script)))
> -- 
> 2.19.1
> 
> _______________________________________________
> Libosinfo mailing list
> Libosinfo@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libosinfo

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux