Skip to content

Commit 2787db9

Browse files
committed
Small cleanups for pgcrypto. Marko Kreen
1 parent dd4a190 commit 2787db9

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

contrib/pgcrypto/fortuna.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.2 2005/07/11 15:07:59 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.3 2005/07/18 17:09:01 tgl Exp $
3030
*/
3131

3232
#include "postgres.h"
@@ -174,8 +174,8 @@ static void init_state(FState *st)
174174
}
175175

176176
/*
177-
* Must not reseed more ofter than RESEED_PER_SEC
178-
* times per second.
177+
* The time between reseed must be at least RESEED_INTERVAL
178+
* microseconds.
179179
*/
180180
static int too_often(FState *st)
181181
{
@@ -241,7 +241,6 @@ static void reseed(FState *st)
241241

242242
memset(&key_md, 0, sizeof(key_md));
243243
memset(buf, 0, BLOCK);
244-
n = k = 0;
245244
}
246245

247246
/*

contrib/pgcrypto/internal.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.20 2005/07/11 15:07:59 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.21 2005/07/18 17:09:01 tgl Exp $
3030
*/
3131

3232
#include "postgres.h"
@@ -127,6 +127,7 @@ int_md5_free(PX_MD * h)
127127
{
128128
MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
129129

130+
memset(ctx, 0, sizeof(*ctx));
130131
px_free(ctx);
131132
px_free(h);
132133
}
@@ -174,6 +175,7 @@ int_sha1_free(PX_MD * h)
174175
{
175176
SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
176177

178+
memset(ctx, 0, sizeof(*ctx));
177179
px_free(ctx);
178180
px_free(h);
179181
}
@@ -221,6 +223,7 @@ int_sha256_free(PX_MD * h)
221223
{
222224
SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
223225

226+
memset(ctx, 0, sizeof(*ctx));
224227
px_free(ctx);
225228
px_free(h);
226229
}
@@ -267,6 +270,7 @@ int_sha384_free(PX_MD * h)
267270
{
268271
SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
269272

273+
memset(ctx, 0, sizeof(*ctx));
270274
px_free(ctx);
271275
px_free(h);
272276
}
@@ -314,6 +318,7 @@ int_sha512_free(PX_MD * h)
314318
{
315319
SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
316320

321+
memset(ctx, 0, sizeof(*ctx));
317322
px_free(ctx);
318323
px_free(h);
319324
}
@@ -326,6 +331,7 @@ init_md5(PX_MD * md)
326331
MD5_CTX *ctx;
327332

328333
ctx = px_alloc(sizeof(*ctx));
334+
memset(ctx, 0, sizeof(*ctx));
329335

330336
md->p.ptr = ctx;
331337

@@ -345,6 +351,7 @@ init_sha1(PX_MD * md)
345351
SHA1_CTX *ctx;
346352

347353
ctx = px_alloc(sizeof(*ctx));
354+
memset(ctx, 0, sizeof(*ctx));
348355

349356
md->p.ptr = ctx;
350357

@@ -364,6 +371,7 @@ init_sha256(PX_MD * md)
364371
SHA256_CTX *ctx;
365372

366373
ctx = px_alloc(sizeof(*ctx));
374+
memset(ctx, 0, sizeof(*ctx));
367375

368376
md->p.ptr = ctx;
369377

@@ -383,6 +391,7 @@ init_sha384(PX_MD * md)
383391
SHA384_CTX *ctx;
384392

385393
ctx = px_alloc(sizeof(*ctx));
394+
memset(ctx, 0, sizeof(*ctx));
386395

387396
md->p.ptr = ctx;
388397

@@ -402,6 +411,7 @@ init_sha512(PX_MD * md)
402411
SHA512_CTX *ctx;
403412

404413
ctx = px_alloc(sizeof(*ctx));
414+
memset(ctx, 0, sizeof(*ctx));
405415

406416
md->p.ptr = ctx;
407417

