diff --git a/.gitignore b/.gitignore index f47cb20..bebb0b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.out +/challenge/*.o +/doorchallenge diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..465fd0d --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +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) diff --git a/challenge/challenge.c b/challenge/challenge.c index 7354425..c100906 100644 --- a/challenge/challenge.c +++ b/challenge/challenge.c @@ -1,28 +1,26 @@ +#include #include #include int main() { - int bytes_read; - size_t nbytes = 10; - char **my_string = malloc(sizeof(char**)); + int ret; + size_t nbytes = 0; + char *input_str = NULL; char *password = "23door42\n"; puts("Please enter Password: "); + ret = getline(&input_str, &nbytes, stdin); - bytes_read = getline(my_string, &nbytes, stdin); - - if(bytes_read == -1) { + if (ret == -1) { puts("Error"); - return -1; + } else if (strcmp(input_str, password) == 0) { + puts("Success"); + ret = 0; } else { - if (strcmp(*my_string, password) == 0) { - puts("Success"); - return 0; - } else { - puts("How about no?!"); - return -1; - } + puts("How about no?!"); + ret = -1; } - return 0; + free(input_str); + return ret; } diff --git a/dooropen b/dooropen old mode 100644 new mode 100755 diff --git a/lock b/lock old mode 100644 new mode 100755 diff --git a/unlock b/unlock old mode 100644 new mode 100755