freeseaboy 2025. 6. 3. 16:20
반응형

설명 : 대문자 및 소문자를 입력받아 그역으로 출력하는 프로그램

취약점 : 엄청나다.

등급 : 하

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

#define __GNU__IS__NOT__UNIX__
#define g_ARRAY_SZ 24

int main(void){
        char cl_array[g_ARRAY_SZ] = {0,}; //Create buffer
        bool bl_stat_flag = false;
        printf("Insert value\n");
        scanf("%s",cl_array);
        if(g_ARRAY_SZ-1 <= strlen(cl_array)){ //Check value lenght
                printf("Buffer over flow\n");
                return -1;
        }
        for(int i=0;i<g_ARRAY_SZ;++i){
                if(0x00 == cl_array[i]){ // Check null value
                        bl_stat_flag = true;
                        if(0x00 == cl_array[0]){ // Check first null value
                                printf("First value is null\n");
                                return -1;
                        }
                        break;
                }
        }
        __GNU__IS__NOT__UNIX__
        for(int i=0;i<g_ARRAY_SZ;++i){ // Find upper of lower and exange char
                if((char)65 <= cl_array[i] && (char)90 >= cl_array[i]){
                        cl_array[i] = tolower(cl_array[i]);
                        continue;
                }
                cl_array[i] = toupper(cl_array[i]);
        }
        printf("-> %s\n",cl_array);
        return 0;
}
반응형