~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- DynamicLibrary.cpp - Runtime link/load libraries --------*- C++ -*-===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
//  This header file implements the operating system DynamicLibrary concept.
 
11
//
 
12
// FIXME: This file leaks the ExplicitSymbols and OpenedHandles vector, and is
 
13
// not thread safe!
 
14
//
 
15
//===----------------------------------------------------------------------===//
 
16
 
 
17
#include "llvm/System/DynamicLibrary.h"
 
18
#include "llvm/Config/config.h"
 
19
#include <cstdio>
 
20
#include <cstring>
 
21
#include <map>
 
22
#include <vector>
 
23
 
 
24
// Collection of symbol name/value pairs to be searched prior to any libraries.
 
25
static std::map<std::string, void*> *ExplicitSymbols = 0;
 
26
 
 
27
namespace {
 
28
 
 
29
struct ExplicitSymbolsDeleter {
 
30
  ~ExplicitSymbolsDeleter() {
 
31
    if (ExplicitSymbols)
 
32
      delete ExplicitSymbols;
 
33
  }
 
34
};
 
35
 
 
36
}
 
37
 
 
38
static ExplicitSymbolsDeleter Dummy;
 
39
 
 
40
void llvm::sys::DynamicLibrary::AddSymbol(const char* symbolName,
 
41
                                          void *symbolValue) {
 
42
  if (ExplicitSymbols == 0)
 
43
    ExplicitSymbols = new std::map<std::string, void*>();
 
44
  (*ExplicitSymbols)[symbolName] = symbolValue;
 
45
}
 
46
 
 
47
#ifdef LLVM_ON_WIN32
 
48
 
 
49
#include "Win32/DynamicLibrary.inc"
 
50
 
 
51
#else
 
52
 
 
53
#if 1
 
54
/* CLAMAV LOCAL: no plugins */
 
55
bool llvm::sys::DynamicLibrary::LoadLibraryPermanently(const char *Filename,
 
56
                                            std::string *ErrMsg) {
 
57
    if (ErrMsg) *ErrMsg = "dlopen disabled";
 
58
    return true;
 
59
}
 
60
void* llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
 
61
    return 0;
 
62
}
 
63
#else
 
64
#include <dlfcn.h>
 
65
using namespace llvm;
 
66
using namespace llvm::sys;
 
67
 
 
68
//===----------------------------------------------------------------------===//
 
69
//=== WARNING: Implementation here must contain only TRULY operating system
 
70
//===          independent code.
 
71
//===----------------------------------------------------------------------===//
 
72
 
 
73
static std::vector<void *> *OpenedHandles = 0;
 
74
 
 
75
bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
 
76
                                            std::string *ErrMsg) {
 
77
  void *H = dlopen(Filename, RTLD_LAZY|RTLD_GLOBAL);
 
78
  if (H == 0) {
 
79
    if (ErrMsg) *ErrMsg = dlerror();
 
80
    return true;
 
81
  }
 
82
#ifdef __CYGWIN__
 
83
  // Cygwin searches symbols only in the main
 
84
  // with the handle of dlopen(NULL, RTLD_GLOBAL).
 
85
  if (Filename == NULL)
 
86
    H = RTLD_DEFAULT;
 
87
#endif
 
88
  if (OpenedHandles == 0)
 
89
    OpenedHandles = new std::vector<void *>();
 
90
  OpenedHandles->push_back(H);
 
91
  return false;
 
92
}
 
93
 
 
94
using namespace llvm;
 
95
using namespace llvm::sys;
 
96
 
 
97
bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
 
98
                                            std::string *ErrMsg) {
 
99
  if (ErrMsg) *ErrMsg = "dlopen() not supported on this platform";
 
100
  return true;
 
101
}
 
102
 
 
103
namespace llvm {
 
104
void *SearchForAddressOfSpecialSymbol(const char* symbolName);
 
105
}
 
106
 
 
107
void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {
 
108
  // First check symbols added via AddSymbol().
 
109
  if (ExplicitSymbols) {
 
110
    std::map<std::string, void *>::iterator I =
 
111
      ExplicitSymbols->find(symbolName);
 
112
    std::map<std::string, void *>::iterator E = ExplicitSymbols->end();
 
113
  
 
114
    if (I != E)
 
115
      return I->second;
 
116
  }
 
117
 
 
118
#if HAVE_DLFCN_H
 
119
  // Now search the libraries.
 
120
  if (OpenedHandles) {
 
121
    for (std::vector<void *>::iterator I = OpenedHandles->begin(),
 
122
         E = OpenedHandles->end(); I != E; ++I) {
 
123
      //lt_ptr ptr = lt_dlsym(*I, symbolName);
 
124
      void *ptr = dlsym(*I, symbolName);
 
125
      if (ptr) {
 
126
        return ptr;
 
127
      }
 
128
    }
 
129
  }
 
130
#endif
 
131
 
 
132
  if (void *Result = llvm::SearchForAddressOfSpecialSymbol(symbolName))
 
133
    return Result;
 
134
 
 
135
// This macro returns the address of a well-known, explicit symbol
 
136
#define EXPLICIT_SYMBOL(SYM) \
 
137
   if (!strcmp(symbolName, #SYM)) return &SYM
 
138
 
 
139
// On linux we have a weird situation. The stderr/out/in symbols are both
 
140
// macros and global variables because of standards requirements. So, we 
 
141
// boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
 
142
#if defined(__linux__)
 
143
  {
 
144
    EXPLICIT_SYMBOL(stderr);
 
145
    EXPLICIT_SYMBOL(stdout);
 
146
    EXPLICIT_SYMBOL(stdin);
 
147
  }
 
148
#else
 
149
  // For everything else, we want to check to make sure the symbol isn't defined
 
150
  // as a macro before using EXPLICIT_SYMBOL.
 
151
  {
 
152
#ifndef stdin
 
153
    EXPLICIT_SYMBOL(stdin);
 
154
#endif
 
155
#ifndef stdout
 
156
    EXPLICIT_SYMBOL(stdout);
 
157
#endif
 
158
#ifndef stderr
 
159
    EXPLICIT_SYMBOL(stderr);
 
160
#endif
 
161
  }
 
162
#endif
 
163
#undef EXPLICIT_SYMBOL
 
164
 
 
165
  return 0;
 
166
}
 
167
#endif // LLVM_ON_WIN32
 
168
#endif