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

Christophe Fergeau cfergeau at redhat.com
Mon Dec 10 12:29:53 UTC 2018


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 at redhat.com
> https://www.redhat.com/mailman/listinfo/libosinfo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libosinfo/attachments/20181210/9c5edb9d/attachment.sig>


More information about the Libosinfo mailing list