dpid patches

123 <[email protected]>
Newsgroups gmane.comp.web.dillo.devel
Message-ID <[email protected]>
One patch for using random instead of rand. [1]

Reordered headers and removed old comments (what is ckt_write?). umask
is actually in sys/stat.h and not in unistd.h

Also removed expired TODO item about dpi_service.[c|h].

[1] https://www.securecoding.cert.org/confluence/display/seccode/MSC30-C.+Do+not+use+the+rand%28%29+function+for+generating+pseudorandom+numbers

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
random.diff (text/plain, 1.3 KB)
diff -r 54817f9aa3e4 dpid/misc_new.c
--- a/dpid/misc_new.c	Sat May 26 22:35:19 2012 +0400
+++ b/dpid/misc_new.c	Sat May 26 23:01:10 2012 +0400
@@ -163,7 +163,7 @@
 {
    char *tmp = template + strlen(template) - 6;
    int i;
-   uint_t random;
+   uint_t rnd;
    struct stat stat_buf;
 
    if (tmp < template)
@@ -174,12 +174,12 @@
          errno = EINVAL;
          return 0;
       }
-   srand((uint_t)(time(0) ^ getpid()));
+   srandom((uint_t)(time(0) ^ getpid()));
 
    for (;;) {
-      random = (unsigned) rand();
+      rnd = (unsigned) random();
       for (i = 0; i < 6; ++i) {
-         int hexdigit = (random >> (i * 5)) & 0x1f;
+         int hexdigit = (rnd >> (i * 5)) & 0x1f;
 
          tmp[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
       }
@@ -196,13 +196,13 @@
 char *a_Misc_mksecret(int nchar)
 {
    int i;
-   uint_t random;
+   uint_t rnd;
    char *secret = dNew(char, nchar + 1);
 
-   srand((uint_t)(time(0) ^ getpid()));
-   random = (unsigned) rand();
+   srandom((uint_t)(time(0) ^ getpid()));
+   rnd = (unsigned) random();
    for (i = 0; i < nchar; ++i) {
-      int hexdigit = (random >> (i * 5)) & 0x0f;
+      int hexdigit = (rnd >> (i * 5)) & 0x0f;
 
       secret[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
    }
todo.diff (text/plain, 549 B)
diff -r e77b384a9d4d dpid/TODO
--- a/dpid/TODO	Sat May 26 13:58:42 2012 +0200
+++ b/dpid/TODO	Sat May 26 23:00:33 2012 +0400
@@ -1,13 +1,5 @@
 Todo List
 
- File dpi_service.c
- This module should be removed because its original functions
- have been removed or modified. Put these functions in dpid.c
-
- File dpi_service.h
- This module should be removed because its original functions
- have been removed or modified. Put these functions in dpid.c
-
  Add other file types, but first we need to add files associated
  with a dpi to the design.
header.diff (text/plain, 3.8 KB)
diff -r d4b18bae3331 dpid/dpi.c
--- a/dpid/dpi.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/dpi.c	Sat May 26 23:00:53 2012 +0400
@@ -22,9 +22,10 @@
  */
 
 #include <errno.h>
-#include <stdlib.h>  /* for exit */
+#include <stdlib.h>
+
+#include "dpi.h"
 #include "dpid_common.h"
-#include "dpi.h"
 #include "misc_new.h"
 
 /*! \Return
diff -r d4b18bae3331 dpid/dpi_socket_dir.c
--- a/dpid/dpi_socket_dir.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/dpi_socket_dir.c	Sat May 26 23:00:53 2012 +0400
@@ -21,10 +21,11 @@
 
 #include <errno.h>
 #include <stdlib.h>
+
+#include "dpi.h"
+#include "dpi_socket_dir.h"
 #include "dpid_common.h"
-#include "dpi.h"
 #include "misc_new.h"
-#include "dpi_socket_dir.h" /* for function prototypes */
 
 /*! Save socket directory name in ~/.dillo/dpi_socket_dir
  * \Return
diff -r d4b18bae3331 dpid/dpid.c
--- a/dpid/dpid.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/dpid.c	Sat May 26 23:00:53 2012 +0400
@@ -18,24 +18,23 @@
 /*! \file
  * Main functions to set-up dpi information and to initialise sockets
  */
-#include <errno.h>
-#include <stdlib.h>             /* for exit */
-#include <fcntl.h>              /* for F_SETFD, F_GETFD, FD_CLOEXEC */
-
+#include <netinet/tcp.h>
+#include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
-#include <sys/socket.h>
-#include <netinet/tcp.h>
 
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
 #include <unistd.h>
-#include "dpid_common.h"
-#include "dpid.h"
+
+#include "../dpip/dpip.h"
 #include "dpi.h"
 #include "dpi_socket_dir.h"
+#include "dpid.h"
+#include "dpid_common.h"
 #include "misc_new.h"
 
-#include "../dpip/dpip.h"
-
 #define QUEUE 5
 
 volatile sig_atomic_t caught_sigchld = 0;
diff -r d4b18bae3331 dpid/dpid_common.c
--- a/dpid/dpid_common.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/dpid_common.c	Sat May 26 23:00:53 2012 +0400
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
+
 #include "dpid_common.h"
 
 /*
diff -r d4b18bae3331 dpid/dpidc.c
--- a/dpid/dpidc.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/dpidc.c	Sat May 26 23:00:53 2012 +0400
@@ -1,13 +1,14 @@
-#include <stdio.h>
-#include <stdlib.h>  /* for exit */
-#include <string.h>  /* for bzero */
-#include <unistd.h>  /* for read and write */
-#include <ctype.h>   /* for isxdigit */
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netdb.h>
+
+#include <ctype.h> /* for isxdigit */
 #include <errno.h>
+#include <stdio.h>
+#include <stdlib.h> /* for exit */
+#include <string.h> /* for bzero */
+#include <unistd.h> /* for read and write */
 
 #include "../dpip/dpip.h"
 
diff -r d4b18bae3331 dpid/main.c
--- a/dpid/main.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/main.c	Sat May 26 23:00:53 2012 +0400
@@ -15,11 +15,11 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <errno.h>       /* for ckd_write */
-#include <unistd.h>      /* for ckd_write */
-#include <stdlib.h>      /* for exit */
-#include <assert.h>      /* for assert */
-#include <sys/stat.h>    /* for umask */
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
 
 #include "dpid_common.h"
 #include "dpid.h"
diff -r d4b18bae3331 dpid/misc_new.c
--- a/dpid/misc_new.c	Sat May 26 23:00:40 2012 +0400
+++ b/dpid/misc_new.c	Sat May 26 23:00:53 2012 +0400
@@ -9,17 +9,18 @@
  * (at your option) any later version.
  */
 
-#include <errno.h>      /* errno, err-codes */
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <time.h>
 #include <unistd.h>
-#include <time.h>
-#include <sys/stat.h>   /* stat */
-#include <stdlib.h>     /* rand, srand */
 
 #include "../dlib/dlib.h"
 #include "dpid_common.h"
 #include "misc_new.h"   /* for function prototypes */
 
-
 /*
  * Close a FD handling EINTR.
  */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.