Skip to content
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

GSoC IPPServer Functionality #120 #121 #122 #139

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 6 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
64 changes: 62 additions & 2 deletions cups/ipp-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ _ippFileParse(
{
_ippVarsExpand(v, value, temp, sizeof(value));
_ippVarsSet(v, name, value);
}
}
}
else
{
Expand Down Expand Up @@ -624,11 +624,71 @@ parse_value(_ipp_file_t *f, /* I - IPP data file */
break;

case IPP_TAG_STRING :
return (ippSetOctetString(ipp, attr, element, value, (int)strlen(value)));
{
if(value[0]=='<') /* Input is binary(in form of hex) values*/
{
memmove(value, value+1, strlen(value)); /* Eliminate the '<' sign */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse the value string into a buffer, don't copy/move stuff around. The buffer just needs to be 32767 bytes, e.g.:

unsigned char data[32767], *dataptr = data;
char *valptr = value + 1;

do
{
  while (isxdigit(valptr[0]) && isxdigit(valptr[1]))
  {
     // Decode hex digits and store in *dataptr;
     valptr += 2;
     dataptr ++;
     if (dataptr >= (data + sizeof(data))
       break;
  }

  if (*valptr == '>')
    break;
  else if (*valptr)
  {
    report_error(...);
    return (0);
  }

  if (!_ippFileReadToken(f, value, sizeof(value))
  {
    report_error(...);
    return (0);
  }

  valptr = value;
}

// data contains data, "dataptr - data" contains length

char value_concat[50000]; /* Concatenated string with hexadecimal values without whitespace */
int starting_line_number = f->linenum;
while(value[strlen(value)-1] != '>')
{
strcat(value_concat,value);
if (!_ippFileReadToken(f, value, sizeof(value)))
{
report_error(f, v, user_data, "hexadecimal value not terminated starting line %d of \"%s\".", starting_line_number, f->filename);
return (0);
}
}
value[(strlen(value)-1)]='\0'; /* Eliminate the last '>' sign */
strcat(value_concat,value); /* Final concatenation for hexadecimal value to be complete*/
int i; /* Iterating variable*/
for(i=0;i<strlen(value_concat);i++) /* Sanity Check*/
{
if(!(value_concat[i] >= '0' && value_concat[i]<= '9') || (value_concat[i]>='a' && value_concat[i]<='f'))
{
report_error(f, v, user_data, "Bad hexadecimal value \"%s\" on line %d of \"%s\".", value_concat, starting_line_number, f->filename);
return (0);
}
}
return (ippSetOctetString(ipp, attr, element, value_concat, (int)strlen(value_concat)));
}
else
{
return (ippSetOctetString(ipp, attr, element, value, (int)strlen(value))); /* If a quoted string like "..", pass it on */
}

}

break;

case IPP_TAG_TEXTLANG :
{
(*attr)->values[element].string.text = _cupsStrAlloc(value);
if (!_ippFileReadToken(f, value, sizeof(value)))
{
report_error(f, v, user_data, "No Language Data in line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
memmove(value, value+1, strlen(value));
value[strlen(value)-1]='\0'; /* Purge parenthesis */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the syntax is:

"string"(language)

then we need to verify that the token we've read starts and ends with "(" and ")".

(*attr)->values[element].string.language = _cupsStrAlloc(value);

}
break;
case IPP_TAG_NAMELANG :
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same code for IPP_TAG_NAMELANG and IPP_TAG_TEXTLANG (with the two case statements together feeding into the same code).

(*attr)->values[element].string.text = _cupsStrAlloc(value);
if (!_ippFileReadToken(f, value, sizeof(value)))
{
report_error(f, v, user_data, "No Language Data in line %d of \"%s\".", f->linenum, f->filename);
return (0);
}
memmove(value, value+1, strlen(value));
value[strlen(value)-1]='\0'; /* Purge parenthesis */
(*attr)->values[element].string.language = _cupsStrAlloc(value);

}
break;
case IPP_TAG_TEXT :
case IPP_TAG_NAME :
case IPP_TAG_KEYWORD :
Expand Down