/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugbasedclient.c

  • Committer: Björn Påhlsson
  • Date: 2008-07-20 03:51:41 UTC
  • Revision ID: belorn@braxen-20080720035141-ta0y0be7fotdm4ks
Fixed a overbufferflow bug, thanks to a forgotten \0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- coding: utf-8 -*- */
2
 
/*
3
 
 * Mandos plugin runner - Run Mandos plugins
4
 
 *
5
 
 * Copyright © 2007-2008 Teddy Hogeborn and Björn Påhlsson.
6
 
 * 
7
 
 * This program is free software: you can redistribute it and/or
8
 
 * modify it under the terms of the GNU General Public License as
9
 
 * published by the Free Software Foundation, either version 3 of the
10
 
 * License, or (at your option) any later version.
11
 
 * 
12
 
 * This program is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * General Public License for more details.
16
 
 * 
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program.  If not, see
19
 
 * <http://www.gnu.org/licenses/>.
20
 
 * 
21
 
 * Contact the authors at <https://www.fukt.bsnet.se/~belorn/> and
22
 
 * <https://www.fukt.bsnet.se/~teddy/>.
23
 
 */
24
 
 
25
 
#define _FORTIFY_SOURCE 2
26
 
 
27
1
#include <stdio.h>      /* popen, fileno */
28
2
#include <iso646.h>     /* and, or, not */
29
3
#include <sys/types.h>  /* DIR, opendir, stat, struct stat, waitpid,
33
7
#include <sys/stat.h>   /* stat, struct stat */
34
8
#include <unistd.h>     /* stat, struct stat, chdir */
35
9
#include <stdlib.h>     /* EXIT_FAILURE */
36
 
#include <sys/select.h> /* fd_set, select, FD_ZERO, FD_SET,
37
 
                           FD_ISSET */
 
10
#include <sys/select.h> /* fd_set, select, FD_ZERO, FD_SET, FD_ISSET */
38
11
#include <string.h>     /* strlen, strcpy, strcat */
39
12
#include <stdbool.h>    /* true */
40
13
#include <sys/wait.h>   /* waitpid, WIFEXITED, WEXITSTATUS */
46
19
  pid_t pid;
47
20
  int fd;
48
21
  char *buffer;
49
 
  size_t buffer_size;
50
 
  size_t buffer_length;
 
22
  int buffer_size;
 
23
  int buffer_length;
51
24
  struct process *next;
52
25
} process;
53
26
 
107
80
        close(pipefd[0]);       /* close unused read end of pipe */
108
81
        dup2(pipefd[1], STDOUT_FILENO); /* replace our stdout */
109
82
        /* create a new modified argument list */
110
 
        char **new_argv = malloc(sizeof(char *)
111
 
                                 * ((unsigned int) argc + 1));
 
83
        char **new_argv = malloc(sizeof(char *) * (argc + 1));
112
84
        new_argv[0] = filename;
113
85
        for(int i = 1; i < argc; i++){
114
86
          new_argv[i] = argv[i];
159
131
               > process_itr->buffer_size){
160
132
                process_itr->buffer = realloc(process_itr->buffer,
161
133
                                              process_itr->buffer_size
162
 
                                              + (size_t) BUFFER_SIZE);
 
134
                                              + BUFFER_SIZE);
163
135
                if (process_itr->buffer == NULL){
164
136
                  perror(argv[0]);
165
137
                  goto end;
168
140
            }
169
141
            ret = read(process_itr->fd, process_itr->buffer
170
142
                       + process_itr->buffer_length, BUFFER_SIZE);
171
 
            if(ret < 0){
172
 
              /* Read error from this process; ignore it */
173
 
              continue;
174
 
            }
175
 
            process_itr->buffer_length += (size_t) ret;
 
143
            process_itr->buffer_length+=ret;
176
144
            if(ret == 0){
177
145
              /* got EOF */
178
146
              /* wait for process exit */