Skip to content

Commit 447d764

Browse files
committed
fix
1 parent 7ba1cac commit 447d764

File tree

1 file changed

+58
-2
lines changed
  • src/backend/storage/file

1 file changed

+58
-2
lines changed

src/backend/storage/file/cfs.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,62 @@ static void cfs_rc4_init(void)
260260
}
261261
}
262262

263+
/*
264+
* For a file name like 'path/to/16384/16401[.123]' return part1 = 16384, part2 = 16401 and part3 = 123.
265+
* Returns 0 on success and negative value on error.
266+
*/
267+
static int extract_fname_parts(const char* fname, unsigned int* part1, unsigned int* part2, unsigned int* part3)
268+
{
269+
int idx = strlen(fname);
270+
if(idx == 0)
271+
return -1;
272+
idx--;
273+
274+
while(idx >= 0 && isdigit(fname[idx]))
275+
idx--;
276+
277+
if(idx == 0)
278+
return -2;
279+
280+
if(fname[idx] != '.')
281+
{
282+
*part3 = 0;
283+
goto assign_part2;
284+
}
285+
286+
*part3 = atoi(&fname[idx+1]);
287+
288+
idx--;
289+
while(idx >= 0 && isdigit(fname[idx]))
290+
idx--;
291+
292+
if(idx == 0)
293+
return -3;
294+
295+
assign_part2:
296+
*part2 = atoi(&fname[idx+1]);
297+
298+
idx--;
299+
while(idx >= 0 && isdigit(fname[idx]))
300+
idx--;
301+
302+
if(idx == 0)
303+
return -4;
304+
305+
*part1 = atoi(&fname[idx+1]);
306+
return 0;
307+
}
308+
263309
void cfs_encrypt(const char* fname, void* block, uint32 offs, uint32 size)
264310
{
265311
if (cfs_encryption)
266312
{
267-
elog(LOG, "cfs_encrypt, fname = %s, offs = %d, size = %d", fname, offs, size);
313+
unsigned int fname_part1, fname_part2, fname_part3;
314+
if(extract_fname_parts(fname, &fname_part1, &fname_part2, &fname_part3) < 0)
315+
fname_part1 = fname_part2 = fname_part3 = 0;
316+
317+
elog(LOG, "cfs_encrypt, fname = %s, part1 = %d, part2 = %d, part3 = %d, offs = %d, size = %d",
318+
fname, fname_part1, fname_part2, fname_part3, offs, size);
268319
cfs_rc4_encrypt_block(block, offs, size);
269320
}
270321
}
@@ -273,7 +324,12 @@ void cfs_decrypt(const char* fname, void* block, uint32 offs, uint32 size)
273324
{
274325
if (cfs_encryption)
275326
{
276-
elog(LOG, "cfs_decrypt, fname = %s, offs = %d, size = %d", fname, offs, size);
327+
unsigned int fname_part1, fname_part2, fname_part3;
328+
if(extract_fname_parts(fname, &fname_part1, &fname_part2, &fname_part3) < 0)
329+
fname_part1 = fname_part2 = fname_part3 = 0;
330+
331+
elog(LOG, "cfs_decrypt, fname = %s, part1 = %d, part2 = %d, part3 = %d, offs = %d, size = %d",
332+
fname, fname_part1, fname_part2, fname_part3, offs, size);
277333
cfs_rc4_encrypt_block(block, offs, size);
278334
}
279335
}

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