New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash in httpGetHostname() #1561

Closed
michaelrsweet opened this Issue Apr 13, 2006 · 4 comments

Comments

Projects
None yet
1 participant
@michaelrsweet
Collaborator

michaelrsweet commented Apr 13, 2006

Version: 1.2rc2
CUPS.org User: martin.pitt.canonical

An user just reported a crash with 1.2rc2 test packages, with the following backtrace: http://kubuntu.pastebin.com/657295

Sorry, it's relatively poor due to no debug symbols. I'll try to have him reproduce the issue. However, in the meantime I added some robustification to httpGetHostname() so that crashes are less likely. They might not fix the crash, but the additional checks can't hurt anyway IMHO.

Thanks,

Martin

@michaelrsweet

This comment has been minimized.

Collaborator

michaelrsweet commented Apr 13, 2006

CUPS.org User: mike

Um, http->hostname is a constant string (not a string pointer), so the "if (http->hostname)" change isn't valid.

I'd guess that http is pointing to an invalid http_t instance, but will look into this further...

@michaelrsweet

This comment has been minimized.

Collaborator

michaelrsweet commented Apr 14, 2006

CUPS.org User: mike

OK, I'm attaching the patch I've applied in r5399.

To summarize: http->hostname is a character array - it cannot be NULL. I added a check for the s and slen arguments, and a check for the gethostname() return value, and finally to make sure that h_name in the hostent structure is not NULL.

@michaelrsweet

This comment has been minimized.

Collaborator

michaelrsweet commented Apr 19, 2006

"httpGetHostname-robustification.patch":

diff -urNad cups-1.2~/cups/http-addr.c cups-1.2/cups/http-addr.c
--- cups-1.2~/cups/http-addr.c 2006-03-08 19:34:07.000000000 +0100
+++ cups-1.2/cups/http-addr.c 2006-04-13 13:07:32.000000000 +0200
@@ -510,7 +510,7 @@

if (http)
{

  • if (http->hostname[0] == '/')
  • if (!http->hostname || http->hostname[0] == '/')
    strlcpy(s, "localhost", slen);
    else
    strlcpy(s, http->hostname, slen);
    @@ -521,9 +521,16 @@
  • Get the hostname...
    */
  • gethostname(s, slen);
  • if (gethostname(s, slen) != 0)
  • {
  • /*
  • * Fall back to localhost on failure
  • */
  • strlcpy(s, "localhost", slen);
  • return (s);
  • }

if (!strchr(s, '.'))
{

@michaelrsweet

This comment has been minimized.

Collaborator

michaelrsweet commented Apr 19, 2006

"str1561.patch":

Index: http-addr.c

--- http-addr.c (revision 5398)
+++ http-addr.c (working copy)
@@ -508,6 +508,9 @@
struct hostent host; / Host entry to get FQDN */

  • if (!s || slen <= 1)
  • return (NULL);

if (http)
{
if (http->hostname[0] == '/')
@@ -521,7 +524,8 @@

  • Get the hostname...
    */

  • gethostname(s, slen);

  • if (gethostname(s, slen) < 0)

  •  strlcpy(s, "localhost", slen);
    

    if (!strchr(s, '.'))
    {
    @@ -529,7 +533,7 @@

    • The hostname is not a FQDN, so look it up...
      */
  •  if ((host = gethostbyname(s)) != NULL)
    
  •  if ((host = gethostbyname(s)) != NULL && host->h_name)
    

    strlcpy(s, host->h_name, slen);
    }
    }

@michaelrsweet michaelrsweet added this to the Stable milestone Mar 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment