Merge pull request #2 from hmage/master - fiche - A pastebin adjusted for gopher use
 (HTM) git clone git://vernunftzentrum.de/fiche.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit c23aee0900e15be512d525fc72339bb85f397521
 (DIR) parent cb774abf27c10a8ba300a4e4ae11a5c8c2d174df
 (HTM) Author: solusipse <solus1ps3@gmail.com>
       Date:   Tue, 17 Sep 2013 13:35:55 -0700
       
       Merge pull request #2 from hmage/master
       
       Fix segfaults
       Diffstat:
         .gitignore                          |       2 ++
         fiche.c                             |      15 +++++++--------
         fiche.h                             |       5 ++---
       
       3 files changed, 11 insertions(+), 11 deletions(-)
       ---
 (DIR) diff --git a/.gitignore b/.gitignore
       @@ -0,0 +1,2 @@
       +# ignore binaries
       +/fiche
 (DIR) diff --git a/fiche.c b/fiche.c
       @@ -84,8 +84,8 @@ void *thread_connection(void *args)
        
            if (status != -1)
            {
       -        char slug[SLUG_SIZE];
       -        generate_url(buffer, slug);
       +        char slug[SLUG_SIZE+1];
       +        generate_url(buffer, slug, SLUG_SIZE+1);
                save_log(slug, data.ip_address, data.hostname);
                char response[strlen(slug) + strlen(DOMAIN) + 2];
                snprintf(response, sizeof response, "%s%s\n", DOMAIN, slug);
       @@ -256,10 +256,10 @@ void bind_to_port(int listen_socket, struct sockaddr_in server_address)
                error("ERROR while starting listening");
        }
        
       -void generate_url(char *buffer, char *slug)
       +void generate_url(char *buffer, char *slug, size_t slug_length)
        {
            int i;
       -    memset(slug, '\0', sizeof(slug));
       +    memset(slug, '\0', slug_length);
        
            for (i = 0; i <= SLUG_SIZE - 1; i++)
            {
       @@ -278,7 +278,7 @@ void generate_url(char *buffer, char *slug)
        
        int create_directory(char *slug)
        {
       -    char *directory = malloc(strlen(BASEDIR) + strlen(slug));
       +    char *directory = malloc(strlen(BASEDIR) + strlen(slug) + 1);
        
            strcpy(directory, BASEDIR);
            strcat(directory, slug);
       @@ -295,7 +295,7 @@ int create_directory(char *slug)
        
        void save_to_file(char *slug, char *buffer)
        {
       -    char *directory = malloc(strlen(BASEDIR) + strlen(slug) + strlen("/index.txt"));
       +    char *directory = malloc(strlen(BASEDIR) + strlen(slug) + strlen("/index.txt") + 1);
            strcpy(directory, BASEDIR);
            strcat(directory, slug);
            strcat(directory, "/index.txt");
       @@ -391,4 +391,4 @@ void parse_parameters(int argc, char **argv)
                        printf("                     [-l log file] [-b banlist] [-w whitelist]\n");
                        exit(1);
                }
       -}
       -\ No newline at end of file
       +}
 (DIR) diff --git a/fiche.h b/fiche.h
       @@ -67,7 +67,7 @@ void error(char *error_code){perror(error_code); exit(1);}
        void nerror(char *error_code){perror(error_code);}
        void display_date();
        void perform_connection(int listen_socket);
       -void generate_url(char *buffer, char *slug);
       +void generate_url(char *buffer, char *slug, size_t slug_length);
        void save_to_file(char *buffer, char *slug);
        void startup_message();
        void set_basedir();
       @@ -97,4 +97,4 @@ struct client_data
                char *hostname;
        };
        
       -#endif
       -\ No newline at end of file
       +#endif