~ubuntu-branches/ubuntu/breezy/koffice/breezy-security

« back to all changes in this revision

Viewing changes to filters/kword/applixword/applixwordimport.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-10-11 14:49:50 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051011144950-lwpngbifzp8nk0ds
Tags: 1:1.4.1-0ubuntu7
* SECURITY UPDATE: fix heap based buffer overflow in the RTF importer of KWord
* Opening specially crafted RTF files in KWord can cause
  execution of abitrary code.
* Add kubuntu_01_rtfimport_heap_overflow.diff
* References:
  CAN-2005-2971
  CESA-2005-005
  http://www.koffice.org/security/advisory-20051011-1.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <unistd.h>
24
24
#endif
25
25
 
26
 
#include <qregexp.h>
27
26
#include <qmessagebox.h>
28
27
#include <qptrlist.h>
29
28
#include <applixwordimport.h>
33
32
#include <kgenericfactory.h>
34
33
 
35
34
typedef KGenericFactory<APPLIXWORDImport, KoFilter> APPLIXWORDImportFactory;
36
 
K_EXPORT_COMPONENT_FACTORY( libapplixwordimport, APPLIXWORDImportFactory( "applixwordfilter" ) )
 
35
K_EXPORT_COMPONENT_FACTORY( libapplixwordimport, APPLIXWORDImportFactory( "kofficefilters" ) )
37
36
 
38
37
 
39
38
/******************************************************************************
95
94
    QFile in(m_chain->inputFile());
96
95
    if (!in.open (IO_ReadOnly))
97
96
    {
98
 
        kdError(30502) << "Unable to open input file!" << endl;
 
97
        kdError(30517) << "Unable to open input file!" << endl;
99
98
        in.close();
100
99
        return KoFilter::FileNotFound;
101
100
    }
147
146
          printf ("Start styles\n");
148
147
          t_mycolor *col = new t_mycolor; // delete is in place
149
148
          QString    coltxt ;
150
 
          int zaehler = 0;
 
149
          int zaehler = 0; // Note: "zaehler" means "counter" in English
151
150
          do
152
151
          {
153
152
            mystr = readTagLine (stream, in);
154
153
            if (mystr == "<end_styles>")
155
154
            {
156
155
             ok = false;
157
 
             kdDebug()<<"End styles\n\n";
 
156
             kdDebug(30517)<<"End styles\n\n";
158
157
            }
159
158
            else
160
159
            {
167
166
                rueck = sscanf ((const char *) mystr.latin1() ,
168
167
                                ":%d:%d:%d:%d>",
169
168
                                 &col->c, &col->m, &col->y, &col->k);
170
 
                kdDebug()<<"  Color " <<  zaehler<<"  : "<<col->c << "  " << col->m<< " "<< col->y<<" "<< col->k<<" "<<coltxt<<" "<<endl;
 
169
                kdDebug(30517)<<"  Color " <<  zaehler<<"  : "<<col->c << "  " << col->m<< " "<< col->y<<" "<< col->k<<" "<<coltxt<<" "<<endl;
171
170
                zaehler ++;
172
171
 
173
172
                // Color transformation cmyk -> rgb
193
192
         ***********************************************************************/
194
193
        else if (mystr == "<start_data Applix>")
195
194
        {
196
 
          kdDebug()<<"\nEmbedded Applix object starts:\n";
 
195
          kdDebug(30517)<<"\nEmbedded Applix object starts:\n";
197
196
          do
198
197
          {
199
198
            mystr = readTagLine (stream, in);
200
199
            if (mystr == "<end_data>") ok = false;
201
200
            else
202
201
            {
203
 
              kdDebug()<<"   "<<mystr<<endl;
 
202
              kdDebug(30517)<<"   "<<mystr<<endl;
204
203
            }
205
204
          }
206
205
          while (ok == true);
207
 
          kdDebug()<<"Embedded Applix object ends\n\n";
 
206
          kdDebug(30517)<<"Embedded Applix object ends\n\n";
208
207
 
209
208
        }
