Changeset 70 in Main for trunk/Server/server.c
- Timestamp:
- Sep 19, 2024, 6:23:45 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/server.c
r68 r70 51 51 SOCKADDR addresses[MAX_PORTS]; 52 52 int sockets[MAX_PORTS]; 53 54 #ifdef __MINGW32__ 55 const char* reserved_names[] = {"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"}; 56 #endif 53 57 54 58 /* https://qiita.com/gyu-don/items/5a640c6d2252a860c8cd */ … … 429 433 int i; 430 434 time_t cmtime = 0; 431 if(req.headers != NULL) {435 if(req.headers != NULL) { 432 436 for(i = 0; req.headers[i] != NULL; i += 2) { 433 437 if(cm_strcaseequ(req.headers[i], "Host")) { … … 480 484 char* path = cm_strcat(vhost_entry->root == NULL ? "" : vhost_entry->root, req.path); 481 485 cm_log("Server", "Filesystem path is %s", path); 486 bool rej = false; 487 #ifdef __MINGW32__ 488 for(i = 0; i < sizeof(reserved_names) / sizeof(reserved_names[0]); i++) { 489 char* n = cm_strcat("/", reserved_names[i]); 490 if(cm_nocase_endswith(path, n)) { 491 tw_http_error(s, sock, 403, name, port); 492 free(n); 493 rej = true; 494 cm_log("Server", "XP Patch ; rejecting access to device"); 495 break; 496 } 497 free(n); 498 char* y = cm_strcat3("/", reserved_names[i], ":"); 499 if(cm_nocase_endswith(path, y)) { 500 tw_http_error(s, sock, 403, name, port); 501 free(y); 502 rej = true; 503 cm_log("Server", "XP Patch ; rejecting access to device"); 504 break; 505 } 506 free(y); 507 } 508 #endif 482 509 struct stat st; 483 if( stat(path, &st) == 0) {510 if(!rej && stat(path, &st) == 0) { 484 511 if(!tw_permission_allowed(path, addr, req, vhost_entry)) { 485 512 tw_http_error(s, sock, 403, name, port); … … 648 675 addstring(&str, "<pre><code>%h</code></pre>\n", rmbuf); 649 676 fclose(fr); 677 free(rmbuf); 650 678 } 651 679 free(fpth); … … 682 710 free(vhost); 683 711 free(host); 684 tw_free_request(&req);685 712 } else if(ret == -1) { 686 713 } else { 687 714 tw_http_error(s, sock, 400, name, port); 688 715 } 716 tw_free_request(&req); 689 717 cleanup: 690 718 #ifndef NO_SSL … … 718 746 #ifdef __MINGW32__ 719 747 struct thread_entry threads[2048]; 720 for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) {748 for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) { 721 749 threads[i].used = false; 722 750 } … … 732 760 if(ret == -1) { 733 761 break; 734 } else if(ret == 0){735 #ifdef __MINGW32__ 736 for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) {737 if(threads[i].used) {762 } else if(ret == 0) { 763 #ifdef __MINGW32__ 764 for(i = 0; i < sizeof(threads) / sizeof(threads[0]); i++) { 765 if(threads[i].used) { 738 766 DWORD ex; 739 767 GetExitCodeThread(threads[i].handle, &ex); 740 if(ex != STILL_ACTIVE) {768 if(ex != STILL_ACTIVE) { 741 769 CloseHandle(threads[i].handle); 742 770 threads[i].used = false; … … 746 774 #endif 747 775 #ifdef SERVICE 748 if(status.dwCurrentState == SERVICE_STOP_PENDING) {776 if(status.dwCurrentState == SERVICE_STOP_PENDING) { 749 777 break; 750 778 } … … 766 794 e->addr = claddr; 767 795 int j; 768 for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {769 if(threads[j].used) {796 for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) { 797 if(threads[j].used) { 770 798 DWORD ex; 771 799 GetExitCodeThread(threads[j].handle, &ex); 772 if(ex != STILL_ACTIVE) {800 if(ex != STILL_ACTIVE) { 773 801 CloseHandle(threads[j].handle); 774 802 threads[j].used = false; … … 776 804 } 777 805 } 778 for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) {779 if(!threads[j].used) {806 for(j = 0; j < sizeof(threads) / sizeof(threads[0]); j++) { 807 if(!threads[j].used) { 780 808 threads[j].handle = (HANDLE)_beginthreadex(NULL, 0, tw_server_pass, e, 0, NULL); 781 809 threads[j].used = true;
Note:
See TracChangeset
for help on using the changeset viewer.