Comment 9 for bug 173757

Revision history for this message
Marcus Comstedt (marcus-mc) wrote :

I can only find one small error in your new patch:

If fgets can not read at least one character (because of EOF), it will return NULL. Your
definition of read_gstring_from_stdin does not handle that case (it will segfault on the
call to strlen(readp), or possibly before because the call to strip is not safe either).

I simply added a NULL check, making the definition like so:

gboolean read_gstring_from_stdin(GString *s)
{
  gchar buffer[255];
  char *readp;
  do
  {
     readp = fgets(buffer, sizeof(buffer), stdin);
     if (readp == NULL)
       return FALSE;
     strip (buffer);
     g_string_append(s, buffer);
  } while (sizeof(buffer)-1 == strlen(readp));
  return TRUE;
}

and tested the resulting package with good results. I can now feed 3000 arguments to
the xauth list testcase without problems.

I'm not sure whether the return code "FALSE" actually makes sense in the above, but
as the return code isn't checked anyway... :-)