<commit_before>{ stdenv, fetchurl
, libtool
, python
, perl
, texinfo
, flex
, bison
, gettext
, makeWrapper
, glib
, zlib
, pixman

# Optional Arguments
, SDL2 ? null
, gtk ? null
, vte ? null
, virglrenderer ? null
, nettle ? null
, gnutls ? null
, cyrus_sasl ? null
, libjpeg ? null
, libpng ? null
, ncurses ? null
, curl ? null
, libcap ? null
, attr ? null
, bluez ? null
, libibverbs ? null
, librdmacm ? null
, libuuid ? null
, vde2 ? null
, libaio ? null
, libcap_ng ? null
, spice ? null
, spice_protocol ? null
, libceph ? null
, libxfs ? null
, libcacard ? null
, libusb ? null
, usbredir ? null
, mesa ? null
, epoxy ? null
, lzo ? null
, snappy ? null
, bzip2 ? null
, libseccomp ? null
, glusterfs ? null
, libssh2 ? null
, numactl ? null
, gperftools ? null
, jemalloc ? null

# Audio libraries
, libpulseaudio ? null
, alsaLib ? null

# Extra options
, type ? ""
}:

with stdenv;
with stdenv.lib;
let
  version = "2.5.0";

  isKvmOnly = type == "kvm-only";
  isNix = type == "nix";

  optSDL2 = if isNix then null else shouldUsePkg SDL2;
  optGtk = if isNix then null else shouldUsePkg gtk;
  optVte = if isNix then null else shouldUsePkg vte;
  optVirglrenderer = if isNix then null else shouldUsePkg virglrenderer;
  optLibcap = if isNix then null else shouldUsePkg libcap;
  optAttr = if isNix then null else shouldUsePkg attr;
  optNettle = if isNix then null else shouldUsePkg nettle;
  optGnutls = if isNix || optNettle == null then null else shouldUsePkg gnutls;
  optCyrus_sasl = if isNix then null else shouldUsePkg cyrus_sasl;
  optLibjpeg = if isNix then null else shouldUsePkg libjpeg;
  optLibpng = if isNix then null else shouldUsePkg libpng;
  optNcurses = if isNix then null else shouldUsePkg ncurses;
  optCurl = if isNix then null else shouldUsePkg curl;
  optBluez = if isNix then null else shouldUsePkg bluez;
  optLibibverbs = if isNix then null else shouldUsePkg libibverbs;
  optLibrdmacm = if isNix then null else shouldUsePkg librdmacm;
  optLibuuid = if isNix then null else shouldUsePkg libuuid;
  optVde2 = if isNix then null else shouldUsePkg vde2;
  optLibaio = shouldUsePkg libaio;
  optLibcap_ng = if isNix then null else shouldUsePkg libcap_ng;
  optSpice = if isNix then null else shouldUsePkg spice;
  optSpice_protocol = if isNix then null else shouldUsePkg spice_protocol;
  optLibceph = if isNix then null else shouldUsePkg libceph;
  optLibxfs = if isNix then null else shouldUsePkg libxfs;
  optLibcacard = if isNix then null else shouldUsePkg libcacard;
  optLibusb = if isNix then null else shouldUsePkg libusb;
  optUsbredir = if isNix then null else shouldUsePkg usbredir;
  optMesa = if isNix then null else shouldUsePkg mesa;
  optEpoxy = if isNix then null else shouldUsePkg epoxy;
  optLzo = if isNix then null else shouldUsePkg lzo;
  optSnappy = if isNix then null else shouldUsePkg snappy;
  optBzip2 = if isNix then null else shouldUsePkg bzip2;
  optLibseccomp = if isNix then null else shouldUsePkg libseccomp;
  optGlusterfs = if isNix then null else shouldUsePkg glusterfs;
  optLibssh2 = if isNix then null else shouldUsePkg libssh2;
  optNumactl = if isNix then null else shouldUsePkg numactl;
  optGperftools = if isNix then null else shouldUsePkg gperftools;
  optJemalloc = if isNix then null else shouldUsePkg jemalloc;

  hasSDLAbi = if optSDL2 != null then true else null;

  hasVirtfs = stdenv.isLinux && optLibcap != null && optAttr != null;

  hasVnc = !isNix;
  hasVncTls = hasVnc && optGnutls != null;
  hasVncSasl = hasVnc && optCyrus_sasl != null;
  hasVncJpeg = hasVnc && optLibjpeg != null;
  hasVncPng = hasVnc && optLibpng != null;

  hasFdt = !isNix;

  hasRdma = optLibibverbs != null && optLibrdmacm != null;

  hasLinuxAio = stdenv.isLinux && optLibaio != null;

  hasSpice = optSpice != null && optSpice_protocol != null;

  hasOpengl = optMesa != null && optEpoxy != null;

  optLibpulseaudio = if isNix then null else shouldUsePkg libpulseaudio;
  optAlsaLib = if isNix then null else shouldUsePkg alsaLib;
  audio = concatStringsSep "," (
       optional (optSDL2 != null) "sdl"
    ++ optional (optLibpulseaudio != null) "pa"
    ++ optional (optAlsaLib != null) "alsa"
  );

  systemBinary = if stdenv.system == "x86_64-linux" then "x86_64"
    else if stdenv.system == "i686-linux" then "i386"
    else null;

  targetList = if stdenv.system == "x86_64-linux" then "x86_64-softmmu,i386-softmmu"
    else if stdenv.system == "i686-linux" then "i386-softmmu"
    else null;

  hasModules = !isNix;

  malloc = if optJemalloc != null then "jemalloc" else
    if optGperfTools != null then "tcmalloc" else null;
in

stdenv.mkDerivation rec {
  name = "qemu-${version}${optionalString (type != null && type != "") "-${type}"}";

  src = fetchurl {
    url = "http://wiki.qemu.org/download/qemu-${version}.tar.bz2";
    sha256 = "1m3j6xl7msrniidkvr5pw9d44yba5m7hm42xz8xy77v105s8hhrl";
  };
<commit_msg>qemu: Fix CVE-2015-7549, CVE-2015-8558, CVE-2015-8666, CVE-2015-8744, CVE-2015-8745<commit_after>{ stdenv, fetchurl
, libtool
, python
, perl
, texinfo
, flex
, bison
, gettext
, makeWrapper
, glib
, zlib
, pixman

# Optional Arguments
, SDL2 ? null
, gtk ? null
, vte ? null
, virglrenderer ? null
, nettle ? null
, gnutls ? null
, cyrus_sasl ? null
, libjpeg ? null
, libpng ? null
, ncurses ? null
, curl ? null
, libcap ? null
, attr ? null
, bluez ? null
, libibverbs ? null
, librdmacm ? null
, libuuid ? null
, vde2 ? null
, libaio ? null
, libcap_ng ? null
, spice ? null
, spice_protocol ? null
, libceph ? null
, libxfs ? null
, libcacard ? null
, libusb ? null
, usbredir ? null
, mesa ? null
, epoxy ? null
, lzo ? null
, snappy ? null
, bzip2 ? null
, libseccomp ? null
, glusterfs ? null
, libssh2 ? null
, numactl ? null
, gperftools ? null
, jemalloc ? null

# Audio libraries
, libpulseaudio ? null
, alsaLib ? null

# Extra options
, type ? ""
}:

with stdenv;
with stdenv.lib;
let
  version = "2.5.0";

  isKvmOnly = type == "kvm-only";
  isNix = type == "nix";

  optSDL2 = if isNix then null else shouldUsePkg SDL2;
  optGtk = if isNix then null else shouldUsePkg gtk;
  optVte = if isNix then null else shouldUsePkg vte;
  optVirglrenderer = if isNix then null else shouldUsePkg virglrenderer;
  optLibcap = if isNix then null else shouldUsePkg libcap;
  optAttr = if isNix then null else shouldUsePkg attr;
  optNettle = if isNix then null else shouldUsePkg nettle;
  optGnutls = if isNix || optNettle == null then null else shouldUsePkg gnutls;
  optCyrus_sasl = if isNix then null else shouldUsePkg cyrus_sasl;
  optLibjpeg = if isNix then null else shouldUsePkg libjpeg;
  optLibpng = if isNix then null else shouldUsePkg libpng;
  optNcurses = if isNix then null else shouldUsePkg ncurses;
  optCurl = if isNix then null else shouldUsePkg curl;
  optBluez = if isNix then null else shouldUsePkg bluez;
  optLibibverbs = if isNix then null else shouldUsePkg libibverbs;
  optLibrdmacm = if isNix then null else shouldUsePkg librdmacm;
  optLibuuid = if isNix then null else shouldUsePkg libuuid;
  optVde2 = if isNix then null else shouldUsePkg vde2;
  optLibaio = shouldUsePkg libaio;
  optLibcap_ng = if isNix then null else shouldUsePkg libcap_ng;
  optSpice = if isNix then null else shouldUsePkg spice;
  optSpice_protocol = if isNix then null else shouldUsePkg spice_protocol;
  optLibceph = if isNix then null else shouldUsePkg libceph;
  optLibxfs = if isNix then null else shouldUsePkg libxfs;
  optLibcacard = if isNix then null else shouldUsePkg libcacard;
  optLibusb = if isNix then null else shouldUsePkg libusb;
  optUsbredir = if isNix then null else shouldUsePkg usbredir;
  optMesa = if isNix then null else shouldUsePkg mesa;
  optEpoxy = if isNix then null else shouldUsePkg epoxy;
  optLzo = if isNix then null else shouldUsePkg lzo;
  optSnappy = if isNix then null else shouldUsePkg snappy;
  optBzip2 = if isNix then null else shouldUsePkg bzip2;
  optLibseccomp = if isNix then null else shouldUsePkg libseccomp;
  optGlusterfs = if isNix then null else shouldUsePkg glusterfs;
  optLibssh2 = if isNix then null else shouldUsePkg libssh2;
  optNumactl = if isNix then null else shouldUsePkg numactl;
  optGperftools = if isNix then null else shouldUsePkg gperftools;
  optJemalloc = if isNix then null else shouldUsePkg jemalloc;

  hasSDLAbi = if optSDL2 != null then true else null;

  hasVirtfs = stdenv.isLinux && optLibcap != null && optAttr != null;

  hasVnc = !isNix;
  hasVncTls = hasVnc && optGnutls != null;
  hasVncSasl = hasVnc && optCyrus_sasl != null;
  hasVncJpeg = hasVnc && optLibjpeg != null;
  hasVncPng = hasVnc && optLibpng != null;

  hasFdt = !isNix;

  hasRdma = optLibibverbs != null && optLibrdmacm != null;

  hasLinuxAio = stdenv.isLinux && optLibaio != null;

  hasSpice = optSpice != null && optSpice_protocol != null;

  hasOpengl = optMesa != null && optEpoxy != null;

  optLibpulseaudio = if isNix then null else shouldUsePkg libpulseaudio;
  optAlsaLib = if isNix then null else shouldUsePkg alsaLib;
  audio = concatStringsSep "," (
       optional (optSDL2 != null) "sdl"
    ++ optional (optLibpulseaudio != null) "pa"
    ++ optional (optAlsaLib != null) "alsa"
  );

  systemBinary = if stdenv.system == "x86_64-linux" then "x86_64"
    else if stdenv.system == "i686-linux" then "i386"
    else null;

  targetList = if stdenv.system == "x86_64-linux" then "x86_64-softmmu,i386-softmmu"
    else if stdenv.system == "i686-linux" then "i386-softmmu"
    else null;

  hasModules = !isNix;

  malloc = if optJemalloc != null then "jemalloc" else
    if optGperfTools != null then "tcmalloc" else null;

  fetchpatch = cve: hash: sha256: fetchurl {
    name = "${cve}.patch";
    url = "http://git.qemu.org/?p=qemu.git;a=patch;h=${hash}";
    inherit sha256;
  };
in

stdenv.mkDerivation rec {
  name = "qemu-${version}${optionalString (type != null && type != "") "-${type}"}";

  src = fetchurl {
    url = "http://wiki.qemu.org/download/qemu-${version}.tar.bz2";
    sha256 = "1m3j6xl7msrniidkvr5pw9d44yba5m7hm42xz8xy77v105s8hhrl";
  };

  patches = [
    # All CVE's for 2.5.0, hopefully removed in 2.5.1+
    (fetchpatch "CVE-2015-7549" "43b11a91dd861a946b231b89b754285" "1ch9xkbd8c2r28jqkxcq0s2lmix2qhny8ynb4ymnxyk0bkml1pvi")
    (fetchpatch "CVE-2015-8558" "156a2e4dbffa85997636a7a39ef12da6f1b40254" "1j5l3fr2623wyyry1hnydj0d4l5j51ynzblwmjbm6v7801rix0dj")
    (fetchpatch "CVE-2015-8666" "d9a3b33d2c9f996537b7f1d0246dee2d0120cefb" "1c1gx9qy24d3yps1717id9pqpm13k4wggidzhh2cs0ncziqaq3lb")
    (fetchpatch "CVE-2015-8744" "a7278b36fcab9af469563bd7b" "05mmbdikh4vvgqk4kr22pzddjzvfyyykmgqc5h3ip4pfd9b555h6")
    (fetchpatch "CVE-2015-8745" "c6048f849c7e3f009786df76206e895" "0a20qh54f0k4nq9bqmkh96f2pll8djwg1n2j4jj4j0nnys41dw3j")
  ];

{'fraction_non_alphanumeric': 0.08940891292187209, 'fraction_numerical': 0.03962334514264404, 'mean_word_length': 4.08147797252487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '972363', 'n_tokens_mistral': 4483, 'n_tokens_neox': 4182, 'n_words': 1160}