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
This commit is contained in:
commit
0e62272c44
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*.out
|
/challenge/*.o
|
||||||
|
/doorchallenge
|
||||||
|
|
27
Makefile
Normal file
27
Makefile
Normal file
|
@ -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)
|
|
@ -1,28 +1,26 @@
|
||||||
|
#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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue