poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Check return value of pk_str_concat


From: Jose E. Marchesi
Subject: Re: [PATCH] Check return value of pk_str_concat
Date: Wed, 06 May 2020 16:39:25 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Tim.

    diff --git a/libpoke/pkl-fold.c b/libpoke/pkl-fold.c
    index 64feffdb..44bc2898 100644
    --- a/libpoke/pkl-fold.c
    +++ b/libpoke/pkl-fold.c
    @@ -586,6 +586,8 @@ EMUL_UU (bnoto) { return ~op; }
                                                                             \
               res = pk_str_concat (PKL_AST_STRING_POINTER (op1),            \
                                    PKL_AST_STRING_POINTER (op2), NULL);     \
    +          if (!res)                                                     \
    +            PKL_PASS_DONE;                                              \


That's not the right thing to do: PKL_PASS_DONE will basically continue
the compilation process.

IMO when compiler code finds an out-of-memory condition, it should raise
an ICE, i.e. to call pkl_ice.

Right now pkl_ice aborts the process, but we can change it in the future
to longjump to the out_of_memory label you are introducing:

               new = pkl_ast_make_string (PKL_PASS_AST, res);                \
               free (res);                                                   \
    diff --git a/libpoke/pkl.c b/libpoke/pkl.c
    index 3b6ae369..aeb6ecc9 100644
    --- a/libpoke/pkl.c
    +++ b/libpoke/pkl.c
    @@ -79,6 +79,16 @@ pkl_new (pvm vm, const char *rt_path)
          error and should be reported as such.  */
       {
         char *poke_rt_pk = pk_str_concat (rt_path, "/pkl-rt.pk", NULL);
    +    if (!poke_rt_pk)
    +      {
    +out_of_memory:
    +        pk_term_class ("error");
    +        pk_puts ("error: ");
    +        pk_term_end_class ("error");
    +        pk_puts ("out of memory\n");
    +
    +        return NULL;
    +      }

... I wonder if libtextstyle allocates memory while stylizing? :)


         if (!pkl_compile_file (compiler, poke_rt_pk))
           {
    @@ -97,6 +107,8 @@ pkl_new (pvm vm, const char *rt_path)
       /* Load the standard library.  */
       {
         char *poke_std_pk = pk_str_concat (rt_path, "/std.pk", NULL);
    +    if (!poke_std_pk)
    +      goto out_of_memory;
    
         if (!pkl_compile_file (compiler, poke_std_pk))
           return NULL;
    diff --git a/poke/pk-cmd.c b/poke/pk-cmd.c
    index b57f0ac0..6fb9f3f9 100644
    --- a/poke/pk-cmd.c
    +++ b/poke/pk-cmd.c
    @@ -585,6 +585,13 @@ pk_cmd_exec (const char *str)
                 what = 1;
    
               cmd_alloc = pk_str_concat (cmd, ";", NULL);
    +          if (!cmd_alloc)
    +            {
    +              pk_printf (_("out of memory\n"));
    +              retval = 0;
    +              goto cleanup;
    +            }
    +
               ecmd = cmd_alloc;
             }
    
    diff --git a/poke/poke.c b/poke/poke.c
    index f6d46351..798adb2b 100644
    --- a/poke/poke.c
    +++ b/poke/poke.c
    @@ -446,6 +446,11 @@ initialize_user (void)
       if (homedir != NULL)
         {
           char *pokerc = pk_str_concat (homedir, "/.pokerc", NULL);
    +      if (!pokerc)
    +        {
    +          pk_printf (_("out of memory\n"));
    +          exit (EXIT_FAILURE);
    +        }
    
           if (pk_file_readable (pokerc) == NULL)
             {
    @@ -479,6 +484,11 @@ initialize_user (void)
           xdg_config_dirs = "/etc/xdg";
    
         char *config_path = pk_str_concat (xdg_config_dirs, ":", 
xdg_config_home, NULL);
    +    if (!config_path)
    +      {
    +        pk_printf (_("out of memory\n"));
    +        exit (EXIT_FAILURE);
    +      }
    
         char *dir = strtok (config_path, ":");
         do
    @@ -490,6 +500,11 @@ initialize_user (void)
             /* Mount the full path and determine whether the resulting
                file is readable. */
             char *config_filename = pk_str_concat (dir, "/poke/pokerc.conf", 
NULL);
    +        if (!config_path)
    +          {
    +            pk_printf (_("out of memory\n"));
    +            exit (EXIT_FAILURE);
    +          }
    
             if (pk_file_readable (config_filename) == NULL)
               {
    --
    2.26.2



reply via email to

[Prev in Thread] Current Thread [Next in Thread]