@@ -829,6 +839,7 @@ static void system_reseed(void)
829839
fortuna_add_entropy(SYSTEM_ENTROPY, buf, n);
830840

831841
seed_time = t;
842+
memset(buf, 0, sizeof(buf));
832843
}
833844

834845
int

contrib/pgcrypto/pgp-compress.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-compress.c,v 1.3 2005/07/18 16:35:06 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-compress.c,v 1.4 2005/07/18 17:09:01 tgl Exp $
3030
*/
3131

3232
#include "postgres.h"
@@ -270,7 +270,11 @@ static int decompress_read(void *priv, PullFilter *src, int len,
270270
dec->stream.avail_out = dec->buf_len;
271271
dec->pos = dec->buf;
272272

273-
/* Z_NO_FLUSH, Z_SYNC_FLUSH */
273+
/*
274+
* Z_SYNC_FLUSH is tell zlib to output as much as possible.
275+
* It should do it anyway (Z_NO_FLUSH), but seems to reserve
276+
* the right not to. So lets follow the API.
277+
*/
274278
flush = dec->stream.avail_in ? Z_SYNC_FLUSH : Z_FINISH;
275279
res = inflate(&dec->stream, flush);
276280
if (res != Z_OK && res != Z_STREAM_END)

contrib/pgcrypto/pgp-decrypt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-decrypt.c,v 1.3 2005/07/18 16:35:06 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-decrypt.c,v 1.4 2005/07/18 17:09:01 tgl Exp $
3030
*/
3131

3232
#include "postgres.h"
@@ -339,7 +339,6 @@ static void mdc_free(void *priv)
339339
ctx->mdc_ctx = NULL;
340340
}
341341

342-
/* fixme: clarify */
343342
static int mdc_finish(PGP_Context *ctx, PullFilter *src,
344343
int len, uint8 **data_p)
345344
{
@@ -364,13 +363,15 @@ static int mdc_finish(PGP_Context *ctx, PullFilter *src,
364363
return 0;
365364
}
366365

366+
/* safety check */
367367
if (ctx->in_mdc_pkt > 1)
368368
{
369369
px_debug("mdc_finish: several times here?");
370370
return PXE_PGP_CORRUPT_DATA;
371371
}
372372
ctx->in_mdc_pkt++;
373373

374+
/* is the packet sane? */
374375
if (res != 20)
375376
{
376377
px_debug("mdc_finish: read failed, res=%d", res);

contrib/pgcrypto/pgp.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.1 2005/07/10 13:46:29 momjian Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp.h,v 1.2 2005/07/18 17:09:01 tgl Exp $
3030
*/
3131

3232
enum
@@ -238,8 +238,6 @@ unsigned pgp_armor_dec_len(unsigned len);
238238
int pgp_compress_filter(PushFilter **res, PGP_Context *ctx, PushFilter *dst);
239239
int pgp_decompress_filter(PullFilter **res, PGP_Context *ctx, PullFilter *src);
240240

241-
extern void (*pgp_packet_debug) (int tag, uint8 *buf, int len);
242-
243241
int pgp_key_alloc(PGP_PubKey **pk_p);
244242
void pgp_key_free(PGP_PubKey *pk);
245243
int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey *pk);

contrib/pgcrypto/random.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/random.c,v 1.14 2005/07/11 19:06:46 tgl Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/random.c,v 1.15 2005/07/18 17:09:01 tgl Exp $
3030
*/
3131

3232
#include "postgres.h"
@@ -44,7 +44,9 @@
4444
*/
4545
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
4646
|| defined(__NetBSD__) || defined(__DragonFly__) \
47-
|| defined(__darwin__) || defined(__SOLARIS__)
47+
|| defined(__darwin__) || defined(__SOLARIS__) \
48+
|| defined(__hpux) || defined(__HPUX__) \
49+
|| defined(__CYGWIN__) || defined(_AIX)
4850

4951
#define TRY_DEV_RANDOM
5052

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy