Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: [PATCH] fix segfaults because of channels with umlauts



Klaus Schmidinger wrote:
> 
> Ludwig Nussel wrote:
> >
> > Hi,
> >
> > vdr 1.2.6 segfaults in the "What's on now?" screen if there are
> > channels with Umlauts (e.g. WDR Köln). For some reason asprintf
> > refuses those channels (Invalid or incomplete multibyte or wide
> > character). vdr doesn't evaluate the return value of asprintf and
> > therefore operates on broken (not necessarily NULL) pointers. I have
> > no idea why asprintf suddenly behaves like that, I haven't seen such
> > segfaults before.
> 
> Have you made any changes to your system lately that might have triggered
> this?
> 
> Is this "plain vanilla VDR 1.2.6" or are there any patches involved?
> 
> I don't have any problems here with VDR 1.3.10. Channels with umlauts
> work just fine . This is a SuSE 7.3 system with kernel 2.4.10, in case
> that matters. Maybe you're running a system that uses UTF8 or something
> like that. If so, you could try turning that off.
> 
> > Nevertheless it's a bug in vdr to ignore the
> > return value and to not check for NULL. Attached patch is for 1.2.6,
> > 1.3.x needs a similar one.
> 
> I guess you're right about checking the return value of asprintf().
> But first I'd like to know exactly why asprintf() failed on your system.
> The typical error mentioned in the GNU C Library Reference Manual for
> asprintf() would be a failure to allocate the buffer, which normally
> should be pretty unlikely, given the amount of RAM today's systems have...

I've decided against checking all the return values of asprintf(), because
that would be too much hassle in many places. Besides, there are many places
where objects are allocated on the heap and it is not explicitly checked
whether the returned pointer is valid. At some point one must be able to
assume that there is enough memory available, otherwise the whole system
wouldn't be able to work reasonably at all.

The actual problem here doesn't even have to do with memory consumption,
but rather with incompatible character representations, which would cause
the program to work wrong, anyway. So I'd rather remove the root of all evil,
which is UTF-8. I'll therefore add a few lines to vdr.c, which will check
this at program startup and exit if necessary:

  // Check for UTF-8 and exit if present - asprintf() will fail if it encounters 8 bit ASCII codes
  char *LangEnv;
  if ((LangEnv = getenv("LANG"))    != NULL && strcasestr(LangEnv, "utf") ||
      (LangEnv = getenv("LC_TYPE")) != NULL && strcasestr(LangEnv, "utf")) {
     fprintf(stderr, "vdr: please turn off UTF-8 before starting VDR\n");
     return 2;
     }

Klaus




Home | Main Index | Thread Index