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

  • Committer: Teddy Hogeborn
  • Date: 2014-06-14 23:43:07 UTC
  • Revision ID: teddy@recompile.se-20140614234307-i0mh9r2n4orkqtki
plugin-runner: Release memory and close FD's correctly in all cases.

* plugins.d/mandos-client.c (main): Init "direntries" to NULL.  Close
                                    "dir_fd" at fallback label.  Do
                                    not free "direntries" if
                                    scandirat() or scandir() failed.
                                    Do free(direntries) at fallback
                                    label.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1510
1510
__attribute__((nonnull))
1511
1511
void run_network_hooks(const char *mode, const char *interface,
1512
1512
                       const float delay){
1513
 
  struct dirent **direntries;
 
1513
  struct dirent **direntries = NULL;
1514
1514
  if(hookdir_fd == -1){
1515
1515
    hookdir_fd = open(hookdir, O_RDONLY);
1516
1516
    if(hookdir_fd == -1){
1670
1670
                   direntry->d_name);
1671
1671
    }
1672
1672
  }
 
1673
  free(direntries);
1673
1674
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
1674
1675
    perror_plus("close");
1675
1676
  } else {
2253
2254
  
2254
2255
  /* If no interfaces were specified, make a list */
2255
2256
  if(mc.interfaces == NULL){
2256
 
    struct dirent **direntries;
 
2257
    struct dirent **direntries = NULL;
2257
2258
    /* Look for any good interfaces */
2258
2259
    ret = scandir(sys_class_net, &direntries, good_interface,
2259
2260
                  alphasort);
2274
2275
      }
2275
2276
      free(direntries);
2276
2277
    } else {
2277
 
      free(direntries);
 
2278
      if(ret == 0){
 
2279
        free(direntries);
 
2280
      }
2278
2281
      fprintf_plus(stderr, "Could not find a network interface\n");
2279
2282
      exitcode = EXIT_FAILURE;
2280
2283
      goto end;
2591
2594
  /* Removes the GPGME temp directory and all files inside */
2592
2595
  if(tempdir != NULL){
2593
2596
    struct dirent **direntries = NULL;
2594
 
    int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY));
 
2597
    int tempdir_fd = (int)TEMP_FAILURE_RETRY(open(tempdir, O_RDONLY |
 
2598
                                                  O_NOFOLLOW));
2595
2599
    if(tempdir_fd == -1){
2596
2600
      perror_plus("open");
2597
2601
    } else {
2607
2611
      int numentries = scandir(tempdir, &direntries, notdotentries,
2608
2612
                               alphasort);
2609
2613
#endif  /* not __GLIBC__ */
2610
 
      if(numentries > 0){
 
2614
      if(numentries >= 0){
2611
2615
        for(int i = 0; i < numentries; i++){
2612
2616
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2613
2617
          if(ret == -1){