Subject: bug#30785: Man pages truncated, repeated

From: Danny Milosavljevic <[email-masked]>
Date: Mon, 14 Jan 2019 18:46:00 +0100

Hi Pierre,

On Mon, 14 Jan 2019 17:57:12 +0100
Pierre Neidhardt <[email-masked]> wrote:

> > (libs/libgroff/localcharset.c's locale_charset looks overly complicated, WTF?)  
> 
> Oh dear... relocatep.cpp is not much better, here is the offending function:
> 
> --8<---------------cut here---------------start------------->8---
> // Strip the installation prefix and replace it
> // with the current installation prefix; return the relocated path.
> char *relocatep(const char *path)
> {
> #if DEBUG
>   fprintf(stderr, "relocatep: path = %s\n", path);
>   fprintf(stderr, "relocatep: INSTALLPATH = %s\n", INSTALLPATH);
>   fprintf(stderr, "relocatep: INSTALLPATHLEN = %d\n", INSTALLPATHLEN);
> #endif
>   if (!curr_prefix)
>     set_current_prefix();
>   if (strncmp(INSTALLPATH, path, INSTALLPATHLEN))
>     return strsave(path);
>   char *relative_path = (char *)path + INSTALLPATHLEN;
>   size_t relative_path_len = strlen(relative_path);
>   char *relocated_path = new char[curr_prefix_len + relative_path_len + 1];
>   strcpy(relocated_path, curr_prefix);
>   strcat(relocated_path, relative_path);
> #if DEBUG
>   fprintf(stderr, "relocated_path: %s\n", relocated_path);
> #endif /* DEBUG */
>   return relocated_path;
> }
> --8<---------------cut here---------------end--------------->8---
> 
> I don't even get the use case of the function...  From locale_charset, it seems
> that the argument is LIBDIR.

It's used inside get_charset_aliases, which reads the file "charset.alias".
We have only one alias in our file "charset.alias" (in GuixSD), so let's try
ignoring it completely for now.

What happens if you don't mess with LC_ALL but set the environment variable
CHARSETALIASDIR to "/does_not_exist" ?

> Can you see a fix then?

If the avove also works, we can just patch get_charset_aliases to always return
the empty string (or a string literal).

The one alias we do have in "charset.alias" is:

ISO_646.IRV:1983 ASCII

Alternatively, we could patch get_charset_aliases so it always takes our
charset.alias from our libiconv (without get_charset_aliases calling
"relocate").

Still it would be interesting to find the Segmentation fault (that's
not supposed to ever happen).