Institute of Computer Science
  1. Courses
  2. 2018/19 spring
  3. Secure Programming Techniques (MTAT.07.015)
ET
Log in

Secure Programming Techniques 2018/19 spring

  • HomePage
  • Lectures
  • Links
  • Homeworks

Homework 4 - deadline May 31th

Find all potential vulnerabilities in this C function:

int get_input(unsigned char *prompt)
{
        unsigned char question[100];
        unsigned char input[80];
        char *addrbuf;
        struct in_addr *addr;
        int i, val, fd;

        sprintf(question, "%s> ", prompt);
        printf(question);
        gets(input);
        if (strlen(input) > 79) {
                printf("Input is too long!\n");
                return 0;
        }
        val = atoi(input);
        if (val > 0) {
                if (access ("/tmp/mydata", O_RDWR)) {
                        fd = open("/tmp/mydata", O_RDWR);
                        addrbuf = malloc(val*sizeof(addr));
                        for (i = 0; i < val; i++) {
                                if (read(0, addrbuf, sizeof(*addr)) < 0)
                                        return 0;
                                write(fd, addrbuf, sizeof(addrbuf));
                        }
                        close(fd);
                } else {
                        printf("You do can not write to output file\n");
                        return 0;
                }
        }
        return val;
}

Please submit the homework below (log in to courses.cs.ut.ee environment with your ut.ee account), plain text is sufficient but PDF is also OK:

4. Homework 4
Solutions for this task can no longer be submitted.
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment