'Get this to buffer overflow / Finding Vulnerabilities

I have been set an assignment where I am to find vulnerabilities in the code however I don't seem to be able to find one. I am very new to C and have the basic know how of integer overflow, buffer overflow, and heap overflow as we have been taught this. Below is the file I am supposed to be analysing


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static char input[16];
char * openFile(char * filename, int select);
int readWord(char * argv);

int main(int argc, char ** argv) {
    char * det = "input1.txt";
    char * output;
    int select = 1;
    printf(argc);
    if (argc > 1)
        select = readWord(argv[1]);
    output = openFile(det, select);
    printf("%s\n", output);
}

int readWord(char * argv) {
    int word;
    printf("Which number word do you want selected? ");
    scanf("%d", &word);
    printf("word is %d\n", word);
    strcpy(input, argv);
    return word;
}

char * openFile(char * filename, int select) {
    int x;
    FILE * f0;
    char * fileScan;
    fileScan = malloc(16);
    if ((f0 = fopen(filename, "r")) == NULL) {
        printf("Error\n");
        exit(0);
    }

    for (x = 0; x < (select + 1); x++)
        fscanf(f0, "%s", fileScan);
    fclose(f0);
    return fileScan;
}

And the contents of input1.txt is:

He had never said as much before and I must admit that his words gave me keen pleasure for I had often been piqued by his indifference to my admiration and to the attempts which I had made to give publicity to his methods I was proud too to think that I had so far mastered his system as to apply it in a way which earned his approval He now took the stick from my hands and examined it for a few minutes with his naked eyes Then with an expression of interest he laid down his cigarette and carrying the cane to the window he looked over it again with a convex lens

If anyone could help point me in the right direction it would be greatly appreciated.

c


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source