Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Possible problems found by static analysis of code #2

Merged
merged 3 commits into from

2 participants

Jiri Popelka François Pinard
Jiri Popelka

Hello,

we analyzed the recode-3.6 code with Coverity.
Coverity is commercial enterprise level tool for
static analysis (analysis based only on compiling of sources,
not based on running of binary) of the code.

As a result I have 3 tiny commits that should fix some possible problems.
There's a respective part of the error log in each commit comment.

With regards,
Jiri Popelka,
Red Hat, inc.

jpopelka added some commits
Jiri Popelka jpopelka Coverity: FORWARD_NULL
src/mixed.c:56: assign_zero: Assigning: "task->input.name" = 0.
src/mixed.c:64: var_deref_op: Dereferencing null variable "task->input.name".
9e13643
Jiri Popelka jpopelka Coverity: UNINIT
src/recode.c:192: var_decl: Declaring variable "right_table" without initializer.
src/recode.c:240: uninit_use_in_call: Using uninitialized value
                  "right_table[right]" when calling "recode_error".

src/recode.c:191: var_decl: Declaring variable "left_table" without initializer.
src/recode.c:228: uninit_use_in_call: Using uninitialized value
                  "left_table[left]" when calling "recode_error".
src/recode.c:281: uninit_use: Using uninitialized value "left_table[search]".
38e52d5
Jiri Popelka jpopelka Coverity: RESOURCE_LEAK
src/hash.c:783: var_assign: Assigning: "new_table" =  storage returned from
                "hash_initialize(candidate, table->tuning, table->hasher,
                                 table->comparator, table->data_freer)".
src/hash.c:816: leaked_storage: Variable "new_table" going out of scope
                                leaks the storage it points to.

src/html.c:428: var_assign: Assigning: "table" =  storage returned from
                "hash_initialize(0U, NULL, code_hash, code_compare, NULL)".
src/html.c:436: leaked_storage: Variable "table" going out of scope
                                leaks the storage it points to.

src/html.c:609: var_assign: Assigning: "table" =  storage returned from
                "hash_initialize(0U, NULL, string_hash, string_compare, NULL)".
src/html.c:617: leaked_storage: Variable "table" going out of scope
                                leaks the storage it points to.

src/request.c:758: var_assign: Assigning: "new" =  storage returned from
                               "recode_malloc(outer, 16UL)".
src/request.c:768: leaked_storage: Variable "new" going out of scope
                                   leaks the storage it points to.
267dda0
François Pinard pinard merged commit 1be6337 into from
François Pinard
Owner

Thank you for the work, Jiri !

François

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 23, 2011
  1. Jiri Popelka

    Coverity: FORWARD_NULL

    jpopelka authored
    src/mixed.c:56: assign_zero: Assigning: "task->input.name" = 0.
    src/mixed.c:64: var_deref_op: Dereferencing null variable "task->input.name".
  2. Jiri Popelka

    Coverity: UNINIT

    jpopelka authored
    src/recode.c:192: var_decl: Declaring variable "right_table" without initializer.
    src/recode.c:240: uninit_use_in_call: Using uninitialized value
                      "right_table[right]" when calling "recode_error".
    
    src/recode.c:191: var_decl: Declaring variable "left_table" without initializer.
    src/recode.c:228: uninit_use_in_call: Using uninitialized value
                      "left_table[left]" when calling "recode_error".
    src/recode.c:281: uninit_use: Using uninitialized value "left_table[search]".
  3. Jiri Popelka

    Coverity: RESOURCE_LEAK

    jpopelka authored
    src/hash.c:783: var_assign: Assigning: "new_table" =  storage returned from
                    "hash_initialize(candidate, table->tuning, table->hasher,
                                     table->comparator, table->data_freer)".
    src/hash.c:816: leaked_storage: Variable "new_table" going out of scope
                                    leaks the storage it points to.
    
    src/html.c:428: var_assign: Assigning: "table" =  storage returned from
                    "hash_initialize(0U, NULL, code_hash, code_compare, NULL)".
    src/html.c:436: leaked_storage: Variable "table" going out of scope
                                    leaks the storage it points to.
    
    src/html.c:609: var_assign: Assigning: "table" =  storage returned from
                    "hash_initialize(0U, NULL, string_hash, string_compare, NULL)".
    src/html.c:617: leaked_storage: Variable "table" going out of scope
                                    leaks the storage it points to.
    
    src/request.c:758: var_assign: Assigning: "new" =  storage returned from
                                   "recode_malloc(outer, 16UL)".
    src/request.c:768: leaked_storage: Variable "new" going out of scope
                                       leaks the storage it points to.
This page is out of date. Refresh to see the latest.
5 src/hash.c
View
@@ -860,7 +860,10 @@ hash_rehash (Hash_table *table, size_t candidate)
struct hash_entry *new_entry = allocate_entry (new_table);
if (new_entry == NULL)
- return false;
+ {
+ hash_free (new_table);
+ return false;
+ }
new_entry->data = data;
new_entry->next = new_bucket->next;
10 src/html.c
View
@@ -435,7 +435,10 @@ init_ucs2_html (RECODE_STEP step,
if (cursor->flags & mask
&& (!request->diacritics_only || cursor->code > 128))
if (!hash_insert (table, cursor))
- return false;
+ {
+ hash_free (table);
+ return false;
+ }
step->step_type = RECODE_UCS2_TO_STRING;
step->step_table = table;
@@ -616,7 +619,10 @@ init_html_ucs2 (RECODE_STEP step,
if (cursor->flags & mask
&& (!request->diacritics_only || cursor->code > 128))
if (!hash_insert (table, cursor))
- return false;
+ {
+ hash_free (table);
+ return false;
+ }
step->step_type = RECODE_STRING_TO_UCS2;
step->step_table = table;
2  src/mixed.c
View
@@ -61,7 +61,7 @@ open_mixed (struct mixed *mixed, RECODE_TASK task)
!task->output.file)
{
recode_perror (NULL, "fopen (%s)", task->output.name);
- if (*(task->input.name))
+ if (task->input.file != stdin)
fclose (task->input.file);
return false;
}
2  src/recode.c
View
@@ -206,6 +206,8 @@ complete_pairs (RECODE_OUTER outer, RECODE_STEP step,
memset (left_flag, 0, 256);
memset (right_flag, 0, 256);
+ memset (left_table, 0, 256);
+ memset (right_table, 0, 256);
table_error = false;
/* Establish known data. */
5 src/request.c
View
@@ -765,7 +765,10 @@ scan_options (RECODE_REQUEST request)
scan_identifier (request);
ALLOC (copy, strlen (request->scanned_string) + 1, char);
if (!copy)
- break; /* FIXME: should interrupt decoding */
+ {
+ free (new);
+ break; /* FIXME: should interrupt decoding */
+ }
strcpy (copy, request->scanned_string);
new_->option = copy;
Something went wrong with that request. Please try again.