Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGES - OpenPrinting CUPS
v2.5b1 - YYYY-MM-DD
-------------------

- Web interface session IDs now use random data from `cupsGetRand` instead of a
time-seeded PRNG (CVE-2018-4700 follow-up).
- Added multiple language support for IPP Everywhere.
- Added `cupsConcatString`, `cupsCopyString`, and `cupsFormatString` string
APIs.
Expand Down
40 changes: 13 additions & 27 deletions cgi-bin/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,33 +1315,19 @@ cgi_passwd(const char *prompt) /* I - Prompt (not used) */
static const char * /* O - New session ID */
cgi_set_sid(void)
{
char buffer[512], /* SID data */
sid[33]; /* SID string */
unsigned char sum[16]; /* MD5 sum */
const char *remote_addr, /* REMOTE_ADDR */
*server_name, /* SERVER_NAME */
*server_port; /* SERVER_PORT */
struct timeval curtime; /* Current time */


if ((remote_addr = getenv("REMOTE_ADDR")) == NULL)
remote_addr = "REMOTE_ADDR";
if ((server_name = getenv("SERVER_NAME")) == NULL)
server_name = "SERVER_NAME";
if ((server_port = getenv("SERVER_PORT")) == NULL)
server_port = "SERVER_PORT";

gettimeofday(&curtime, NULL);
CUPS_SRAND(curtime.tv_sec + curtime.tv_usec);
snprintf(buffer, sizeof(buffer), "%s:%s:%s:%02X%02X%02X%02X%02X%02X%02X%02X",
remote_addr, server_name, server_port,
(unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255,
(unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255,
(unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255,
(unsigned)CUPS_RAND() & 255, (unsigned)CUPS_RAND() & 255);
cupsHashData("md5", (unsigned char *)buffer, strlen(buffer), sum, sizeof(sum));

cgiSetCookie(CUPS_SID, cupsHashString(sum, sizeof(sum), sid, sizeof(sid)), "/", NULL, 0, 0);
char sid[33]; /* SID string */
unsigned char secret[16]; /* SID data */
size_t i; /* Looping var */


/*
* Generate a random session ID...
*/

for (i = 0; i < sizeof(secret); i ++)
secret[i] = (unsigned char)cupsGetRand();

cgiSetCookie(CUPS_SID, cupsHashString(secret, sizeof(secret), sid, sizeof(sid)), "/", NULL, 0, 0);

return (cupsGetOption(CUPS_SID, num_cookies, cookies));
}
Expand Down