Преглед на файлове

* Fix multiple warnings about unused results (warn_unused_result)

Bryan Drewery преди 17 години
родител
ревизия
b48d1c8211
променени са 8 файла, в които са добавени 52 реда и са изтрити 23 реда
  1. 2 7
      src/bg.c
  2. 4 1
      src/conf.c
  3. 6 2
      src/dccutil.c
  4. 2 1
      src/main.c
  5. 1 2
      src/misc.c
  6. 17 4
      src/mod/transfer.mod/transfer.c
  7. 10 4
      src/shell.c
  8. 10 2
      src/users.c

+ 2 - 7
src/bg.c

@@ -62,7 +62,7 @@ int close_tty()
   return 0;
 }
 
-static int my_daemon(int nochdir, int noclose)
+static int my_daemon()
 {
   switch (fork()) {
     case -1:
@@ -76,11 +76,6 @@ static int my_daemon(int nochdir, int noclose)
   if (setsid() == -1)
     return (-1);
 
-  if (!nochdir)
-    (void) chdir("/");
-
-  if (!noclose)
-    close_tty();
   return (0);
 }
 
@@ -88,7 +83,7 @@ static int my_daemon(int nochdir, int noclose)
 pid_t
 do_fork()
 {
-  if (my_daemon(1, 1))
+  if (my_daemon())
     fatal(strerror(errno), 0);
 
   pid_t pid = getpid();

+ 4 - 1
src/conf.c

@@ -433,7 +433,10 @@ checkpid(const char *nick, conf_bot *bot)
   if ((f = fopen(buf, "r"))) {
     char *bufp = NULL, *pids = NULL;
 
-    fgets(buf, sizeof(buf), f);
+    if (!fgets(buf, sizeof(buf), f)) {
+      fclose(f);
+      return 0;
+    }
     fclose(f);
     remove_crlf(buf);
 

+ 6 - 2
src/dccutil.c

@@ -1031,12 +1031,16 @@ identd_open(const char *sourceIp, const char *destIp)
         free(p);
       }
 
-      ftruncate(fileno(f), 0);
-      fwrite(outbuf, 1, strlen(outbuf), f);
+      if (ftruncate(fileno(f), 0))
+        goto failure;
+
+      if (!fwrite(outbuf, 1, strlen(outbuf), f))
+        goto failure;
 
       //And make a record in the oidentd.conf to spoof the ident request from this port->dest-prot
       fprintf(f, "to %s from %s { reply \"%s\" }\n", destIp, sourceIp, origbotname);
       
+failure:
       fflush(f);
       flock(fileno(f), LOCK_UN);
       fclose(f);

+ 2 - 1
src/main.c

@@ -748,7 +748,8 @@ printf("out: %s\n", out);
   }
 
   binname = getfullbinname(argv[0]);
-  chdir(dirname(binname));
+  if (chdir(dirname(binname)))
+    werr(ERR_BINSTAT);
 
   /* Find a temporary tempdir until we load binary data */
   /* setup initial tempdir as /tmp until we read in tmpdir from conf */

+ 1 - 2
src/misc.c

@@ -1296,8 +1296,7 @@ char *step_thru_file(FILE *fd)
   size_t ret_siz = 0;
 
   while (!feof(fd)) {
-    fgets(tempBuf, sizeof(tempBuf), fd);
-    if (!feof(fd)) {
+    if (fgets(tempBuf, sizeof(tempBuf), fd) && !feof(fd)) {
       if (retStr == NULL) {
         ret_siz = strlen(tempBuf) + 2;
         retStr = (char *) my_calloc(1, ret_siz);

+ 17 - 4
src/mod/transfer.mod/transfer.c

@@ -95,9 +95,10 @@ static unsigned long pump_file_to_sock(FILE *file, long sock,
   if (bf) {
     do {
       actual_size = pending_data >= buf_len ? buf_len : pending_data;
-      fread(bf, actual_size, 1, file);
-      tputs(sock, bf, actual_size);
-      pending_data -= actual_size;
+      if (fread(bf, actual_size, 1, file)) {
+        tputs(sock, bf, actual_size);
+        pending_data -= actual_size;
+      }
     } while (!sock_has_data(SOCK_DATA_OUTGOING, sock) && pending_data != 0);
     free(bf);
   }
@@ -462,7 +463,19 @@ void dcc_send(int idx, char *buf, int len)
   size_t siz = 0;
   unsigned long sent;
 
-  fwrite(buf, len, 1, dcc[idx].u.xfer->f);
+  if (!fwrite(buf, len, 1, dcc[idx].u.xfer->f)) {
+    putlog(LOG_FILES, "*", "Problem writing file");
+    fclose(dcc[idx].u.xfer->f);
+    siz = strlen(tempdir) + strlen(dcc[idx].u.xfer->filename) + 1;
+    b = (char *) my_calloc(1, siz);
+    strlcpy(b, tempdir, siz);
+    strlcat(b, dcc[idx].u.xfer->filename, siz);
+    unlink(b);
+    free(b);
+    killsock(dcc[idx].sock);
+    lostdcc(idx);
+    return;
+  }
 
   fflush(dcc[idx].u.xfer->f);
   fsync(fileno(dcc[idx].u.xfer->f));

+ 10 - 4
src/shell.c

@@ -726,7 +726,7 @@ void baduname(char *confhas, char *myuname) {
 
 char *homedir(bool useconf)
 {
-  static char homedir_buf[DIRMAX] = "";
+  static char homedir_buf[PATH_MAX] = "";
 
   if (!homedir_buf[0]) {
     char tmp[DIRMAX] = "";
@@ -747,8 +747,10 @@ char *homedir(bool useconf)
 #endif /* CYGWIN_HACKS */
     }
     ContextNote(STR("realpath()"));
-    if (tmp[0])
+    if (tmp[0]) {
       realpath(tmp, homedir_buf); /* this will convert lame home dirs of /home/blah->/usr/home/blah */
+      homedir_buf[DIRMAX] = 0;
+    }
     ContextNote(STR("realpath(): Success"));
   }
   return homedir_buf[0] ? homedir_buf : NULL;
@@ -858,12 +860,13 @@ char *move_bin(const char *ipath, const char *file, bool run)
 
   /* move the binary to the correct place */
   static char newbin[DIRMAX] = "";
-  char real[DIRMAX] = "";
+  char real[PATH_MAX] = "";
 
   simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);
 
   ContextNote(STR("realpath()"));
   realpath(binname, real);            /* get the realpath of binname */
+  real[DIRMAX] = 0;
   ContextNote(STR("realpath(): Success"));
   /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
   sdprintf(STR("binname: %s"), binname);
@@ -894,7 +897,10 @@ char *move_bin(const char *ipath, const char *file, bool run)
       if (run) {
         simple_snprintf(newbin, sizeof newbin, "%s%s%s", 
                         path, path[strlen(path) - 1] == '/' ? "" : "/", shell_escape(file));
-        system(newbin);
+        if (system(newbin) == -1) {
+          printf("Unable to automatically start new binary.\n");
+          exit(1);
+        }
         sdprintf(STR("exiting to let new binary run..."));
         exit(0);
       }

+ 10 - 2
src/users.c

@@ -610,7 +610,11 @@ int readuserfile(const char *file, struct userrec **ret)
     return 0;
   noshare = 1;
   /* read opening comment */
-  fgets(cbuf, 180, f);
+  if (!fgets(cbuf, 180, f)) {
+    fclose(f);
+    putlog(LOG_MISC, "*", "!*! Failed to read userfile.");
+    return 0;
+  }
   remove_crlf(cbuf);
   temps = (char *) decrypt_string(salt1, cbuf);
   simple_snprintf(s, 180, "%s", temps);
@@ -625,7 +629,11 @@ int readuserfile(const char *file, struct userrec **ret)
   }
   while (!feof(f)) {
     s = buf;
-    fgets(cbuf, 1024, f);
+    if (!fgets(cbuf, 1024, f)) {
+      fclose(f);
+      putlog(LOG_MISC, "*", "!*! Failed to parse userfile.");
+      return 0;
+    }
     remove_crlf(cbuf);
     temps = (char *) decrypt_string(salt1, cbuf);
     simple_snprintf(s, 1024, "%s", temps);