Skip to content

Commit

Permalink
Update ippAddCredentialsString to handle CR, CR LF, and/or LF termina…
Browse files Browse the repository at this point in the history
…ted lines

in the credentials string (Issue #58)
  • Loading branch information
michaelrsweet committed Jul 3, 2023
1 parent 2b2d541 commit 15ce4c0
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions cups/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,42 @@ ippAddCredentialsString(
for (num_values = 0, cptr = cvalue; cptr;)
{
// Find the next delimiter
// TODO: Handle CR LF in credentials strings???
if (*cptr)
if (*cptr && *cptr != '\r' && *cptr != '\n')
num_values ++;

if ((cptr = strchr(cptr, '\n')) != NULL)
if ((cptr = strchr(cptr, '\r')) != NULL)
{
// Skip CR or CR LF
if (cptr[1] == '\n')
cptr += 2;
else
cptr ++;
}
else if ((cptr = strchr(cptr, '\n')) != NULL)
{
// Skip LF
cptr ++;
}
}

// Create the empty attribute and copy the values...
if ((attr = ippAddStrings(ipp, group, IPP_TAG_TEXT, name, num_values, NULL, NULL)) != NULL)
{
for (i = 0, cptr = cvalue; cptr;)
for (i = 0, cptr = cvalue; cptr && i < num_values;)
{
cstart = cptr;
if ((cptr = strchr(cptr, '\n')) != NULL)
if ((cptr = strchr(cptr, '\r')) != NULL)
{
// Terminate on CR
*cptr++ = '\0';
if (*cptr == '\n')
cptr ++; // Skip LF
}
else if ((cptr = strchr(cptr, '\n')) != NULL)
{
// Terminate on LF
*cptr++ = '\0';
}

if (*cstart)
attr->values[i++].string.text = _cupsStrAlloc(cstart);
Expand Down

0 comments on commit 15ce4c0

Please sign in to comment.