Forráskód Böngészése

Merge branch 'maint'

* maint:
  Fix potential NULL dereference in laston_gotshare
  Fix potential fd leak in transer.mod dcc sending
  Fix leaked fd in disconnected compress.mod
Bryan Drewery 12 éve
szülő
commit
9a64bc4f6e
3 módosított fájl, 19 hozzáadás és 11 törlés
  1. 16 8
      src/mod/compress.mod/compress.c
  2. 2 2
      src/mod/transfer.mod/transfer.c
  3. 1 1
      src/userent.c

+ 16 - 8
src/mod/compress.mod/compress.c

@@ -112,8 +112,10 @@ static int is_compressedfile(char *filename)
   if (!fin)
     return COMPF_FAILED;
   len2 = fread(buf2, 1, sizeof(buf2), fin);
-  if (ferror(fin))
+  if (ferror(fin)) {
+    fclose(fin);
     return COMPF_FAILED;
+  }
   fclose(fin);
 
   /* Compare what we found.
@@ -239,6 +241,7 @@ static int compress_to_file(char *f_src, char *f_target, int mode_num)
   char buf[BUFLEN] = "", mode[5] = "";
   FILE *fin = NULL, *fout = NULL;
   size_t len;
+  int ret = COMPF_ERROR;
 
   adjust_mode_num(&mode_num);
   simple_snprintf(mode, sizeof mode, "wb%d", mode_num);
@@ -246,20 +249,20 @@ static int compress_to_file(char *f_src, char *f_target, int mode_num)
   if (!is_file(f_src)) {
     putlog(LOG_MISC, "*", "Failed to compress file `%s': not a file.",
 	   f_src);
-    return COMPF_ERROR;
+    goto err;
   }
   fin = fopen(f_src, "rb");
   if (!fin) {
     putlog(LOG_MISC, "*", "Failed to compress file `%s': open failed: %s.",
 	   f_src, strerror(errno));
-    return COMPF_ERROR;
+    goto err;
   }
 
   fout = gzopen(f_target, mode);
   if (!fout) {
     putlog(LOG_MISC, "*", "Failed to compress file `%s': gzopen failed.",
 	   f_src);
-    return COMPF_ERROR;
+    goto err;
   }
 
 #ifdef HAVE_MMAP
@@ -280,24 +283,29 @@ static int compress_to_file(char *f_src, char *f_target, int mode_num)
     if (ferror(fin)) {
       putlog(LOG_MISC, "*", "Failed to compress file `%s': fread failed: %s",
 	     f_src, strerror(errno));
-      return COMPF_ERROR;
+      goto err;
     }
     if (!len)
       break;
     if (gzwrite(fout, buf, (unsigned int) len) != len) {
       putlog(LOG_MISC, "*", "Failed to compress file `%s': gzwrite failed.",
 	     f_src);
-      return COMPF_ERROR;
+      goto err;
     }
   }
-  fclose(fin);
+
   if (gzclose(fout) != Z_OK) {
     putlog(LOG_MISC, "*", "Failed to compress file `%s': gzclose failed.",
 	   f_src);
+    goto err;
     return COMPF_ERROR;
   }
   compressed_files++;
-  return COMPF_SUCCESS;
+  ret = COMPF_SUCCESS;
+err:
+  if (fin)
+    fclose(fin);
+  return ret;
 }
 
 /* Compresses a file `filename' and saves it as `filename'.

+ 2 - 2
src/mod/transfer.mod/transfer.c

@@ -851,11 +851,11 @@ static int raw_dcc_resend_send(char *filename, char *nick, char *from, int resen
   if (zz == (-1))
     return DCCSEND_NOSOCK;
   
+  if ((i = new_dcc(&DCC_GET_PENDING, sizeof(struct xfer_info))) == -1)
+     return DCCSEND_FULL;
   f = fopen(filename, "rb");
   if (!f)
     return DCCSEND_BADFN;
-  if ((i = new_dcc(&DCC_GET_PENDING, sizeof(struct xfer_info))) == -1)
-     return DCCSEND_FULL;
   dcc[i].sock = zz;
   dcc[i].addr = (in_addr_t) (-559026163);
   dcc[i].port = port;

+ 1 - 1
src/userent.c

@@ -742,7 +742,7 @@ static bool laston_gotshare(struct userrec *u, struct user_entry *e, char *par,
 
   if (par[0])
     where = newsplit(&par);
-  if (!strcmp(where, "-"))
+  if (where && !strcmp(where, "-"))
     where = NULL;
   if (par[0])
     timeval = atol(newsplit(&par));