The schedulers mime.types parser gets it wrong sometimes #3059

Closed
michaelrsweet opened this Issue Jan 11, 2009 · 3 comments

Comments

Projects
None yet
1 participant
Collaborator

michaelrsweet commented Jan 11, 2009

Version: 1.3-current
CUPS.org User: opher

The function mimeAddTypeRule() in scheduler/type.c parses some rules wrong. This happens for example to:
application/x-shell

Try this:
----------- foo.sh start --------------

echo "Hello, World!"

----------- foo.bash start ------------

!/bin/bash

echo "Hello, World!"

(1) lp -d printer foo.sh
(2) lp -d printer foo.bash

Both result in the scheduler auto-typing as text/plain.

This happens because of a wrong if' at line 189. At the point when we reach the (first)+' in:
application/x-shell sh printable(0,1024) + string(0,#!)
We have:
logic == MIME_MAGIC_OR
current != NULL
current->prev != NULL
current->prev->prev == NULL

and so the `if' expression evaluates to FALSE and we end up executing this block (line 215):
current->parent->op = MIME_MAGIC_AND;

which ends up evaluating the rule as: sh + printable(0,1024) + ...
The fix is to drop the current->prev->prev != NULL' evaluation from theif'. Please also note that in the "truth" block current->prev->prev is never referenced.

Patch attached.

Collaborator

michaelrsweet commented Jan 13, 2009

CUPS.org User: mike

Fixed in Subversion repository.

Collaborator

michaelrsweet commented Jan 13, 2009

"add-type-rule-fix.patch":

This patch file was generated by NetBeans IDE

Following Index: paths are relative to: H:\My Documents\Projects\CUPS\cups-1.3.x\scheduler

This patch can be applied using context Tools: Patch action on respective folder.

It uses platform neutral UTF-8 encoding and \n newlines.

Above lines and this line are ignored by the patching process.

Index: type.c
--- type.c Base (BASE)
+++ type.c Locally Modified (Based On LOCAL)
@@ -187,8 +187,7 @@
else if (*rule == '+' && current != NULL)
{
if (logic != MIME_MAGIC_AND &&

  •      current != NULL && current->prev != NULL &&
    
  • current->prev->prev != NULL)
    
  •      current != NULL && current->prev != NULL)
    
    {
    /*
    * OK, we have more than 1 rule in the current tree level... Make a
Collaborator

michaelrsweet commented Jan 13, 2009

"str3059.patch":

Index: CHANGES-1.3.txt

--- CHANGES-1.3.txt (revision 8239)
+++ CHANGES-1.3.txt (working copy)
@@ -5,6 +5,8 @@

- Documentation fixes (STR #2994, STR #2995, STR #3008, STR #3056,
  STR #3057)
    • The scheduler did not always load MIME type rules correctly
  • (STR #3059)
    
    • The test page did not format correctly on A4 paper (STR #3060)
    • The web interface sometimes incorrectly redirected users to
      127.0.0.1 (STR #3022)
      Index: scheduler/type.c

      --- scheduler/type.c (revision 8235)
      +++ scheduler/type.c (working copy)
      @@ -188,8 +188,7 @@
      else if (*rule == '+' && current != NULL)
      {
      if (logic != MIME_MAGIC_AND &&
  •      current != NULL && current->prev != NULL &&
    
  • current->prev->prev != NULL)
    
  •      current != NULL && current->prev != NULL)
    
    {
    /*
    * OK, we have more than 1 rule in the current tree level... Make a

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