~ubuntu-branches/ubuntu/maverick/clamav/maverick-security

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/System/Path.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-23 14:27:51 UTC
  • mfrom: (0.35.17 sid)
  • Revision ID: james.westby@ubuntu.com-20110223142751-o9xb8jyvhkh75d0n
Tags: 0.96.5+dfsg-1ubuntu1.10.10.2
* SECURITY UPDATE: denial of service via double free in vba processing
  - libclamav/vba_extract.c: set buf to NULL when it gets freed.
  - http://git.clamav.net/gitweb?p=clamav-devel.git;a=commit;h=d21fb8d975f8c9688894a8cef4d50d977022e09f
  - CVE-2011-1003

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
        if (memcmp(magic,"!<arch>\n",8) == 0)
62
62
          return Archive_FileType;
63
63
      break;
64
 
      
 
64
 
65
65
    case '\177':
66
66
      if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') {
67
67
        if (length >= 18 && magic[17] == 0)
76
76
      break;
77
77
 
78
78
    case 0xCA:
79
 
      if (magic[1] == char(0xFE) && magic[2] == char(0xBA) && 
 
79
      if (magic[1] == char(0xFE) && magic[2] == char(0xBA) &&
80
80
          magic[3] == char(0xBE)) {
81
 
        // This is complicated by an overlap with Java class files. 
 
81
        // This is complicated by an overlap with Java class files.
82
82
        // See the Mach-O section in /usr/share/file/magic for details.
83
 
        if (length >= 8 && magic[7] < 43) 
 
83
        if (length >= 8 && magic[7] < 43)
84
84
          // FIXME: Universal Binary of any type.
85
85
          return Mach_O_DynamicallyLinkedSharedLib_FileType;
86
86
      }
89
89
    case 0xFE:
90
90
    case 0xCE: {
91
91
      uint16_t type = 0;
92
 
      if (magic[0] == char(0xFE) && magic[1] == char(0xED) && 
 
92
      if (magic[0] == char(0xFE) && magic[1] == char(0xED) &&
93
93
          magic[2] == char(0xFA) && magic[3] == char(0xCE)) {
94
94
        /* Native endian */
95
95
        if (length >= 16) type = magic[14] << 8 | magic[15];
96
 
      } else if (magic[0] == char(0xCE) && magic[1] == char(0xFA) && 
 
96
      } else if (magic[0] == char(0xCE) && magic[1] == char(0xFA) &&
97
97
                 magic[2] == char(0xED) && magic[3] == char(0xFE)) {
98
98
        /* Reverse endian */
99
99
        if (length >= 14) type = magic[13] << 8 | magic[12];
100
100
      }
101
101
      switch (type) {
102
 
        default: break;      
103
 
        case 1: return Mach_O_Object_FileType; 
 
102
        default: break;
 
103
        case 1: return Mach_O_Object_FileType;
104
104
        case 2: return Mach_O_Executable_FileType;
105
105
        case 3: return Mach_O_FixedVirtualMemorySharedLib_FileType;
106
106
        case 4: return Mach_O_Core_FileType;
136
136
 
137
137
bool
138
138
Path::isArchive() const {
139
 
  if (canRead())
140
 
    return hasMagicNumber("!<arch>\012");
141
 
  return false;
 
139
  return hasMagicNumber("!<arch>\012");
142
140
}
143
141
 
144
142
bool
145
143
Path::isDynamicLibrary() const {
146
 
  if (canRead()) {
147
 
    std::string Magic;
148
 
    if (getMagicNumber(Magic, 64))
149
 
      switch (IdentifyFileType(Magic.c_str(),
150
 
                               static_cast<unsigned>(Magic.length()))) {
151
 
        default: return false;
152
 
        case Mach_O_FixedVirtualMemorySharedLib_FileType:
153
 
        case Mach_O_DynamicallyLinkedSharedLib_FileType:
154
 
        case Mach_O_DynamicallyLinkedSharedLibStub_FileType:
155
 
        case ELF_SharedObject_FileType:
156
 
        case COFF_FileType:  return true;
157
 
      }
158
 
  }
 
144
  std::string Magic;
 
145
  if (getMagicNumber(Magic, 64))
 
146
    switch (IdentifyFileType(Magic.c_str(),
 
147
                             static_cast<unsigned>(Magic.length()))) {
 
148
      default: return false;
 
149
      case Mach_O_FixedVirtualMemorySharedLib_FileType:
 
150
      case Mach_O_DynamicallyLinkedSharedLib_FileType:
 
151
      case Mach_O_DynamicallyLinkedSharedLibStub_FileType:
 
152
      case ELF_SharedObject_FileType:
 
153
      case COFF_FileType:  return true;
 
154
    }
 
155
 
159
156
  return false;
160
157
}
161
158
 
222
219
         "Sep must be a 1-character string literal.");
223
220
  if (path.empty())
224
221
    return ".";
225
 
  
 
222
 
226
223
  // If the path is all slashes, return a single slash.
227
224
  // Otherwise, remove all trailing slashes.
228
 
  
 
225
 
229
226
  signed pos = static_cast<signed>(path.size()) - 1;
230
 
  
 
227
 
231
228
  while (pos >= 0 && path[pos] == Sep[0])
232
229
    --pos;
233
 
  
 
230
 
234
231
  if (pos < 0)
235
232
    return path[0] == Sep[0] ? Sep : ".";
236
 
  
 
233
 
237
234
  // Any slashes left?
238
235
  signed i = 0;
239
 
  
 
236
 
240
237
  while (i < pos && path[i] != Sep[0])
241
238
    ++i;
242
 
  
 
239
 
243
240
  if (i == pos) // No slashes?  Return "."
244
241
    return ".";
245
 
  
246
 
  // There is at least one slash left.  Remove all trailing non-slashes.  
 
242
 
 
243
  // There is at least one slash left.  Remove all trailing non-slashes.
247
244
  while (pos >= 0 && path[pos] != Sep[0])
248
245
    --pos;
249
 
  
 
246
 
250
247
  // Remove any trailing slashes.
251
248
  while (pos >= 0 && path[pos] == Sep[0])
252
249
    --pos;
253
 
  
 
250
 
254
251
  if (pos < 0)
255
252
    return path[0] == Sep[0] ? Sep : ".";
256
 
  
 
253
 
257
254
  return path.substr(0, pos+1);
258
255
}
259
256