poke-devel
[Top][All Lists]
Advanced

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

[PATCH 1/6] Check return value of pk_str_concat


From: Tim Rühsen
Subject: [PATCH 1/6] Check return value of pk_str_concat
Date: Thu, 7 May 2020 12:50:59 +0200

2020-05-06  Tim Rühsen  <address@hidden>

        * libpoke/pkl-fold.c (OP_BINARY_SSS): Check return value of
        pk_str_concat.
        * libpoke/pkl.c (pkl_new): Likewise.
        * poke/pk-cmd.c (pk_cmd_exec): Likewise.
        * poke/poke.c (initialize_user): Likewise.
---
 ChangeLog          |  8 ++++++++
 libpoke/pkl-fold.c |  4 ++++
 libpoke/pkl.c      | 12 ++++++++++++
 poke/pk-cmd.c      |  7 +++++++
 poke/poke.c        | 15 +++++++++++++++
 5 files changed, 46 insertions(+)

diff --git a/libpoke/pkl-fold.c b/libpoke/pkl-fold.c
index 64feffdb..d3c02831 100644
--- a/libpoke/pkl-fold.c
+++ b/libpoke/pkl-fold.c
@@ -20,6 +20,8 @@

 #include <config.h>

+#include <gettext.h>
+#define _(str) gettext (str)
 #include <string.h>
 #include <stdint.h>
 #include <assert.h>
@@ -586,6 +588,8 @@ EMUL_UU (bnoto) { return ~op; }
                                                                         \
           res = pk_str_concat (PKL_AST_STRING_POINTER (op1),            \
                                PKL_AST_STRING_POINTER (op2), NULL);     \
+          if (!res)                                                     \
+            PKL_ICE (PKL_AST_LOC (op1), _("out of memory"));            \
                                                                         \
           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;
+      }

     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..aa82448c 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_filename)
+          {
+            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]