phar_path_check.re 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. +----------------------------------------------------------------------+
  3. | phar php single-file executable PHP extension |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | https://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Marcus Boerger <helly@php.net> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #include "phar_internal.h"
  19. phar_path_check_result phar_path_check(char **s, size_t *len, const char **error)
  20. {
  21. const unsigned char *p = (const unsigned char*)*s;
  22. const unsigned char *m;
  23. if (*len == 1 && *p == '.') {
  24. *error = "current directory reference";
  25. return pcr_err_curr_dir;
  26. } else if (*len == 2 && p[0] == '.' && p[1] == '.') {
  27. *error = "upper directory reference";
  28. return pcr_err_up_dir;
  29. }
  30. #define YYCTYPE unsigned char
  31. #define YYCURSOR p
  32. #define YYLIMIT p+*len
  33. #define YYMARKER m
  34. #define YYFILL(n) do {} while (0)
  35. loop:
  36. /*!re2c
  37. END = "\x00";
  38. NEWLINE = "\r"? "\n";
  39. UTF8T = [\x80-\xBF] ;
  40. UTF8_1 = [\x1A-\x7F] ;
  41. UTF8_2 = [\xC2-\xDF] UTF8T ;
  42. UTF8_3A = "\xE0" [\xA0-\xBF] UTF8T ;
  43. UTF8_3B = [\xE1-\xEC] UTF8T{2} ;
  44. UTF8_3C = "\xED" [\x80-\x9F] UTF8T ;
  45. UTF8_3D = [\xEE-\xEF] UTF8T{2} ;
  46. UTF8_3 = UTF8_3A | UTF8_3B | UTF8_3C | UTF8_3D ;
  47. UTF8_4A = "\xF0"[\x90-\xBF] UTF8T{2} ;
  48. UTF8_4B = [\xF1-\xF3] UTF8T{3} ;
  49. UTF8_4C = "\xF4" [\x80-\x8F] UTF8T{2} ;
  50. UTF8_4 = UTF8_4A | UTF8_4B | UTF8_4C ;
  51. UTF8 = UTF8_1 | UTF8_2 | UTF8_3 | UTF8_4 ;
  52. EOS = "/" | END;
  53. ANY = . | NEWLINE;
  54. "//" {
  55. *error = "double slash";
  56. return pcr_err_double_slash;
  57. }
  58. "/.." EOS {
  59. *error = "upper directory reference";
  60. return pcr_err_up_dir;
  61. }
  62. "/." EOS {
  63. *error = "current directory reference";
  64. return pcr_err_curr_dir;
  65. }
  66. "\\" {
  67. *error = "back-slash";
  68. return pcr_err_back_slash;
  69. }
  70. "*" {
  71. *error = "star";
  72. return pcr_err_star;
  73. }
  74. "?" {
  75. if (**s == '/') {
  76. (*s)++;
  77. }
  78. *len = (p - (const unsigned char*)*s) -1;
  79. *error = NULL;
  80. return pcr_use_query;
  81. }
  82. UTF8 {
  83. goto loop;
  84. }
  85. END {
  86. if (**s == '/') {
  87. (*s)++;
  88. (*len)--;
  89. }
  90. if ((p - (const unsigned char*)*s) - 1 != *len)
  91. {
  92. *error ="illegal character";
  93. return pcr_err_illegal_char;
  94. }
  95. *error = NULL;
  96. return pcr_is_ok;
  97. }
  98. ANY {
  99. *error ="illegal character";
  100. return pcr_err_illegal_char;
  101. }
  102. */
  103. }