Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15b824d

Browse files
committed
Fix and simplify some code related to cryptohashes
This commit addresses two issues:- In pgcrypto, MD5 computation called pg_cryptohash_{init,update,final}without checking for the result status.- Simplify pg_checksum_raw_context to use only one variable for all theSHA2 options available in checksum manifests.Reported-by: Heikki LinnakangasDiscussion:https://postgr.es/m/f62f26bb-47a5-8411-46e5-4350823e06a5@iki.fi
1 parent9ffe227 commit15b824d

File tree

3 files changed

+32
-41
lines changed

3 files changed

+32
-41
lines changed

‎contrib/pgcrypto/internal.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,23 +96,26 @@ int_md5_update(PX_MD *h, const uint8 *data, unsigned dlen)
9696
{
9797
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
9898

99-
pg_cryptohash_update(ctx,data,dlen);
99+
if (pg_cryptohash_update(ctx,data,dlen)<0)
100+
elog(ERROR,"could not update %s context","MD5");
100101
}
101102

102103
staticvoid
103104
int_md5_reset(PX_MD*h)
104105
{
105106
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
106107

107-
pg_cryptohash_init(ctx);
108+
if (pg_cryptohash_init(ctx)<0)
109+
elog(ERROR,"could not initialize %s context","MD5");
108110
}
109111

110112
staticvoid
111113
int_md5_finish(PX_MD*h,uint8*dst)
112114
{
113115
pg_cryptohash_ctx*ctx= (pg_cryptohash_ctx*)h->p.ptr;
114116

115-
pg_cryptohash_final(ctx,dst);
117+
if (pg_cryptohash_final(ctx,dst)<0)
118+
elog(ERROR,"could not finalize %s context","MD5");
116119
}
117120

118121
staticvoid

