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

« back to all changes in this revision

Viewing changes to kexi/core/kexivalidator.cpp

  • 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:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
 
3
 
 
4
   This program is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this program; see the file COPYING.  If not, write to
 
16
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include "kexivalidator.h"
 
21
 
 
22
KexiValidator::KexiValidator(QObject * parent, const char * name)
 
23
: QValidator(parent,name)
 
24
, m_acceptsEmptyValue(false)
 
25
{
 
26
}
 
27
 
 
28
KexiValidator::~KexiValidator()
 
29
{
 
30
}
 
31
 
 
32
KexiValidator::Result KexiValidator::check(const QString &valueName, const QVariant& v, 
 
33
        QString &message, QString &details)
 
34
{
 
35
        if (v.isNull() || v.type()==QVariant::String && v.toString().isEmpty()) {
 
36
                if (!m_acceptsEmptyValue) {
 
37
                        message = KexiValidator::msgColumnNotEmpty().arg(valueName);
 
38
                        return Error;
 
39
                }
 
40
                return Ok;
 
41
        }
 
42
        return internalCheck(valueName, v, message, details);
 
43
}
 
44
 
 
45
KexiValidator::Result KexiValidator::internalCheck(const QString & /*valueName*/, 
 
46
        const QVariant& /*v*/, QString & /*message*/, QString & /*details*/)
 
47
{
 
48
        return Error;
 
49
}
 
50
 
 
51
QValidator::State KexiValidator::validate ( QString & , int & ) const
 
52
{
 
53
        return QValidator::Acceptable;
 
54
}
 
55
 
 
56
//-----------------------------------------------------------
 
57
 
 
58
KexiMultiValidator::KexiMultiValidator(QObject* parent, const char * name)
 
59
 : KexiValidator(parent, name)
 
60
{
 
61
        m_ownedSubValidators.setAutoDelete(true);
 
62
}
 
63
 
 
64
KexiMultiValidator::KexiMultiValidator(KexiValidator *validator, 
 
65
        QObject * parent, const char * name)
 
66
 : KexiValidator(parent, name)
 
67
{
 
68
        addSubvalidator(validator);
 
69
}
 
70
 
 
71
 
 
72
void KexiMultiValidator::addSubvalidator( KexiValidator* validator, bool owned )
 
73
{
 
74
        if (!validator)
 
75
                return;
 
76
        m_subValidators.append(validator);
 
77
        if (owned && !validator->parent())
 
78
                m_ownedSubValidators.append(validator);
 
79
}
 
80
 
 
81
QValidator::State KexiMultiValidator::validate( QString & input, int & pos ) const
 
82
{
 
83
        if (m_subValidators.isEmpty())
 
84
                return Invalid;
 
85
        State s;
 
86
        QValueList<KexiValidator*>::const_iterator it;
 
87
        for ( it=m_subValidators.constBegin(); it!=m_subValidators.constEnd(); ++it) {
 
88
                s = (*it)->validate(input, pos);
 
89
                if (s==Intermediate || s==Invalid)
 
90
                        return s;
 
91
        }
 
92
        return Acceptable;
 
93
}
 
94
 
 
95
void KexiMultiValidator::fixup ( QString & input ) const
 
96
{
 
97
        QValueList<KexiValidator*>::const_iterator it;
 
98
        for ( it=m_subValidators.constBegin(); it!=m_subValidators.constEnd(); ++it) {
 
99
                (*it)->fixup(input);
 
100
        }
 
101
}
 
102
 
 
103
KexiValidator::Result KexiMultiValidator::internalCheck(
 
104
        const QString &valueName, const QVariant& v, 
 
105
        QString &message, QString &details)
 
106
{
 
107
        if (m_subValidators.isEmpty())
 
108
                return Error;
 
109
        Result r;
 
110
        bool warning = false;
 
111
        QValueList<KexiValidator*>::const_iterator it;
 
112
        for ( it=m_subValidators.begin(); it!=m_subValidators.end(); ++it) {
 
113
                r = (*it)->internalCheck(valueName, v, message, details);
 
114
                if (r==Error)
 
115
                        return Error;
 
116
                if (r==Warning)
 
117
                        warning = true;
 
118
        }
 
119
        return warning ? Warning : Ok;
 
120
}
 
121