[Geany-devel] [geanygdb plugin] Stack overflow when activating it.

Eugene Arshinov earshinov at xxxxx
Wed Sep 2 16:48:17 UTC 2009


Hi all.

The trouble is caused by unsafe usage of `strncpy' and long strings in 
Russian localization. I found that the stack overflow is caused by the 
following code (geany-plugins/geanygdb/src/gdb-ui-main.c : 366)

-------------------- 8< --------------------

if (text && disable_mnemonics)
    {
        gchar *p;
        gchar buf[32];
        strncpy(buf, text, sizeof(buf));
        for (p = buf; *p; p++)
        {
            if (*p == '_')
            {
                memmove(p, p + 1, strlen(p));
            }
        }
        text = buf;
    }

-------------------- 8< --------------------

Obviously, 32 chars are enough for English localisation, but not for 
Russian one (which I am using). Quick fix:

...
gchar buf[64];
strncpy(buf, text, sizeof(buf)-1);
buf[sizeof(buf)-1] = '\0';
...

BTW, those memmove() and strlen() in cycle are quite inefficient and 
ugly ;-)

Best regards,
Eugene.




More information about the Devel mailing list