Advertisement
Guest User

Vulnerable shared semaphore

a guest
Jan 26th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<stdio.h>
  3. #include<Windows.h>
  4.  
  5. HANDLE semaphore;
  6.  
  7.  
  8. #define NAME "Local\\SemaphoreName"
  9.  
  10. int main() {
  11.  
  12.  
  13.     semaphore = OpenSemaphore(NULL, TRUE, NAME);
  14.     if (semaphore == NULL) {
  15.         semaphore = CreateSemaphore(NULL, 3, 3, NAME);
  16.     }
  17.  
  18.  
  19.     if (semaphore == NULL)
  20.         return EXIT_FAILURE;
  21.  
  22.  
  23.     WaitForSingleObject(semaphore, INFINITE);
  24.  
  25.     printf("Window Opened\n\n");
  26.  
  27.     system("pause");
  28.  
  29.     ReleaseSemaphore(semaphore , 1 , NULL);
  30.     CloseHandle(semaphore);
  31.  
  32.     return EXIT_SUCCESS;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement