/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-13 22:13:56 UTC
  • Revision ID: teddy@recompile.se-20140613221356-b9c36ctxmw4pelja
Fix free() of possibly uninitialized pointer in mandos-client.

* plugins.d/mandos-client (main): Initialize "direntries" to NULL so
                                  it can be free()'d even if scandir()
                                  fails.

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 = NULL;
 
1513
  struct dirent **direntries;
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);
1674
1673
  if((int)TEMP_FAILURE_RETRY(close(hookdir_fd)) == -1){
1675
1674
    perror_plus("close");
1676
1675
  } else {
2275
2274
      }
2276
2275
      free(direntries);
2277
2276
    } else {
2278
 
      if(ret == 0){
2279
 
        free(direntries);
2280
 
      }
 
2277
      free(direntries);
2281
2278
      fprintf_plus(stderr, "Could not find a network interface\n");
2282
2279
      exitcode = EXIT_FAILURE;
2283
2280
      goto end;
2611
2608
      int numentries = scandir(tempdir, &direntries, notdotentries,
2612
2609
                               alphasort);
2613
2610
#endif  /* not __GLIBC__ */
2614
 
      if(numentries >= 0){
 
2611
      if(numentries > 0){
2615
2612
        for(int i = 0; i < numentries; i++){
2616
2613
          ret = unlinkat(tempdir_fd, direntries[i]->d_name, 0);
2617
2614
          if(ret == -1){