/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 plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2015-07-20 00:59:17 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 325.
  • Revision ID: teddy@recompile.se-20150720005917-ud7fxa6wcv9y4ta6
mandos-client: Bug fix: don't crash if --dh-params was not used.

* plugins.d/mandos-client.c (main): Bug fix: Check if dh_params_file
                                    is NULL before using it in the
                                    workaround for Debian bug #633582.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include <stdlib.h>             /* free(), EXIT_SUCCESS, srand(),
47
47
                                   strtof(), abort() */
48
48
#include <stdbool.h>            /* bool, false, true */
49
 
#include <string.h>             /* memset(), strcmp(), strlen(),
50
 
                                   strerror(), asprintf(), strcpy() */
 
49
#include <string.h>             /* strcmp(), strlen(), strerror(),
 
50
                                   asprintf(), strcpy() */
51
51
#include <sys/ioctl.h>          /* ioctl */
52
52
#include <sys/types.h>          /* socket(), inet_pton(), sockaddr,
53
53
                                   sockaddr_in6, PF_INET6,
305
305
      return false;
306
306
    }
307
307
    
308
 
    ret = (int)TEMP_FAILURE_RETRY(close(fd));
 
308
    ret = close(fd);
309
309
    if(ret == -1){
310
310
      perror_plus("close");
311
311
    }
931
931
      perror_plus("dup2(devnull, STDIN_FILENO)");
932
932
      _exit(EX_OSERR);
933
933
    }
934
 
    ret = (int)TEMP_FAILURE_RETRY(close(devnull));
 
934
    ret = close(devnull);
935
935
    if(ret == -1){
936
936
      perror_plus("close");
937
937
      _exit(EX_OSERR);
954
954
                                                   helper, O_RDONLY));
955
955
    if(helper_fd == -1){
956
956
      perror_plus("openat");
 
957
      close(helperdir_fd);
957
958
      _exit(EX_UNAVAILABLE);
958
959
    }
959
 
    TEMP_FAILURE_RETRY(close(helperdir_fd));
 
960
    close(helperdir_fd);
960
961
#ifdef __GNUC__
961
962
#pragma GCC diagnostic push
962
963
#pragma GCC diagnostic ignored "-Wcast-qual"
1130
1131
    goto mandos_end;
1131
1132
  }
1132
1133
  
1133
 
  memset(&to, 0, sizeof(to));
1134
1134
  if(af == AF_INET6){
1135
 
    ((struct sockaddr_in6 *)&to)->sin6_family = (sa_family_t)af;
1136
 
    ret = inet_pton(af, ip, &((struct sockaddr_in6 *)&to)->sin6_addr);
 
1135
    struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&to;
 
1136
    *to6 = (struct sockaddr_in6){ .sin6_family = (sa_family_t)af };
 
1137
    ret = inet_pton(af, ip, &to6->sin6_addr);
1137
1138
  } else {                      /* IPv4 */
1138
 
    ((struct sockaddr_in *)&to)->sin_family = (sa_family_t)af;
1139
 
    ret = inet_pton(af, ip, &((struct sockaddr_in *)&to)->sin_addr);
 
1139
    struct sockaddr_in *to4 = (struct sockaddr_in *)&to;
 
1140
    *to4 = (struct sockaddr_in){ .sin_family = (sa_family_t)af };
 
1141
    ret = inet_pton(af, ip, &to4->sin_addr);
1140
1142
  }
1141
1143
  if(ret < 0 ){
1142
1144
    int e = errno;
1465
1467
    free(decrypted_buffer);
1466
1468
    free(buffer);
1467
1469
    if(tcp_sd >= 0){
1468
 
      ret = (int)TEMP_FAILURE_RETRY(close(tcp_sd));
 
1470
      ret = close(tcp_sd);
1469
1471
    }
1470
1472
    if(ret == -1){
1471
1473
      if(e == 0){
2010
2012
        perror_plus("openat");
2011
2013
        _exit(EXIT_FAILURE);
2012
2014
      }
2013
 
      if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
2015
      if(close(hookdir_fd) == -1){
2014
2016
        perror_plus("close");
2015
2017
        _exit(EXIT_FAILURE);
2016
2018
      }
2019
2021
        perror_plus("dup2(devnull, STDIN_FILENO)");
2020
2022
        _exit(EX_OSERR);
2021
2023
      }
2022
 
      ret = (int)TEMP_FAILURE_RETRY(close(devnull));
 
2024
      ret = close(devnull);
2023
2025
      if(ret == -1){
2024
2026
        perror_plus("close");
2025
2027
        _exit(EX_OSERR);
2074
2076
    free(direntry);
2075
2077
  }
2076
2078
  free(direntries);
2077
 
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
 
2079
  if(close(hookdir_fd) == -1){
2078
2080
    perror_plus("close");
2079
2081
  } else {
2080
2082
    hookdir_fd = -1;
2120
2122
    }
2121
2123
    
2122
2124
    if(quit_now){
2123
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2125
      ret = close(sd);
2124
2126
      if(ret == -1){
2125
2127
        perror_plus("close");
2126
2128
      }
2176
2178
    }
2177
2179
    
2178
2180
    /* Close the socket */
2179
 
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2181
    ret = close(sd);
2180
2182
    if(ret == -1){
2181
2183
      perror_plus("close");
2182
2184
    }
2264
2266
    }
2265
2267
    
2266
2268
    /* Close the socket */
2267
 
    int ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
2269
    int ret = close(sd);
2268
2270
    if(ret == -1){
2269
2271
      perror_plus("close");
2270
2272
    }
2521
2523
              }
2522
2524
            }
2523
2525
          }
2524
 
          TEMP_FAILURE_RETRY(close(seckey_fd));
 
2526
          close(seckey_fd);
2525
2527
        }
2526
2528
      }
2527
2529
      
2542
2544
              }
2543
2545
            }
2544
2546
          }
2545
 
          TEMP_FAILURE_RETRY(close(pubkey_fd));
 
2547
          close(pubkey_fd);
2546
2548
        }
2547
2549
      }
2548
2550
      
2549
 
      if(strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
 
2551
      if(dh_params_file != NULL
 
2552
         and strcmp(dh_params_file, PATHDIR "/dhparams.pem" ) == 0){
2550
2553
        int dhparams_fd = open(dh_params_file, O_RDONLY);
2551
2554
        if(dhparams_fd == -1){
2552
2555
          perror_plus("open");
2563
2566
              }
2564
2567
            }
2565
2568
          }
2566
 
          TEMP_FAILURE_RETRY(close(dhparams_fd));
 
2569
          close(dhparams_fd);
2567
2570
        }
2568
2571
      }
2569
2572
      
2746
2749
      errno = bring_up_interface(interface, delay);
2747
2750
      if(not interface_was_up){
2748
2751
        if(errno != 0){
2749
 
          perror_plus("Failed to bring up interface");
 
2752
          fprintf_plus(stderr, "Failed to bring up interface \"%s\":"
 
2753
                       " %s\n", interface, strerror(errno));
2750
2754
        } else {
2751
2755
          errno = argz_add(&interfaces_to_take_down,
2752
2756
                           &interfaces_to_take_down_size,
3081
3085
          perror_plus("rmdir");
3082
3086
        }
3083
3087
      }
3084
 
      TEMP_FAILURE_RETRY(close(tempdir_fd));
 
3088
      close(tempdir_fd);
3085
3089
    }
3086
3090
  }
3087
3091