‎src/common/checksum_helper.c

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -93,42 +93,42 @@ pg_checksum_init(pg_checksum_context *context, pg_checksum_type type)
9393
INIT_CRC32C(context->raw_context.c_crc32c);
9494
break;
9595
caseCHECKSUM_TYPE_SHA224:
96-
context->raw_context.c_sha224=pg_cryptohash_create(PG_SHA224);
97-
if (context->raw_context.c_sha224==NULL)
96+
context->raw_context.c_sha2=pg_cryptohash_create(PG_SHA224);
97+
if (context->raw_context.c_sha2==NULL)
9898
return-1;
99-
if (pg_cryptohash_init(context->raw_context.c_sha224)<0)
99+
if (pg_cryptohash_init(context->raw_context.c_sha2)<0)
100100
{
101-
pg_cryptohash_free(context->raw_context.c_sha224);
101+
pg_cryptohash_free(context->raw_context.c_sha2);
102102
return-1;
103103
}
104104
break;
105105
caseCHECKSUM_TYPE_SHA256:
106-
context->raw_context.c_sha256=pg_cryptohash_create(PG_SHA256);
107-
if (context->raw_context.c_sha256==NULL)
106+
context->raw_context.c_sha2=pg_cryptohash_create(PG_SHA256);
107+
if (context->raw_context.c_sha2==NULL)
108108
return-1;
109-
if (pg_cryptohash_init(context->raw_context.c_sha256)<0)
109+
if (pg_cryptohash_init(context->raw_context.c_sha2)<0)
110110
{
111-
pg_cryptohash_free(context->raw_context.c_sha256);
111+
pg_cryptohash_free(context->raw_context.c_sha2);
112112
return-1;
113113
}
114114
break;
115115
caseCHECKSUM_TYPE_SHA384:
116-
context->raw_context.c_sha384=pg_cryptohash_create(PG_SHA384);
117-
if (context->raw_context.c_sha384==NULL)
116+
context->raw_context.c_sha2=pg_cryptohash_create(PG_SHA384);
117+
if (context->raw_context.c_sha2==NULL)
118118
return-1;
119-
if (pg_cryptohash_init(context->raw_context.c_sha384)<0)
119+
if (pg_cryptohash_init(context->raw_context.c_sha2)<0)
120120
{
121-
pg_cryptohash_free(context->raw_context.c_sha384);
121+
pg_cryptohash_free(context->raw_context.c_sha2);
122122
return-1;
123123
}
124124
break;
125125
caseCHECKSUM_TYPE_SHA512:
126-
context->raw_context.c_sha512=pg_cryptohash_create(PG_SHA512);
127-
if (context->raw_context.c_sha512==NULL)
126+
context->raw_context.c_sha2=pg_cryptohash_create(PG_SHA512);
127+
if (context->raw_context.c_sha2==NULL)
128128
return-1;
129-
if (pg_cryptohash_init(context->raw_context.c_sha512)<0)
129+
if (pg_cryptohash_init(context->raw_context.c_sha2)<0)
130130
{
131-
pg_cryptohash_free(context->raw_context.c_sha512);
131+
pg_cryptohash_free(context->raw_context.c_sha2);
132132
return-1;
133133
}
134134
break;
@@ -154,19 +154,10 @@ pg_checksum_update(pg_checksum_context *context, const uint8 *input,
154154
COMP_CRC32C(context->raw_context.c_crc32c,input,len);
155155
break;
156156
caseCHECKSUM_TYPE_SHA224:
157-
if (pg_cryptohash_update(context->raw_context.c_sha224,input,len)<0)
158-
return-1;
159-
break;
160157
caseCHECKSUM_TYPE_SHA256:
161-
if (pg_cryptohash_update(context->raw_context.c_sha256,input,len)<0)
162-
return-1;
163-
break;
164158
caseCHECKSUM_TYPE_SHA384:
165-
if (pg_cryptohash_update(context->raw_context.c_sha384,input,len)<0)
166-
return-1;
167-
break;
168159
caseCHECKSUM_TYPE_SHA512:
169-
if (pg_cryptohash_update(context->raw_context.c_sha512,input,len)<0)
160+
if (pg_cryptohash_update(context->raw_context.c_sha2,input,len)<0)
170161
return-1;
171162
break;
172163
}
@@ -207,27 +198,27 @@ pg_checksum_final(pg_checksum_context *context, uint8 *output)
207198
memcpy(output,&context->raw_context.c_crc32c,retval);
208199
break;
209200
caseCHECKSUM_TYPE_SHA224:
210-
if (pg_cryptohash_final(context->raw_context.c_sha224,output)<0)
201+
if (pg_cryptohash_final(context->raw_context.c_sha2,output)<0)
211202
return-1;
212-
pg_cryptohash_free(context->raw_context.c_sha224);
203+
pg_cryptohash_free(context->raw_context.c_sha2);
213204
retval=PG_SHA224_DIGEST_LENGTH;
214205
break;
215206
caseCHECKSUM_TYPE_SHA256:
216-
if (pg_cryptohash_final(context->raw_context.c_sha256,output)<0)
207+
if (pg_cryptohash_final(context->raw_context.c_sha2,output)<0)
217208
return-1;
218-
pg_cryptohash_free(context->raw_context.c_sha256);
209+
pg_cryptohash_free(context->raw_context.c_sha2);
219210
retval=PG_SHA224_DIGEST_LENGTH;
220211
break;
221212
caseCHECKSUM_TYPE_SHA384:
222-
if (pg_cryptohash_final(context->raw_context.c_sha384,output)<0)
213+
if (pg_cryptohash_final(context->raw_context.c_sha2,output)<0)
223214
return-1;
224-
pg_cryptohash_free(context->raw_context.c_sha384);
215+
pg_cryptohash_free(context->raw_context.c_sha2);
225216
retval=PG_SHA384_DIGEST_LENGTH;
226217
break;
227218
caseCHECKSUM_TYPE_SHA512:
228-
if (pg_cryptohash_final(context->raw_context.c_sha512,output)<0)
219+
if (pg_cryptohash_final(context->raw_context.c_sha2,output)<0)
229220
return-1;
230-
pg_cryptohash_free(context->raw_context.c_sha512);
221+
pg_cryptohash_free(context->raw_context.c_sha2);
231222
retval=PG_SHA512_DIGEST_LENGTH;
232223
break;
233224
}

‎src/include/common/checksum_helper.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ typedef enum pg_checksum_type
4242
typedefunionpg_checksum_raw_context
4343
{
4444
pg_crc32cc_crc32c;
45-
pg_cryptohash_ctx*c_sha224;
46-
pg_cryptohash_ctx*c_sha256;
47-
pg_cryptohash_ctx*c_sha384;
48-
pg_cryptohash_ctx*c_sha512;
45+
pg_cryptohash_ctx*c_sha2;
4946
}pg_checksum_raw_context;
5047

5148
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp