|
Lines 655-736
rewrite_percent_specifiers(char *s)
Link Here
|
| 655 |
int |
655 |
int |
| 656 |
gs_add_outputfile_control_path(gs_memory_t *mem, const char *fname) |
656 |
gs_add_outputfile_control_path(gs_memory_t *mem, const char *fname) |
| 657 |
{ |
657 |
{ |
| 658 |
char *fp, f[gp_file_name_sizeof]; |
658 |
char f[gp_file_name_sizeof]; |
| 659 |
const int pipe = 124; /* ASCII code for '|' */ |
659 |
int code; |
| 660 |
const int len = strlen(fname); |
|
|
| 661 |
int i, code; |
| 662 |
|
660 |
|
| 663 |
/* Be sure the string copy will fit */ |
661 |
/* Be sure the string copy will fit */ |
| 664 |
if (len >= gp_file_name_sizeof) |
662 |
if (strlen(fname) >= gp_file_name_sizeof) |
| 665 |
return gs_error_rangecheck; |
663 |
return gs_error_rangecheck; |
| 666 |
strcpy(f, fname); |
664 |
strcpy(f, fname); |
| 667 |
fp = f; |
|
|
| 668 |
/* Try to rewrite any %d (or similar) in the string */ |
665 |
/* Try to rewrite any %d (or similar) in the string */ |
| 669 |
rewrite_percent_specifiers(f); |
666 |
rewrite_percent_specifiers(f); |
| 670 |
for (i = 0; i < len; i++) { |
667 |
|
| 671 |
if (f[i] == pipe) { |
668 |
code = gs_add_control_path(mem, gs_permit_file_control, f); |
| 672 |
fp = &f[i + 1]; |
|
|
| 673 |
/* Because we potentially have to check file permissions at two levels |
| 674 |
for the output file (gx_device_open_output_file and the low level |
| 675 |
fopen API, if we're using a pipe, we have to add both the full string, |
| 676 |
(including the '|', and just the command to which we pipe - since at |
| 677 |
the pipe_fopen(), the leading '|' has been stripped. |
| 678 |
*/ |
| 679 |
code = gs_add_control_path(mem, gs_permit_file_writing, f); |
| 680 |
if (code < 0) |
| 681 |
return code; |
| 682 |
code = gs_add_control_path(mem, gs_permit_file_control, f); |
| 683 |
if (code < 0) |
| 684 |
return code; |
| 685 |
break; |
| 686 |
} |
| 687 |
if (!IS_WHITESPACE(f[i])) |
| 688 |
break; |
| 689 |
} |
| 690 |
code = gs_add_control_path(mem, gs_permit_file_control, fp); |
| 691 |
if (code < 0) |
669 |
if (code < 0) |
| 692 |
return code; |
670 |
return code; |
| 693 |
return gs_add_control_path(mem, gs_permit_file_writing, fp); |
671 |
return gs_add_control_path(mem, gs_permit_file_writing, f); |
| 694 |
} |
672 |
} |
| 695 |
|
673 |
|
| 696 |
int |
674 |
int |
| 697 |
gs_remove_outputfile_control_path(gs_memory_t *mem, const char *fname) |
675 |
gs_remove_outputfile_control_path(gs_memory_t *mem, const char *fname) |
| 698 |
{ |
676 |
{ |
| 699 |
char *fp, f[gp_file_name_sizeof]; |
677 |
char f[gp_file_name_sizeof]; |
| 700 |
const int pipe = 124; /* ASCII code for '|' */ |
678 |
int code; |
| 701 |
const int len = strlen(fname); |
|
|
| 702 |
int i, code; |
| 703 |
|
679 |
|
| 704 |
/* Be sure the string copy will fit */ |
680 |
/* Be sure the string copy will fit */ |
| 705 |
if (len >= gp_file_name_sizeof) |
681 |
if (strlen(fname) >= gp_file_name_sizeof) |
| 706 |
return gs_error_rangecheck; |
682 |
return gs_error_rangecheck; |
| 707 |
strcpy(f, fname); |
683 |
strcpy(f, fname); |
| 708 |
fp = f; |
|
|
| 709 |
/* Try to rewrite any %d (or similar) in the string */ |
684 |
/* Try to rewrite any %d (or similar) in the string */ |
| 710 |
for (i = 0; i < len; i++) { |
685 |
rewrite_percent_specifiers(f); |
| 711 |
if (f[i] == pipe) { |
686 |
|
| 712 |
fp = &f[i + 1]; |
687 |
code = gs_remove_control_path(mem, gs_permit_file_control, f); |
| 713 |
/* Because we potentially have to check file permissions at two levels |
|
|
| 714 |
for the output file (gx_device_open_output_file and the low level |
| 715 |
fopen API, if we're using a pipe, we have to add both the full string, |
| 716 |
(including the '|', and just the command to which we pipe - since at |
| 717 |
the pipe_fopen(), the leading '|' has been stripped. |
| 718 |
*/ |
| 719 |
code = gs_remove_control_path(mem, gs_permit_file_writing, f); |
| 720 |
if (code < 0) |
| 721 |
return code; |
| 722 |
code = gs_remove_control_path(mem, gs_permit_file_control, f); |
| 723 |
if (code < 0) |
| 724 |
return code; |
| 725 |
break; |
| 726 |
} |
| 727 |
if (!IS_WHITESPACE(f[i])) |
| 728 |
break; |
| 729 |
} |
| 730 |
code = gs_remove_control_path(mem, gs_permit_file_control, fp); |
| 731 |
if (code < 0) |
688 |
if (code < 0) |
| 732 |
return code; |
689 |
return code; |
| 733 |
return gs_remove_control_path(mem, gs_permit_file_writing, fp); |
690 |
return gs_remove_control_path(mem, gs_permit_file_writing, f); |
| 734 |
} |
691 |
} |
| 735 |
|
692 |
|
| 736 |
int |
693 |
int |