/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-28 21:45:13 UTC
  • Revision ID: teddy@recompile.se-20190228214513-58glsld2x80fq684
mandos-ctl: Refactor and add more tests

* mandos-ctl (string_to_delta): Factor out old-style parsing to its
                                own function.  Log a warning if
                                old-style parsing is invoked.
  (parse_pre_1_6_1_interval): New; factored out of string_to_delta.
                              Also added more tests.

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);
597
585
      if(arg[0] == '\0'){
598
586
        break;
599
587
      }
600
 
#if __GNUC__ >= 7
601
 
      __attribute__((fallthrough));
602
 
#else
603
 
          /* FALLTHROUGH */
604
 
#endif
 
588
      /* FALLTHROUGH */
605
589
    default:
606
590
      return ARGP_ERR_UNKNOWN;
607
591
    }
719
703
        
720
704
        custom_argc += 1;
721
705
        {
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
 
706
          char **new_argv = realloc(custom_argv, sizeof(char *)
 
707
                                    * ((size_t)custom_argc + 1));
735
708
          if(new_argv == NULL){
736
 
            error(0, errno, "reallocarray");
 
709
            error(0, errno, "realloc");
737
710
            exitstatus = EX_OSERR;
738
711
            free(new_arg);
739
712
            free(org_line);