Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 
sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv17831/src/backends/monet5/merovingian

Modified Files:
        utils.c 
Log Message:
propagated changes of Friday Mar 05 2010 - Wednesday Mar 10 2010
from the Feb2010 branch to the development trunk

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2010/03/05 - mr-meltdown: src/backends/monet5/merovingian/utils.c,1.23.2.1
  check return of fopen() in more places, as pointed out by Mark Bucciarelli
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2010/03/05 - mr-meltdown: src/backends/monet5/merovingian/utils.c,1.23.2.2
  It's better to allocate some memory to write to.  Change signature of 
generateSalt, since it doesn't allocate memory as I mistakenly thought it did.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Index: utils.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/utils.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- utils.c     7 Jan 2010 15:24:31 -0000       1.23
+++ utils.c     10 Mar 2010 14:29:50 -0000      1.24
@@ -286,7 +286,7 @@
  * Padds the remaining bytes in buf with null-bytes.
  */
 void
-generateSalt(char **buf, unsigned int len)
+generateSalt(char *buf, unsigned int len)
 {
        unsigned int c;
        unsigned int size = (unsigned int)rand();
@@ -294,24 +294,31 @@
        unsigned int min = len * 0.42;
        size = (size % (fill - min)) + min;
        for (c = 0; c < size; c++)
-               (*buf)[c] = seedChars[rand() % 62];
+               buf[c] = seedChars[rand() % 62];
        for ( ; c < len; c++)
-               (*buf)[c] = '\0';
+               buf[c] = '\0';
 }
 
 char *
 generatePassphraseFile(char *path)
 {
        FILE *f;
-       char *buf = alloca(sizeof(char) * 48);
+       unsigned int len = 48;
+       char buf[len];
 
-       generateSalt(&buf, 48);
-       f = fopen(path, "w");
-       if (fwrite(buf, 1, 48, f) < 48) {
-               snprintf(buf, sizeof(buf), "cannot write secret: %s",
+       generateSalt(buf, len);
+       if ((f = fopen(path, "w")) == NULL) {
+               char err[512];
+               snprintf(err, sizeof(err), "unable to open '%s': %s",
+                               path, strerror(errno));
+               return(strdup(err));
+       }
+       if (fwrite(buf, 1, len, f) < len) {
+               char err[512];
+               snprintf(err, sizeof(err), "cannot write secret: %s",
                                strerror(errno));
                fclose(f);
-               return(strdup(buf));
+               return(strdup(err));
        }
        fclose(f);
        return(NULL);


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to