bugGNU Gengetopt - Bugs: bug #55745, Test for malloc failure and handle...

 
 

bug #55745: Test for malloc failure and handle it (PATCH)

Submitter:  None
Submitted:  Wed 20 Feb 2019 11:41:38 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 20 Feb 2019 11:41:38 AM UTC, original submission:  

Generated add_node() contains an unchecked malloc() call which could lead to dereferencing a potential null pointer during run time.

Attaching a patch fixing the generated code, the skeleton code diff shows what basically was changed:

--- a/src/skels/c_source.h_skel
+++ b/src/skels/c_source.h_skel
@@ -314,12 +314,14 @@ struct generic_list
 /**
  * @@brief add a node at the head of the list
  */
-static void add_node(struct generic_list **list) {
+static int add_node(struct generic_list **list) {
   struct generic_list new_node = (struct generic_list ) malloc (sizeof (struct generic_list));
+  if (new_node == NULL) return -1;
   new_node->next = *list;
   *list = new_node;
   new_node->arg.string_arg = 0;
   new_node->orig = 0;
+  return 0;
 }
 
 @IF@ (not multiple_options_all_string) and multiple_token_functions @THEN@
@@ -960,7 +962,7 @@ int update_multiple_arg_temp(struct generic_list **list,
 
   while (1)
     {
-      add_node (list);
+      if (add_node (list) == -1) return 1;
       if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
           prev_given, multi_token, possible_values, default_value,
           arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {

All unit tests still pass and since add_node() is an internal static function there should be no others using it.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #46313:  malloc.patch added by None (3KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follows 1 latest change.

Date Changed by Updated Field Previous Value => Replaced by
2019-02-20 None Attached File- Added malloc.patch, #46313

Back to the top

Powered by Savane 3.13-4448.
Corresponding source code