Hi!

After apt-getting the Abiword source and doing some poking around, I finally managed to uncover what the problem was and it is a bit silly.

As background information, I semi-recently converted my system from ISO-8859-1 to using UTF-8 unicode, but apparently I had forgotten to
change the user name/comment fields in /etc/passwd, and those entries
were still using some 8-bit ISO-8859-1 accented characters.

Now, what happens when Abiword is run is  that the following code
gets executed during creation of a new document in src/text/ptbl/xp/pd_Document.cpp:

PD_Document::PD_Document()
[...]
        const gchar *name = g_get_real_name();
        if(strcmp(name, "Unknown") == 0)
                name = g_get_user_name();
        gchar *utf8name = g_locale_to_utf8(name, -1, NULL, NULL, NULL);
        m_sUserName = utf8name;
        g_free(utf8name);

The issue here is that as g_get_{real,user}_name() return the name in ISO-8859-1 encoding, but the system locale is set to en_US.UTF-8, which causes g_locale_to_utf8() conversion to fail and return NULL.

Which, in turn, causes a segfault in the m_sUserName = utf8name assignation (you can't assign a NULL const char value to std::string).

While this may be considered an user error, I think it would be prudent to not crash when such situation is encountered. Thus, I propose the following patch:

--- src/text/ptbl/xp/pd_Document.cpp.orig       2012-10-26 17:51:28.000000000 
+0300
+++ src/text/ptbl/xp/pd_Document.cpp    2012-10-26 18:27:32.000000000 +0300
@@ -213,8 +213,13 @@
        if(strcmp(name, "Unknown") == 0)
                name = g_get_user_name();
        gchar *utf8name = g_locale_to_utf8(name, -1, NULL, NULL, NULL);
-       m_sUserName = utf8name;
-       g_free(utf8name);
+       if (utf8name != NULL)
+       {
+               m_sUserName = utf8name;
+               g_free(utf8name);
+       }
+       else
+               m_sUserName = "Unknown";
 }

 PD_Document::~PD_Document()


Hope this helps.

--
] ccr/TNSP ^ pWp  ::  ccr tnsp org  ::  http://ccr.tnsp.org/
] PGP key: 0466 95ED 96DF 3701 C71D D62D 10A6 28A6 1374 C112
--- src/text/ptbl/xp/pd_Document.cpp.orig	2012-10-26 17:51:28.000000000 +0300
+++ src/text/ptbl/xp/pd_Document.cpp	2012-10-26 18:27:32.000000000 +0300
@@ -213,8 +213,13 @@
 	if(strcmp(name, "Unknown") == 0)
 		name = g_get_user_name();
 	gchar *utf8name = g_locale_to_utf8(name, -1, NULL, NULL, NULL);
-	m_sUserName = utf8name;
-	g_free(utf8name);
+	if (utf8name != NULL)
+	{
+		m_sUserName = utf8name;
+		g_free(utf8name);
+	}
+	else
+		m_sUserName = "Unknown";
 }
 
 PD_Document::~PD_Document()

Reply via email to