/mandos/release

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

« back to all changes in this revision

Viewing changes to plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2014-03-23 22:12:57 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 311.
  • Revision ID: teddy@recompile.se-20140323221257-9lkufevfdn4kwoq6
Use openat() etc. in plugin-runner.  Also one less useless warning.

* plugin-runner.c (main): Only print warning about failure to work
                          around Debian bug #633582 if the plugin
                          directory actually exists.  Use openat(),
                          fstat(), faccessat(), and eliminate
                          asprintf().

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/*
3
3
 * Mandos plugin runner - Run Mandos plugins
4
4
 *
5
 
 * Copyright © 2008-2010 Teddy Hogeborn
6
 
 * Copyright © 2008-2010 Björn Påhlsson
 
5
 * Copyright © 2008-2013 Teddy Hogeborn
 
6
 * Copyright © 2008-2013 Björn Påhlsson
7
7
 * 
8
8
 * This program is free software: you can redistribute it and/or
9
9
 * modify it under the terms of the GNU General Public License as
19
19
 * along with this program.  If not, see
20
20
 * <http://www.gnu.org/licenses/>.
21
21
 * 
22
 
 * Contact the authors at <mandos@fukt.bsnet.se>.
 
22
 * Contact the authors at <mandos@recompile.se>.
23
23
 */
24
24
 
25
25
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
26
 
                                   asprintf(), O_CLOEXEC */
 
26
                                   O_CLOEXEC */
27
27
#include <stddef.h>             /* size_t, NULL */
28
28
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
29
29
                                   realloc() */
30
30
#include <stdbool.h>            /* bool, true, false */
31
31
#include <stdio.h>              /* fileno(), fprintf(),
32
 
                                   stderr, STDOUT_FILENO */
33
 
#include <sys/types.h>          /* DIR, fdopendir(), stat(), struct
 
32
                                   stderr, STDOUT_FILENO, fclose() */
 
33
#include <sys/types.h>          /* DIR, fdopendir(), fstat(), struct
34
34
                                   stat, waitpid(), WIFEXITED(),
35
35
                                   WEXITSTATUS(), wait(), pid_t,
36
36
                                   uid_t, gid_t, getuid(), getgid(),
40
40
#include <sys/wait.h>           /* wait(), waitpid(), WIFEXITED(),
41
41
                                   WEXITSTATUS(), WTERMSIG(),
42
42
                                   WCOREDUMP() */
43
 
#include <sys/stat.h>           /* struct stat, stat(), S_ISREG() */
 
43
#include <sys/stat.h>           /* struct stat, fstat(), S_ISREG() */
44
44
#include <iso646.h>             /* and, or, not */
45
45
#include <dirent.h>             /* DIR, struct dirent, fdopendir(),
46
46
                                   readdir(), closedir(), dirfd() */
47
 
#include <unistd.h>             /* struct stat, stat(), S_ISREG(),
48
 
                                   fcntl(), setuid(), setgid(),
49
 
                                   F_GETFD, F_SETFD, FD_CLOEXEC,
50
 
                                   access(), pipe(), fork(), close()
51
 
                                   dup2(), STDOUT_FILENO, _exit(),
52
 
                                   execv(), write(), read(),
53
 
                                   close() */
 
47
#include <unistd.h>             /* fcntl(), F_GETFD, F_SETFD,
 
48
                                   FD_CLOEXEC, write(), STDOUT_FILENO,
 
49
                                   struct stat, fstat(), close(),
 
50
                                   setgid(), setuid(), S_ISREG(),
 
51
                                   faccessat() pipe(), fork(),
 
52
                                   _exit(), dup2(), fexecve(), read()
 
53
                                */
54
54
#include <fcntl.h>              /* fcntl(), F_GETFD, F_SETFD,
55
 
                                   FD_CLOEXEC */
56
 
#include <string.h>             /* strsep, strlen(), asprintf(),
57
 
                                   strsignal(), strcmp(), strncmp() */
 
55
                                   FD_CLOEXEC, openat() */
 