210
209
        /**********************************************************************
212
211
         **********************************************************************/
213
212
        else if (mystr.startsWith ("<start_hdrftr "))
214
213
        {
215
 
          kdDebug()<<"\nHeader/Footer starts:\n";
 
214
          kdDebug(30517)<<"\nHeader/Footer starts:\n";
216
215
          do
217
216
          {
218
217
            mystr = readTagLine (stream, in);
219
218
            if (mystr == "<end_hdrftr>") ok = false;
220
219
            else
221
220
            {
222
 
              kdDebug()<<"    "<<mystr<<endl;
 
221
              kdDebug(30517)<<"    "<<mystr<<endl;
223
222
            }
224
223
          }
225
224
          while (ok == true);
226
 
          kdDebug()<<"\nHeader/Footer ends\n";
 
225
          kdDebug(30517)<<"\nHeader/Footer ends\n";
227
226
        }
228
227
        /**********************************************************************
229
228
         * found a paragraph string                                           *
232
231
        {
233
232
           sscanf ( (const char *) mystr.latin1(), "<P \"%99s\"", stylename);
234
233
           mystr.remove (0, 5+strlen(stylename));
235
 
           kdDebug()<<" Para  Name: "<< stylename<<endl;
236
 
           kdDebug()<<"       Rest: "<<mystr<<endl;
 
234
           kdDebug(30517)<<" Para  Name: "<< stylename<<endl;
 
235
           kdDebug(30517)<<"       Rest: "<<mystr<<endl;
237
236
        }
238
237
        /**********************************************************************
239
238
         * found a textstring                                                 *
254
253
          do
255
254
          {
256
255
             pos = mystr.find ("\"", y);
257
 
             kdDebug()<<"POS:"<<pos<<" length:"<< mystr.length()<<" y:"<<y <<endl;
 
256
             kdDebug(30517)<<"POS:"<<pos<<" length:"<< mystr.length()<<" y:"<<y <<endl;
258
257
 
259
 
             kdDebug()<<"< "<<mystr<<" >\n";
 
258
             kdDebug(30517)<<"< "<<mystr<<" >\n";
260
259
             if(  (pos-1 > -1) && (mystr[pos-1] == '\\'))
261
260
             {
262
 
               kdDebug()<<" No string end - but G�nsef�sschen\n";
 
261
               kdDebug(30517)<<" No string end - but G�nsef�sschen\n";
263
262
               y=pos+1;
264
263
             }
265
264
             else
266
265
             {
267
 
               kdDebug()<<" String end //\n";
 
266
               kdDebug(30517)<<" String end //\n";
268
267
               ok = false;
269
268
             }
270
269
          }
273
272
          textstr = mystr.left (pos);
274
273
          mystr.remove (0, pos+1);
275
274
          mystr.stripWhiteSpace();
276
 
          kdDebug() <<"Text:<" <<textstr <<" > "<< pos<<"  Rest:<"<< mystr<<"> \n";
 
275
          kdDebug(30517) <<"Text:<" <<textstr <<" > "<< pos<<"  Rest:<"<< mystr<<"> \n";
277
276
 
278
277
          // split format
279
278
          QStringList typeList;
284
283
          int nn=0;
285
284
          for (QStringList::Iterator it = typeList.begin(); it != typeList.end(); ++it )
286
285
          {
287
 
            kdDebug() <<"   No: "<< nn<< "   > "<< (*it)<< "< = \n";
 
286
            kdDebug(30517) <<"   No: "<< nn<< "   > "<< (*it)<< "< = \n";
288
287
 
289
288
            // Looking for bold
290
289
            if      ((*it) == "bold")
291
290
            {
292
291
              bold = 1;
293
 
              kdDebug()<<"bold\n";
 
292
              kdDebug(30517)<<"bold\n";
294
293
            }
295
294
            else if ((*it) == "no-bold")
296
295
            {
297
296
              bold = 0;
298
 
              kdDebug()<<"no bold\n";
 
297
              kdDebug(30517)<<"no bold\n";
299
298
            }
300
299
            else if ((*it) == "italic")
301
300
            {
302
301
              italic = 1;
303
 
              kdDebug()<<"italic\n";
 
302
              kdDebug(30517)<<"italic\n";
304
303
            }
305
304
            else if ((*it) == "no-italic")
306
305
            {
307
306
              italic = 0;
308
 
              kdDebug() <<"no italic\n";
 
307
              kdDebug(30517) <<"no italic\n";
309
308
            }
310
309
            else if ((*it) == "underline")
311
310
            {
312
311
              underline = 1;
313
 
              kdDebug()<<"underline\n";
 
312
              kdDebug(30517)<<"underline\n";
314
313
            }
315
314
            else if ((*it) == "no-underline")
316
315
            {
317
316
              underline = 0;
318
 
              kdDebug() <<"no underline\n";
 
317
              kdDebug(30517) <<"no underline\n";
319
318
            }
320
319
            else if ((*it).startsWith ("size"))
321
320
            {
322
321
              (*it).remove (0, 5);
323
322
              sscanf ( (const char *) (*it).latin1(), "%d", &fontsize);
324
 
              kdDebug()<<"fontsize: "<< fontsize<<endl;
 
323
              kdDebug(30517)<<"fontsize: "<< fontsize<<endl;
325
324
            }
326
325
            else if ((*it).startsWith ("face"))
327
326
            {
328
327
              (*it).remove (0, 6);
329
328
              (*it).remove ((*it).length()-1, 1);
330
329
              fontname = *it;
331
 
              kdDebug()<<"fontname: "<<fontname<<endl;
 
330
              kdDebug(30517)<<"fontname: "<<fontname<<endl;
332
331
            }
333
332
            else if ((*it).startsWith ("color:"))
334
333
            {
336
335
              (*it).remove ((*it).length()-1, 1);
337
336
              colname = *it;
338
337
              colpos = mcoltxt.findIndex (colname);
339
 
              kdDebug() <<"  Color: "<< colname<<" "<< colpos <<" \n";
 
338
              kdDebug(30517) <<"  Color: "<< colname<<" "<< colpos <<" \n";
340
339
            }
341
340
            else
342
341
            {
343
 
              kdDebug()<<" "<< (*it)<<endl;
 
342
              kdDebug(30517)<<" "<< (*it)<<endl;
344
343
            }
345
344
 
346
345
 
347
346
          }
348
 
          kdDebug() <<"\n";
 
347
          kdDebug(30517) <<"\n";
349
348
 
350
349
          // Replaces Part for & <>, applixwear special characters and qouts
351
350
          replaceSpecial (textstr);
418
417
    str += "  </FRAMESET>\n";
419
418
    str += " </FRAMESETS>\n";
420
419
    str += "</DOC>\n";
421
 
    kdDebug()<<"Text "<<str.utf8()<<endl;
 
420
    kdDebug(30517)<<"Text "<< str <<endl;
422
421
 
423
422
    KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write );
424
423
    if (!out)
425
424
    {
426
 
        kdError(30502) << "Unable to open output file!" << endl;
 
425
        kdError(30517) << "Unable to open output file!" << endl;
427
426
        in.close  ();
428
427
        return KoFilter::StorageCreationError;
429
428
    }
692
691
  int ok, pos;
693
692
 
694
693
   // 1. Replace Part for this characters: <, >, &
695
 
   textstr.replace (QRegExp ("&"), "&amp;");
696
 
   textstr.replace (QRegExp ("<"), "&lt;");
697
 
   textstr.replace (QRegExp (">"), "&gt;");
 
694
   textstr.replace ('&', "&amp;");
 
695
   textstr.replace ('<', "&lt;");
 
696
   textstr.replace ('>', "&gt;");
698
697
 
699
698
 
700
699
   // 2. Replace part for this characters: applixwear qoutes