Details

[Home]

Issue of the Implementation # D0019

Brief

Invocation of the interface "g_completion_complete_utf8" with certain values causes an abnormal termination with SIGSEGV signal

Detailed Description

Documentation for the interface g_completion_complete_utf8 states: "new_prefix: if non-NULL, returns the longest prefix which is common to all items that matched prefix, or NULL if no items matched prefix.", whereas when "new_prefix" parameter is set to "NULL" the process is abnormally terminated with SIGSEGV signal.

Problem location(s) in the standard

Linux Standard Base Desktop Specification 3.1, Chapter 12. Libraries, 12.2 Interfaces for libglib-2.0; http://www.gtk.org/api/2.6/glib/glib-Automatic-String-Completion.html#g-completion-complete-utf8

Reproducing

Invocation of the interface g_completion_complete_utf8 with parameter "new_prefix" set to "NULL". The process is terminatied with SIGSEGV signal.

Example

#include <glib.h>

int main ()
{
    GCompletion *gcmp = NULL;
    GList *l_items = NULL;
    GList *ret_list = NULL;

    gcmp = g_completion_new (NULL);
    l_items = g_list_append (l_items, "На берегу ");
    l_items = g_list_append (l_items, "На берегу пустынных волн,");
    g_completion_add_items (gcmp, l_items);
    ret_list = g_completion_complete_utf8 (gcmp, "На ", NULL);
    return 0;
}

Possible solutions

The patch fixing this problem is below (author of the patch M. Clasen):

--- glib-2.6.2/glib/gcompletion.c
+++ glib-2.6.2-fixed/glib/gcompletion.c
@@ -195,7 +195,7 @@

   list = g_completion_complete (cmp, prefix, new_prefix);

-  if (*new_prefix)
+  if (new_prefix && *new_prefix)
     {
       p = *new_prefix + strlen (*new_prefix);
       q = g_utf8_find_prev_char (*new_prefix, p);

Component

gtk-glib 2.6.2 - 2.11.0

Status

Fixed in gtk-glib - 2.11.0

[Home]