56
#include <string.h>             /* strsep, strlen(), strsignal(),
 
57
                                   strcmp(), strncmp() */
58
58
#include <errno.h>              /* errno */
59
59
#include <argp.h>               /* struct argp_option, struct
60
60
                                   argp_state, struct argp,
79
79
#define AFILE "/conf/conf.d/mandos/plugin-runner.conf"
80
80
 
81
81
const char *argp_program_version = "plugin-runner " VERSION;
82
 
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
 
82
const char *argp_program_bug_address = "<mandos@recompile.se>";
83
83
 
84
84
typedef struct plugin{
85
85
  char *name;                   /* can be NULL or any plugin name */
105
105
 
106
106
/* Gets an existing plugin based on name,
107
107
   or if none is found, creates a new one */
 
108
__attribute__((warn_unused_result))
108
109
static plugin *getplugin(char *name){
109
110
  /* Check for existing plugin with that name */
110
111
  for(plugin *p = plugin_list; p != NULL; p = p->next){
171
172
}
172
173
 
173
174
/* Helper function for add_argument and add_environment */
 
175
__attribute__((nonnull, warn_unused_result))
174
176
static bool add_to_char_array(const char *new, char ***array,
175
177
                              int *len){
176
178
  /* Resize the pointed-to array to hold one more pointer */
 
179
  char **new_array = NULL;
177
180
  do {
178
 
    *array = realloc(*array, sizeof(char *)
179
 
                     * (size_t) ((*len) + 2));
180
 
  } while(*array == NULL and errno == EINTR);
 
181
    new_array = realloc(*array, sizeof(char *)
 
182
                        * (size_t) ((*len) + 2));
 
183
  } while(new_array == NULL and errno == EINTR);
181
184
  /* Malloc check */
182
 
  if(*array == NULL){
 
185
  if(new_array == NULL){
183
186
    return false;
184
187
  }
 
188
  *array = new_array;
185
189
  /* Make a copy of the new string */
186
190
  char *copy;
187
191
  do {
199
203
}
200
204
 
201
205
/* Add to a plugin's argument vector */
 
206
__attribute__((nonnull(2), warn_unused_result))
202
207
static bool add_argument(plugin *p, const char *arg){
203
208
  if(p == NULL){
204
209
    return false;
207
212
}
208
213
 
209
214
/* Add to a plugin's environment */
 
215
__attribute__((nonnull(2), warn_unused_result))
210
216
static bool add_environment(plugin *p, const char *def, bool replace){
211
217
  if(p == NULL){
212
218
    return false;
214
220
  /* namelen = length of name of environment variable */
215
221
  size_t namelen = (size_t)(strchrnul(def, '=') - def);
216
222
  /* Search for this environment variable */
217
 
  for(char **e = p->environ; *e != NULL; e++){
218
 
    if(strncmp(*e, def, namelen + 1) == 0){
 
223
  for(char **envdef = p->environ; *envdef != NULL; envdef++){
 
224
    if(strncmp(*envdef, def, namelen + 1) == 0){
219
225
      /* It already exists */
220
226
      if(replace){
221
 
        char *new;
 
227
        char *new_envdef;
222
228
        do {
223
 
          new = realloc(*e, strlen(def) + 1);
224
 
        } while(new == NULL and errno == EINTR);
225
 
        if(new == NULL){
 
229
          new_envdef = realloc(*envdef, strlen(def) + 1);
 
230
        } while(new_envdef == NULL and errno == EINTR);
 
231
        if(new_envdef == NULL){
226
232
          return false;
227
233
        }
228
 
        *e = new;
229
 
        strcpy(*e, def);
 
234
        *envdef = new_envdef;
 
235
        strcpy(*envdef, def);
230
236
      }
231
237
      return true;
232
238
    }
239
245
 * Descriptor Flags".
240
246
 | [[info:libc:Descriptor%20Flags][File Descriptor Flags]] |
241
247
 */
 
248
__attribute__((warn_unused_result))
242
249
static int set_cloexec_flag(int fd){
243
250
  int ret = (int)TEMP_FAILURE_RETRY(fcntl(fd, F_GETFD, 0));
244
251
  /* If reading the flags failed, return error indication now. */
286
293
}
287
294
 
288
295
/* Prints out a password to stdout */
 
296
__attribute__((nonnull, warn_unused_result))
289
297
static bool print_out_password(const char *buffer, size_t length){
290
298
  ssize_t ret;
291
299
  for(size_t written = 0; written < length; written += (size_t)ret){
299
307
}
300
308
 
301
309
/* Removes and free a plugin from the plugin list */
 
310
__attribute__((nonnull))
302
311
static void free_plugin(plugin *plugin_node){
303
312
  
304
313
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
354
363
                                      .sa_flags = SA_NOCLDSTOP };
355
364
  char **custom_argv = NULL;
356
365
  int custom_argc = 0;
 
366
  int dir_fd;
357
367
  
358
368
  /* Establish a signal handler */
359
369
  sigemptyset(&sigchld_action.sa_mask);
416
426
    { .name = NULL }
417
427
  };
418
428
  
 
429
  __attribute__((nonnull(3)))
419
430
  error_t parse_opt(int key, char *arg, struct argp_state *state){
420
431
    errno = 0;
421
432
    switch(key){
422
433
      char *tmp;
423
 
      intmax_t tmpmax;
 
434
      intmax_t tmp_id;
424
435
    case 'g':                   /* --global-options */
425
436
      {
426
437
        char *plugin_option;
429
440
            break;
430
441
          }
431
442
        }
 
443
        errno = 0;
432
444
      }
433
445
      break;
434
446
    case 'G':                   /* --global-env */
435
 
      add_environment(getplugin(NULL), arg, true);
 
447
      if(add_environment(getplugin(NULL), arg, true)){
 
448
        errno = 0;
 
449
      }
436
450
      break;
437
451
    case 'o':                   /* --options-for */
438
452
      {
455
469
            break;
456
470
          }
457
471
        }
 
472
        errno = 0;
458
473
      }
459
474
      break;
460
475
    case 'E':                   /* --env-for */
472
487
          errno = EINVAL;
473
488
          break;
474
489
        }
475
 
        add_environment(getplugin(arg), envdef, true);
 
490
        if(add_environment(getplugin(arg), envdef, true)){
 
491
          errno = 0;
 
492
        }
476
493
      }
477
494
      break;
478
495
    case 'd':                   /* --disable */
480
497
        plugin *p = getplugin(arg);
481
498
        if(p != NULL){
482
499
          p->disabled = true;
 
500
          errno = 0;
483
501
        }
484
502
      }
485
503
      break;
488
506
        plugin *p = getplugin(arg);
489
507
        if(p != NULL){
490
508
          p->disabled = false;
 
509
          errno = 0;
491
510
        }
492
511
      }
493
512
      break;
494
513
    case 128:                   /* --plugin-dir */
495
514
      free(plugindir);
496
515
      plugindir = strdup(arg);
 
516
      if(plugindir != NULL){
 
517
        errno = 0;
 
518
      }
497
519
      break;
498
520
    case 129:                   /* --config-file */
499
521
      /* This is already done by parse_opt_config_file() */
500
522
      break;
501
523
    case 130:                   /* --userid */
502
 
      tmpmax = strtoimax(arg, &tmp, 10);
 
524
      tmp_id = strtoimax(arg, &tmp, 10);
503
525
      if(errno != 0 or tmp == arg or *tmp != '\0'
504
 
         or tmpmax != (uid_t)tmpmax){
 
526
         or tmp_id != (uid_t)tmp_id){
505
527
        argp_error(state, "Bad user ID number: \"%s\", using %"
506
528
                   PRIdMAX, arg, (intmax_t)uid);
507
529
        break;
508
530
      }
509
 
      uid = (uid_t)tmpmax;
 
531
      uid = (uid_t)tmp_id;
 
532
      errno = 0;
510
533
      break;
511
534
    case 131:                   /* --groupid */
512
 
      tmpmax = strtoimax(arg, &tmp, 10);
 
535
      tmp_id = strtoimax(arg, &tmp, 10);
513
536
      if(errno != 0 or tmp == arg or *tmp != '\0'
514
 
         or tmpmax != (gid_t)tmpmax){
 
537
         or tmp_id != (gid_t)tmp_id){
515
538
        argp_error(state, "Bad group ID number: \"%s\", using %"
516
539
                   PRIdMAX, arg, (intmax_t)gid);
517
540
        break;
518
541
      }
519
 
      gid = (gid_t)tmpmax;
 
542
      gid = (gid_t)tmp_id;
 
543
      errno = 0;
520
544
      break;
521
545
    case 132:                   /* --debug */
522
546
      debug = true;
570
594
    case 129:                   /* --config-file */
571
595
      free(argfile);
572
596
      argfile = strdup(arg);
 
597
      if(argfile != NULL){
 
598
        errno = 0;
 
599
      }
573
600
      break;
574
601
    case 130:                   /* --userid */
575
602
    case 131:                   /* --groupid */
658
685
        }
659
686
        
660
687
        custom_argc += 1;
661
 
        custom_argv = realloc(custom_argv, sizeof(char *)
662
 
                              * ((unsigned int) custom_argc + 1));
663
 
        if(custom_argv == NULL){
664
 
          error(0, errno, "realloc");
665
 
          exitstatus = EX_OSERR;
666
 
          free(org_line);
667
 
          goto fallback;
 
688
        {
 
689
          char **new_argv = realloc(custom_argv, sizeof(char *)
 
690
                                    * ((unsigned int)
 
691
                                       custom_argc + 1));
 
692
          if(new_argv == NULL){
 
693
            error(0, errno, "realloc");
 
694
            exitstatus = EX_OSERR;
 
695
            free(new_arg);
 
696
            free(org_line);
 
697
            goto fallback;
 
698
          } else {
 
699
            custom_argv = new_argv;
 
700
          }
668
701
        }
669
702
        custom_argv[custom_argc-1] = new_arg;
670
703
        custom_argv[custom_argc] = NULL;
742
775
    }
743
776
  }
744
777
  
745
 
  /* Strip permissions down to nobody */
746
 
  setgid(gid);
 
778
  if(getuid() == 0){
 
779
    /* Work around Debian bug #633582:
 
780
       <http://bugs.debian.org/633582> */
 
781
    int plugindir_fd = open(/* plugindir or */ PDIR, O_RDONLY);
 
782
    if(plugindir_fd == -1){
 
783
      if(errno != ENOENT){
 
784
        error(0, errno, "open(\"" PDIR "\")");
 
785
      }
 
786
    } else {
 
787
      ret = (int)TEMP_FAILURE_RETRY(fstat(plugindir_fd, &st));
 
788
      if(ret == -1){
 
789
        error(0, errno, "fstat");
 
790
      } else {
 
791
        if(S_ISDIR(st.st_mode) and st.st_uid == 0 and st.st_gid == 0){
 
792
          ret = fchown(plugindir_fd, uid, gid);
 
793
          if(ret == -1){
 
794
            error(0, errno, "fchown");
 
795
          }
 
796
        }
 
797
      }
 
798
      TEMP_FAILURE_RETRY(close(plugindir_fd));
 
799
    }
 
800
  }
 
801
  
 
802
  /* Lower permissions */
 
803
  ret = setgid(gid);
747
804
  if(ret == -1){
748
805
    error(0, errno, "setgid");
749
806
  }
754
811
  
755
812
  /* Open plugin directory with close_on_exec flag */
756
813
  {
757
 
    int dir_fd = -1;
758
 
    if(plugindir == NULL){
759
 
      dir_fd = open(PDIR, O_RDONLY |
760
 
#ifdef O_CLOEXEC
761
 
                    O_CLOEXEC
762
 
#else  /* not O_CLOEXEC */
763
 
                    0
764
 
#endif  /* not O_CLOEXEC */
765
 
                    );
766
 
    } else {
767
 
      dir_fd = open(plugindir, O_RDONLY |
768
 
#ifdef O_CLOEXEC
769
 
                    O_CLOEXEC
770
 
#else  /* not O_CLOEXEC */
771
 
                    0
772
 
#endif  /* not O_CLOEXEC */
773
 
                    );
774
 
    }
 
814
    dir_fd = open(plugindir != NULL ? plugindir : PDIR, O_RDONLY |
 
815
#ifdef O_CLOEXEC
 
816
                  O_CLOEXEC
 
817
#else  /* not O_CLOEXEC */
 
818
                  0
 
819
#endif  /* not O_CLOEXEC */
 
820
                  );
775
821
    if(dir_fd == -1){
776
822
      error(0, errno, "Could not open plugin dir");
777
823
      exitstatus = EX_UNAVAILABLE;
822
868
    {
823
869
      bool bad_name = false;
824
870
      
825
 
      const char const *bad_prefixes[] = { ".", "#", NULL };
 
871
      const char * const bad_prefixes[] = { ".", "#", NULL };
826
872
      
827
 
      const char const *bad_suffixes[] = { "~", "#", ".dpkg-new",
 
873
      const char * const bad_suffixes[] = { "~", "#", ".dpkg-new",
828
874
                                           ".dpkg-old",
829
875
                                           ".dpkg-bak",
830
876
                                           ".dpkg-divert", NULL };
831
 
      for(const char **pre = bad_prefixes; *pre != NULL; pre++){
 
877
#ifdef __GNUC__
 
878
#pragma GCC diagnostic push
 
879
#pragma GCC diagnostic ignored "-Wcast-qual"
 
880
#endif
 
881
      for(const char **pre = (const char **)bad_prefixes;
 
882
          *pre != NULL; pre++){
 
883
#ifdef __GNUC__
 
884
#pragma GCC diagnostic pop
 
885
#endif
832
886
        size_t pre_len = strlen(*pre);
833
887
        if((d_name_len >= pre_len)
834
888
           and strncmp((dirst->d_name), *pre, pre_len) == 0){
843
897
      if(bad_name){
844
898
        continue;
845
899
      }
846
 
      for(const char **suf = bad_suffixes; *suf != NULL; suf++){
 
900
#ifdef __GNUC__
 
901
#pragma GCC diagnostic push
 
902
#pragma GCC diagnostic ignored "-Wcast-qual"
 
903
#endif
 
904
      for(const char **suf = (const char **)bad_suffixes;
 
905
          *suf != NULL; suf++){
 
906
#ifdef __GNUC__
 
907
#pragma GCC diagnostic pop
 
908
#endif
847
909
        size_t suf_len = strlen(*suf);
848
910
        if((d_name_len >= suf_len)
849
911
           and (strcmp((dirst->d_name) + d_name_len-suf_len, *suf)
862
924
      }
863
925
    }
864
926
    
865
 
    char *filename;
866
 
    if(plugindir == NULL){
867
 
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, PDIR "/%s",
868
 
                                             dirst->d_name));
869
 
    } else {
870
 
      ret = (int)TEMP_FAILURE_RETRY(asprintf(&filename, "%s/%s",
871
 
                                             plugindir,
872
 
                                             dirst->d_name));
 
927
    int plugin_fd = openat(dir_fd, dirst->d_name, O_RDONLY |
 
928
#ifdef O_CLOEXEC
 
929
                            O_CLOEXEC
 
930
#else  /* not O_CLOEXEC */
 
931
                            0
 
932
#endif  /* not O_CLOEXEC */
 
933
                            );
 
934
    if(plugin_fd == -1){
 
935
      error(0, errno, "Could not open plugin");
 
936
      continue;
873
937
    }
 
938
#ifndef O_CLOEXEC
 
939
  /* Set the FD_CLOEXEC flag on the plugin FD */
 
940
    ret = set_cloexec_flag(plugin_fd);
874
941
    if(ret < 0){
875
 
      error(0, errno, "asprintf");
 
942
      error(0, errno, "set_cloexec_flag");
 
943
      TEMP_FAILURE_RETRY(close(plugin_fd));
876
944
      continue;
877
945
    }
878
 
    
879
 
    ret = (int)TEMP_FAILURE_RETRY(stat(filename, &st));
 
946
#endif  /* O_CLOEXEC */
 
947
    ret = (int)TEMP_FAILURE_RETRY(fstat(plugin_fd, &st));
880
948
    if(ret == -1){
881
949
      error(0, errno, "stat");
882
 
      free(filename);
 
950
      TEMP_FAILURE_RETRY(close(plugin_fd));
883
951
      continue;
884
952
    }
885
953
    
886
954
    /* Ignore non-executable files */
887
955
    if(not S_ISREG(st.st_mode)
888
 
       or (TEMP_FAILURE_RETRY(access(filename, X_OK)) != 0)){
 
956
       or (TEMP_FAILURE_RETRY(faccessat(dir_fd, dirst->d_name, X_OK,
 
957
                                        0)) != 0)){
889
958
      if(debug){
890
 
        fprintf(stderr, "Ignoring plugin dir entry \"%s\""
891
 
                " with bad type or mode\n", filename);
 
959
        fprintf(stderr, "Ignoring plugin dir entry \"%s/%s\""
 
960
                " with bad type or mode\n",
 
961
                plugindir != NULL ? plugindir : PDIR, dirst->d_name);
892
962
      }
893
 
      free(filename);
 
963
      TEMP_FAILURE_RETRY(close(plugin_fd));
894
964
      continue;
895
965
    }
896
966
    
897
967
    plugin *p = getplugin(dirst->d_name);
898
968
    if(p == NULL){
899
969
      error(0, errno, "getplugin");
900
 
      free(filename);
 
970
      TEMP_FAILURE_RETRY(close(plugin_fd));
901
971
      continue;
902
972
    }
903
973
    if(p->disabled){
905
975
        fprintf(stderr, "Ignoring disabled plugin \"%s\"\n",
906
976
                dirst->d_name);
907
977
      }
908
 
      free(filename);
 
978
      TEMP_FAILURE_RETRY(close(plugin_fd));
909
979
      continue;
910
980
    }
911
981
    {
925
995
        }
926
996
      }
927
997
    }
928
 
    /* If this plugin has any environment variables, we will call
929
 
       using execve and need to duplicate the environment from this
930
 
       process, too. */
 
998
    /* If this plugin has any environment variables, we need to
 
999
       duplicate the environment from this process, too. */
931
1000
    if(p->environ[0] != NULL){
932
1001
      for(char **e = environ; *e != NULL; e++){
933
1002
        if(not add_environment(p, *e, false)){
999
1068
           above and must now close it manually here. */
1000
1069
        closedir(dir);
1001
1070
      }
1002
 
      if(p->environ[0] == NULL){
1003
 
        if(execv(filename, p->argv) < 0){
1004
 
          error(0, errno, "execv for %s", filename);
1005
 
          _exit(EX_OSERR);
1006
 
        }
1007
 
      } else {
1008
 
        if(execve(filename, p->argv, p->environ) < 0){
1009
 
          error(0, errno, "execve for %s", filename);
1010
 
          _exit(EX_OSERR);
1011
 
        }
 
1071
      if(fexecve(plugin_fd, p->argv,
 
1072
                (p->environ[0] != NULL) ? p->environ : environ) < 0){
 
1073
        error(0, errno, "fexecve for %s/%s",
 
1074
              plugindir != NULL ? plugindir : PDIR, dirst->d_name);
 
1075
        _exit(EX_OSERR);
1012
1076
      }
1013
1077
      /* no return */
1014
1078
    }
1015
1079
    /* Parent process */
1016
1080
    TEMP_FAILURE_RETRY(close(pipefd[1])); /* Close unused write end of
1017
1081
                                             pipe */
1018
 
    free(filename);
 
1082
    TEMP_FAILURE_RETRY(close(plugin_fd));
1019
1083
    plugin *new_plugin = getplugin(dirst->d_name);
1020
1084
    if(new_plugin == NULL){
1021
1085
      error(0, errno, "getplugin");
1043
1107
      goto fallback;
1044
1108
    }
1045
1109
    
 
1110
#if defined (__GNUC__) and defined (__GLIBC__)
 
1111
#if not __GLIBC_PREREQ(2, 16)
 
1112
#pragma GCC diagnostic push
 
1113
#pragma GCC diagnostic ignored "-Wsign-conversion"
 
1114
#endif
 
1115
#endif
1046
1116
    FD_SET(new_plugin->fd, &rfds_all); /* Spurious warning from
1047
 
                                          -Wconversion */
 
1117
                                          -Wconversion in GNU libc
 
1118
                                          before 2.16 */
 
1119
#if defined (__GNUC__) and defined (__GLIBC__)
 
1120
#if not __GLIBC_PREREQ(2, 16)
 
1121
#pragma GCC diagnostic pop
 
1122
#endif
 
1123
#endif
1048
1124
    
1049
1125
    if(maxfd < new_plugin->fd){
1050
1126
      maxfd = new_plugin->fd;
1104
1180
          }
1105
1181
          
1106
1182
          /* Remove the plugin */
 
1183
#if defined (__GNUC__) and defined (__GLIBC__)
 
1184
#if not __GLIBC_PREREQ(2, 16)
 
1185
#pragma GCC diagnostic push
 
1186
#pragma GCC diagnostic ignored "-Wsign-conversion"
 
1187
#endif
 
1188
#endif
1107
1189
          FD_CLR(proc->fd, &rfds_all); /* Spurious warning from
1108
 
                                          -Wconversion */
 
1190
                                          -Wconversion in GNU libc
 
1191
                                          before 2.16 */
 
1192
#if defined (__GNUC__) and defined (__GLIBC__)
 
1193
#if not __GLIBC_PREREQ(2, 16)
 
1194
#pragma GCC diagnostic pop
 
1195
#endif
 
1196
#endif
1109
1197
          
1110
1198
          /* Block signal while modifying process_list */
1111
1199
          ret = (int)TEMP_FAILURE_RETRY(sigprocmask
1151
1239
      }
1152
1240
      
1153
1241
      /* This process has not completed.  Does it have any output? */
 
1242
#if defined (__GNUC__) and defined (__GLIBC__)
 
1243
#if not __GLIBC_PREREQ(2, 16)
 
1244
#pragma GCC diagnostic push
 
1245
#pragma GCC diagnostic ignored "-Wsign-conversion"
 
1246
#endif
 
1247
#endif
1154
1248
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){ /* Spurious
1155
1249
                                                         warning from
1156
 
                                                         -Wconversion */
 
1250
                                                         -Wconversion
 
1251
                                                         in GNU libc
 
1252
                                                         before
 
1253
                                                         2.16 */
 
1254
#if defined (__GNUC__) and defined (__GLIBC__)
 
1255
#if not __GLIBC_PREREQ(2, 16)
 
1256
#pragma GCC diagnostic pop
 
1257
#endif
 
1258
#endif
1157
1259
        /* This process had nothing to say at this time */
1158
1260
        proc = proc->next;
1159
1261
        continue;
1160
1262
      }
1161
1263
      /* Before reading, make the process' data buffer large enough */
1162
1264
      if(proc->buffer_length + BUFFER_SIZE > proc->buffer_size){
1163
 
        proc->buffer = realloc(proc->buffer, proc->buffer_size
1164
 
                               + (size_t) BUFFER_SIZE);
1165
 
        if(proc->buffer == NULL){
 
1265
        char *new_buffer = realloc(proc->buffer, proc->buffer_size
 
1266
                                   + (size_t) BUFFER_SIZE);
 
1267
        if(new_buffer == NULL){
1166
1268
          error(0, errno, "malloc");
1167
1269
          exitstatus = EX_OSERR;
1168
1270
          goto fallback;
1169
1271
        }
 
1272
        proc->buffer = new_buffer;
1170
1273
        proc->buffer_size += BUFFER_SIZE;
1171
1274
      }
1172
1275
      /* Read from the process */