/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:29:00 UTC
  • Revision ID: teddy@recompile.se-20140614232900-vhcywskev4u8rz2d
mandos-client: Fix some bugs on error conditions.

* plugins.d/mandos-client.c (run_network_hooks): Init "dirent" to NULL
                                                 and, later, always
                                                 free() it unless
                                                 scandirat() or
                                                 scandir() failed.
  (main): Fix free() of uninitalized memory in case scandirat() or
          scandir() of "/sys/class/net" failed.  Also, when cleaning
          up, even if GPGME temp directory is empty, do
          free(direntries) and remove the directory.

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 {
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;
2608
2611
      int numentries = scandir(tempdir, &direntries, notdotentries,
2609
2612
                               alphasort);
2610
2613
#endif  /* not __GLIBC__ */
2611
 
      if(numentries > 0){
 
2614
      if(numentries >= 0){
2612
2615
        for(int i = 0; i < numentries; i++){
2613
2616
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2614
2617
          if(ret == -1){