Commit 0e62272c authored by gnomus's avatar gnomus
Browse files

Merge branch 'master' into 'master'

memleak bugfix + cleanup + Makefile

- memleak bugfix as free() was missing
- dont call malloc() manually (the old way getline() always called realloc() anyway because of the way the malloc() was written [did not allocate enought memory for the string])
- small minor cleanup
- adding simple Makefile to build door challenge
parents 295b44af e5931c0a
*.out /challenge/*.o
/doorchallenge
TARGET=doorchallenge
CC:=gcc
LD:=$(CC)
LDLIBS=
LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro
CFLAGS=-Wall \
-Wextra \
-Winit-self \
-Wuninitialized \
-Wfloat-equal \
-Wint-to-pointer-cast \
-pedantic \
-O2 \
-fstack-protector-strong
all: $(TARGET)
$(TARGET): challenge/challenge.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
challenge/%.o: challenge/%.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
$(RM) -rf challenge/*.o $(TARGET)
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int main() { int main() {
int bytes_read; int ret;
size_t nbytes = 10; size_t nbytes = 0;
char **my_string = malloc(sizeof(char**)); char *input_str = NULL;
char *password = "23door42\n"; char *password = "23door42\n";
puts("Please enter Password: "); puts("Please enter Password: ");
ret = getline(&input_str, &nbytes, stdin);
bytes_read = getline(my_string, &nbytes, stdin); if (ret == -1) {
if(bytes_read == -1) {
puts("Error"); puts("Error");
return -1; } else if (strcmp(input_str, password) == 0) {
puts("Success");
ret = 0;
} else { } else {
if (strcmp(*my_string, password) == 0) { puts("How about no?!");
puts("Success"); ret = -1;
return 0;
} else {
puts("How about no?!");
return -1;
}
} }
return 0; free(input_str);
return ret;
} }
File mode changed from 100644 to 100755
lock 100644 → 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment