~ubuntu-branches/ubuntu/lucid/mysql-dfsg-5.1/lucid-security

« back to all changes in this revision

Viewing changes to storage/ibmdb2i/db2i_misc.h

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 22:33:55 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120222223355-or06x1euyk8n0ldi
Tags: 5.1.61-0ubuntu0.10.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496
* Dropped patches unnecessary with 5.1.61:
  - debian/patches/90_mysql_safer_strmov.dpatch
  - debian/patches/51_ssl_test_certs.dpatch
  - debian/patches/52_CVE-2009-4030.dpatch
  - debian/patches/53_CVE-2009-4484.dpatch
  - debian/patches/54_CVE-2008-7247.dpatch
  - debian/patches/55_CVE-2010-1621.dpatch
  - debian/patches/56_CVE-2010-1850.dpatch
  - debian/patches/57_CVE-2010-1849.dpatch
  - debian/patches/58_CVE-2010-1848.dpatch
  - debian/patches/59_CVE-2010-1626.dpatch
  - debian/patches/60_CVE-2010-2008.dpatch
  - debian/patches/60_CVE-2010-3677.dpatch
  - debian/patches/60_CVE-2010-3678.dpatch
  - debian/patches/60_CVE-2010-3679.dpatch
  - debian/patches/60_CVE-2010-3680.dpatch
  - debian/patches/60_CVE-2010-3681.dpatch
  - debian/patches/60_CVE-2010-3682.dpatch
  - debian/patches/60_CVE-2010-3683.dpatch
  - debian/patches/60_CVE-2010-3833.dpatch
  - debian/patches/60_CVE-2010-3834.dpatch
  - debian/patches/60_CVE-2010-3835.dpatch
  - debian/patches/60_CVE-2010-3836.dpatch
  - debian/patches/60_CVE-2010-3837.dpatch
  - debian/patches/60_CVE-2010-3838.dpatch
  - debian/patches/60_CVE-2010-3839.dpatch
  - debian/patches/60_CVE-2010-3840.dpatch
  - debian/patches/61_disable_longfilename_test.dpatch
  - debian/patches/62_alter_table_fix.dpatch
  - debian/patches/63_cherrypick-upstream-49479.dpatch
  - debian/patches/10_readline_build_fix.dpatch
* debian/mysql-client-5.1.docs: removed EXCEPTIONS-CLIENT file
* debian/mysql-server-5.1.docs,debian/libmysqlclient16.docs,
  debian/libmysqlclient-dev.docs: removed, no longer necessary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Licensed Materials - Property of IBM
3
 
DB2 Storage Engine Enablement
4
 
Copyright IBM Corporation 2007,2008
5
 
All rights reserved
6
 
 
7
 
Redistribution and use in source and binary forms, with or without modification,
8
 
are permitted provided that the following conditions are met: 
9
 
 (a) Redistributions of source code must retain this list of conditions, the
10
 
     copyright notice in section {d} below, and the disclaimer following this
11
 
     list of conditions. 
12
 
 (b) Redistributions in binary form must reproduce this list of conditions, the
13
 
     copyright notice in section (d) below, and the disclaimer following this
14
 
     list of conditions, in the documentation and/or other materials provided
15
 
     with the distribution. 
16
 
 (c) The name of IBM may not be used to endorse or promote products derived from
17
 
     this software without specific prior written permission. 
18
 
 (d) The text of the required copyright notice is: 
19
 
       Licensed Materials - Property of IBM
20
 
       DB2 Storage Engine Enablement 
21
 
       Copyright IBM Corporation 2007,2008 
22
 
       All rights reserved
23
 
 
24
 
THIS SOFTWARE IS PROVIDED BY IBM CORPORATION "AS IS" AND ANY EXPRESS OR IMPLIED
25
 
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26
 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27
 
SHALL IBM CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
 
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29
 
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
 
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
 
CONTRACT, STRICT LIABILITY, OR TORT INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32
 
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33
 
OF SUCH DAMAGE.
34
 
*/
35
 
 
36
 
#ifndef DB2I_MISC_H
37
 
#define DB2I_MISC_H
38
 
 
39
 
/**
40
 
  Undelimit quote-delimited DB2 names in-place
41
 
*/
42
 
void stripExtraQuotes(char* name, uint maxLen)
43
 
{
44
 
  char* oldName = (char*)sql_strdup(name);
45
 
  uint i = 0;
46
 
  uint j = 0;
47
 
  do
48
 
  {
49
 
    name[j] = oldName[i];
50
 
    if (oldName[i] == '"' && oldName[i+1] == '"')
51
 
      ++i;
52
 
  } while (++j < maxLen && oldName[++i]);
53
 
  
54
 
  if (j == maxLen)
55
 
    --j;
56
 
  name[j] = 0;
57
 
}
58
 
 
59
 
/**
60
 
  Convert a MySQL identifier name into a DB2 compatible format
61
 
  
62
 
  @parm input  The MySQL name
63
 
  @parm output  The DB2 name
64
 
  @parm outlen  The amount of space allocated for output
65
 
  @parm delimit  Should delimiting quotes be placed around the converted name?
66
 
  @parm delimitQuotes  Should quotes in the MySQL be delimited with additional quotes?
67
 
  
68
 
  @return FALSE if output was too small and name was truncated; TRUE otherwise
69
 
*/
70
 
bool convertMySQLNameToDB2Name(const char* input, 
71
 
                               char* output, 
72
 
                               size_t outlen,
73
 
                               bool delimit = true,
74
 
                               bool delimitQuotes = true)
75
 
{
76
 
  uint o = 0;
77
 
  if (delimit)
78
 
    output[o++] = '"';    
79
 
 
80
 
  uint i = 0;
81
 
  do
82
 
  {
83
 
    output[o] = input[i];
84
 
    if (delimitQuotes && input[i] == '"')
85
 
      output[++o] = '"';
86
 
  } while (++o < outlen-2 && input[++i]);
87
 
  
88
 
  if (delimit)
89
 
    output[o++] = '"';
90
 
  output[min(o, outlen-1)] = 0; // This isn't the most user-friendly way to handle overflows,
91
 
                                  // but at least its safe.
92
 
  return (o <= outlen-1);
93
 
}
94
 
 
95
 
bool isOrdinaryIdentifier(const char* s)
96
 
{
97
 
  while (*s)
98
 
  {
99
 
    if (my_isupper(system_charset_info, *s) ||
100
 
        my_isdigit(system_charset_info, *s) ||
101
 
        (*s == '_') ||
102
 
        (*s == '@') ||
103
 
        (*s == '$') ||
104
 
        (*s == '#') ||
105
 
        (*s == '"'))
106
 
      ++s;
107
 
    else
108
 
      return false;
109
 
  }
110
 
  return true;
111
 
}
112
 
 
113
 
/**
114
 
  Fill memory with a 16-bit word.
115
 
  
116
 
  @param p  Pointer to space to fill.
117
 
  @param v  Value to fill
118
 
  @param l  Length of space (in 16-bit words)
119
 
*/
120
 
void memset16(void* p, uint16 v, size_t l)
121
 
{
122
 
  uint16* p2=(uint16*)p;
123
 
  while (l--)
124
 
  {
125
 
    *(p2++) = v;
126
 
  }
127
 
}
128
 
 
129
 
#endif