Bug 212310 - devel/glib20: Error messages with trailing garbage when uninstalling devel/gnome-vfs
Summary: devel/glib20: Error messages with trailing garbage when uninstalling devel/gn...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-gnome (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-01 16:44 UTC by Tobias Kortkamp
Modified: 2017-04-01 20:32 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (gnome)


Attachments
glib.diff (1.51 KB, patch)
2016-09-01 20:00 UTC, Tobias Kortkamp
tobik: maintainer-approval? (gnome)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Kortkamp freebsd_committer freebsd_triage 2016-09-01 16:44:13 UTC
TWIMC

When uninstalling gnome-vfs pkg runs its pkg-deinstall script which in turn invokes gconftool-2 which gives these error messages with a bunch of trailing garbage when LANG=en_US.UTF-8:

I/O warning : failed to load external entity "/usr/local/etc/gconf/schemas/desktop_default_applications.schemas"
Failed to open `/usr/local/etc/gconf/schemas/desktop_default_applications.schemas': No such file or directorøàÿÿÿ
I/O warning : failed to load external entity "/usr/local/etc/gconf/schemas/desktop_gnome_url_handlers.schemas"
Failed to open `/usr/local/etc/gconf/schemas/desktop_gnome_url_handlers.schemas': No such file or directoáÿÿÿ
I/O warning : failed to load external entity "/usr/local/etc/gconf/schemas/system_dns_sd.schemas"
Failed to open `/usr/local/etc/gconf/schemas/system_dns_sd.schemas': No such file or directoáÿÿÿ
I/O warning : failed to load external entity "/usr/local/etc/gconf/schemas/system_http_proxy.schemas"
Failed to open `/usr/local/etc/gconf/schemas/system_http_proxy.schemas': No such file or directoáÿÿÿ
I/O warning : failed to load external entity "/usr/local/etc/gconf/schemas/system_smb.schemas"
Failed to open `/usr/local/etc/gconf/schemas/system_smb.schemas': No such file or directoráÿÿÿ

I noticed this on my FreeBSD 10.3 desktop, but it's reproducible in a fresh FreeBSD 11.0-RC2 VM too.  gnome-vfs version is 2.24.4_4. glib version is 2.46.2_2. gconf2 version is 3.2.6_4.

How to reproduce:
1. pkg install gnome-vfs
2. env -i PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin LANG=en_US.UTF-8 pkg remove gnome-vfs

With LANG=C or LANG=en_US.ISO8859-15 everything looks ok.

I've managed to come up with this minimal example:

#include <stdio.h>
#include <errno.h>
#include <glib.h>
#include <libintl.h>

#define GETTEXT_PACKAGE "GConf2"
#define GCONF_LOCALE_DIR "/usr/locale/share/locale"

int main() {
    /* This is the sequence of calls gconftool-2 makes... */
    setlocale(LC_ALL, "");
    bindtextdomain(GETTEXT_PACKAGE,GCONF_LOCALE_DIR);
    textdomain(GETTEXT_PACKAGE);

    g_thread_init (NULL);

    bindtextdomain (GETTEXT_PACKAGE, GCONF_LOCALE_DIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

    g_printerr("%s\n", g_strerror(ENOENT));
    return 1;
}

Compile and run with:
cc main.c `pkgconf --libs --cflags glib-2.0 gthread-2.0` && env -i LANG=en_US.UTF-8 ./a.out
Comment 1 Tobias Kortkamp freebsd_committer freebsd_triage 2016-09-01 20:00:38 UTC
Created attachment 174298 [details]
glib.diff

The example can be a lot smaller:

#include <errno.h>
#include <glib.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    setlocale(LC_ALL, "");
    const gchar *err = g_strerror(ENOENT);
    printf("%lu: %s\n", strlen(err), err);
    return 1;
}

And it's also pretty clear that the problem is in devel/glib20 and in g_strerror.

g_strerror is defined in glib/gstrfunc.c line 1254. We see this snippet in there

      if (!g_get_charset (NULL))
        {
          msg = g_locale_to_utf8 (msg, -1, NULL, NULL, &error);
          if (error)
            g_print ("%s\n", error->message);
        }

When g_get_charset returns FALSE (which it does when we setlocale(LC_ALL, "")) msg is a pointer to a local variable which is put into a GHashTable and returned. Adding 

      else
        msg = g_strdup(buf);

fixes the problem or at least prevents printing of garbage values.  glib master has a similar patch for this:

      else if (msg == (const gchar *)buf)
        msg = g_strdup (buf);

Also see https://git.gnome.org/browse/glib/commit/glib/gstrfuncs.c?id=f87e002313d566dcce71a9aba040d22ddb5c1e80

I'm attaching a patch against devel/glib20 with a backport of this.

Poudriere testport 9.3/amd64 ok
Comment 2 Tobias Kortkamp freebsd_committer freebsd_triage 2017-04-01 20:32:18 UTC
Fixed implicitly by ports r437456.