Re: The Axe list

From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: "Marko Kreen" <markokr(at)gmail(dot)com>
Cc: "Josh Berkus" <josh(at)agliodbs(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: The Axe list
Date: 2008-10-12 14:41:21
Message-ID: 20081012104121.dc106ca8.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, 12 Oct 2008 12:57:58 +0300
"Marko Kreen" <markokr(at)gmail(dot)com> wrote:
> On 10/11/08, D'Arcy J.M. Cain <darcy(at)druid(dot)net> wrote:
> > + if (!random_initialized)
> > + {
> > + srandom((unsigned int) time(NULL));
> > + random_initialized = true;
> > + }
>
> This is bad idea, postgres already does srandom()

Is that new? I added that to my local version at one time because I
was getting the same salt every time I ran it.

> > - * but I like to play safe */
> > + mysalt[2] = 0; /* technically the terminator is not
> > + * necessary but I like to play safe */
> > strcpy(result->password, crypt(str, mysalt));
> > PG_RETURN_POINTER(result);
> > }
>
> Comment change only? Ok.

If that turns out to be the only change I won't bother.

> > + if ((result = (char *) palloc(16)) != NULL)
> > + {
> > + result[0] = ':';
> > + strcpy(result + 1, password->password);
> > + }
>
> AFAIK palloc() cannot return NULL?

Really? My program will simply come crashing down if there is a memory
problem without giving me a chance to clean up?

> > + if (!a1 || !a2)
> > + PG_RETURN_BOOL(0);
> > +
> > text_to_cstring_buffer(a2, str, sizeof(str));
> > PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) == 0);
> > }
> > @@ -154,6 +166,9 @@ chkpass_ne(PG_FUNCTION_ARGS)
> > text *a2 = PG_GETARG_TEXT_PP(1);
> > char str[9];
> >
> > + if (!a1 || !a2)
> > + PG_RETURN_BOOL(0);
> > +
> > text_to_cstring_buffer(a2, str, sizeof(str));
> > PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) != 0);
> >
> > }
>
> The functions are already defined as STRICT, so unnecessary.
> Also returning non-NULL on NULL input seems to go against SQL style.

I'm a belt and suspenders guy. However, I agree that this is
unneccessary. So, I guess I just need to know, how long has PG been
doing srandom().

--
D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2008-10-12 15:10:33 Re: The Axe list
Previous Message Robert Haas 2008-10-12 13:46:11 Re: SELECT TOP %d PERCENT, or SELECT ... LIMIT %d PERCENT ?