Skip to content

Commit 727cb89

Browse files
committed
Don't allow resolver to return 'localhost' for a non-loopback address.
1 parent 32f266c commit 727cb89

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ v2.5b1 - YYYY-MM-DD
9090
supported document formats for a printer (Issue #1392)
9191
- Updated the scheduler to hold password/PIN jobs for 15 seconds before
9292
releasing to the printer (Issue #1456)
93+
- Updated `httpAddrLookup` to return a numeric address when the resolver
94+
returns "localhost" for a non-loopback address.
9395
- Deprecated the "page-border" Job Template attribute (Issue #1020)
9496
- Removed the `cups-config` utility (use `pkg-config` instead)
9597
- Fixed use-after-free in `cupsdAcceptClient()` when we log warning during error

cups/http-addr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// HTTP address routines for CUPS.
33
//
4-
// Copyright © 2023-2025 by OpenPrinting.
4+
// Copyright © 2023-2026 by OpenPrinting.
55
// Copyright © 2007-2021 by Apple Inc.
66
// Copyright © 1997-2006 by Easy Software Products, all rights reserved.
77
//
@@ -373,7 +373,7 @@ httpAddrLookup(
373373
#endif // AF_LOCAL
374374

375375
// Optimize lookups for localhost/loopback addresses...
376-
if (httpAddrLocalhost(addr))
376+
if (httpAddrIsLocalhost(addr))
377377
{
378378
cupsCopyString(name, "localhost", (size_t)namelen);
379379
return (name);
@@ -401,12 +401,12 @@ httpAddrLookup(
401401
//
402402
// FWIW, I think this is really a bug in the implementation of
403403
// getnameinfo(), but falling back on httpAddrString() is easy to do...
404-
if ((error = getnameinfo(&addr->addr, (socklen_t)httpAddrLength(addr), name, (socklen_t)namelen, NULL, 0, 0)) != 0)
404+
if ((error = getnameinfo(&addr->addr, (socklen_t)httpAddrLength(addr), name, (socklen_t)namelen, NULL, 0, 0)) != 0 || !strcasecmp(name, "localhost"))
405405
{
406406
if (error == EAI_FAIL)
407407
cg->need_res_init = 1;
408408

409-
return (httpAddrGetString(addr, name, (size_t)namelen));
409+
httpAddrGetString(addr, name, (size_t)namelen);
410410
}
411411

412412
DEBUG_printf("1httpAddrLookup: returning \"%s\"...", name);

0 commit comments

Comments
 (0)