/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-10 10:39:26 UTC
  • Revision ID: teddy@recompile.se-20190210103926-gdkbgjcf81yvhfjo
Bug fix: Ignore some failures to remove files.

* debian/mandos-client.postinst (create_keys): Ignore failure to
                                               remove bad keys.
* mandos-keygen (keygen): Ignore failure to remove files in some
                          cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);