/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 plugin-runner.c

  • Committer: Teddy Hogeborn
  • Date: 2019-02-09 23:34:15 UTC
  • Revision ID: teddy@recompile.se-20190209233415-m1ntebuepwna1xg1
Doc fix: Change some "/etc/mandos" to "/etc/keys/mandos"

* clients.conf: Change "/etc/mandos" to "/etc/keys/mandos" where
                appropriate
* mandos-keygen.xml: - '' -

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-2020 Teddy Hogeborn
6
 
 * Copyright © 2008-2020 Björn Påhlsson
 
5
 * Copyright © 2008-2018 Teddy Hogeborn
 
6
 * Copyright © 2008-2018 Björn Påhlsson
7
7
 * 
8
8
 * This file is part of Mandos.
9
9
 * 
26
26
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), getline(),
27
27
                                   O_CLOEXEC, pipe2() */
28
28
#include <stddef.h>             /* size_t, NULL */
29
 
#include <stdlib.h>             /* malloc(), reallocarray(), realloc(),
30
 
                                   EXIT_SUCCESS, exit() */
 
29
#include <stdlib.h>             /* malloc(), exit(), EXIT_SUCCESS,
 
30
                                   realloc() */
31
31
#include <stdbool.h>            /* bool, true, false */
32
32
#include <stdio.h>              /* fileno(), fprintf(),
33
33
                                   stderr, STDOUT_FILENO, fclose() */
179
179
  /* Resize the pointed-to array to hold one more pointer */
180
180
  char **new_array = NULL;
181
181
  do {
182
 
#if defined(__GLIBC_PREREQ) and __GLIBC_PREREQ(2, 26)
183
 
    new_array = reallocarray(*array, (size_t)((*len) + 2),
184
 
                             sizeof(char *));
185
 
#else
186
 
    if(((size_t)((*len) + 2)) > (SIZE_MAX / sizeof(char *))){
187
 
      /* overflow */
188
 
      new_array = NULL;
189
 
      errno = ENOMEM;
190
 
    } else {
191
 
      new_array = realloc(*array, (size_t)((*len) + 2)
192
 
                          * sizeof(char *));
193
 
    }
194
 
#endif
 
182
    new_array = realloc(*array, sizeof(char *)
 
183
                        * (size_t) ((*len) + 2));
195
184
  } while(new_array == NULL and errno == EINTR);
196
185
  /* Malloc check */
197
186
  if(new_array == NULL){
324
313
__attribute__((nonnull))
325
314
static void free_plugin(plugin *plugin_node){
326
315
  
327
 
  for(char **arg = (plugin_node->argv)+1; *arg != NULL; arg++){
 
316
  for(char **arg = plugin_node->argv; *arg != NULL; arg++){
328
317
    free(*arg);
329
318
  }
330
 
  free(plugin_node->name);
331
319
  free(plugin_node->argv);
332
320
  for(char **env = plugin_node->environ; *env != NULL; env++){
333
321
    free(*env);
576
564
    case '?':                   /* --help */
577
565
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
578
566
      argp_state_help(state, state->out_stream, ARGP_HELP_STD_HELP);
579
 
      __builtin_unreachable();
580
567
    case -3:                    /* --usage */
581
568
      state->flags &= ~(unsigned int)ARGP_NO_EXIT; /* force exit */
582
569
      argp_state_help(state, state->out_stream,
583
570
                      ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
584
 
      __builtin_unreachable();
585
571
    case 'V':                   /* --version */
586
572
      fprintf(state->out_stream, "%s\n", argp_program_version);
587
573
      exit(EXIT_SUCCESS);
597
583
      if(arg[0] == '\0'){
598
584
        break;
599
585
      }
600
 
#if __GNUC__ >= 7
601
 
      __attribute__((fallthrough));
602
 
#else
603
 
          /* FALLTHROUGH */
604
 
#endif
 
586
      /* FALLTHROUGH */
605
587
    default:
606
588
      return ARGP_ERR_UNKNOWN;
607
589
    }
719
701
        
720
702
        custom_argc += 1;
721
703
        {
722
 
#if defined(__GLIBC_PREREQ) and __GLIBC_PREREQ(2, 26)
723
 
          char **new_argv = reallocarray(custom_argv, (size_t)custom_argc + 1,
724
 
                                         sizeof(char *));
725
 
#else
726
 
          char **new_argv = NULL;
727
 
          if(((size_t)custom_argc + 1) > (SIZE_MAX / sizeof(char *))){
728
 
            /* overflow */
729
 
            errno = ENOMEM;
730
 
          } else {
731
 
            new_argv = realloc(custom_argv, ((size_t)custom_argc + 1)
732
 
                               * sizeof(char *));
733
 
          }
734
 
#endif
 
704
          char **new_argv = realloc(custom_argv, sizeof(char *)
 
705
                                    * ((size_t)custom_argc + 1));
735
706
          if(new_argv == NULL){
736
 
            error(0, errno, "reallocarray");
 
707
            error(0, errno, "realloc");
737
708
            exitstatus = EX_OSERR;
738
709
            free(new_arg);
739
710
            free(org_line);