Correction device, correction method, and correction program

By calculating priorities based on processing cost and character string properties, the solution converts regular expressions to improve readability by replacing range characters with placeholders, addressing the issue of poor readability in conventional ReDoS correction techniques.

JP7800680B2Active Publication Date: 2026-01-16NIPPON TELEGRAPH & TELEPHONE CORP
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
JP2024526099
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Filing Date
2022-06-07
Publication Date
2026-01-16
Estimated Expiration
2042-06-07

AI Technical Summary

Technical Problem

Conventional techniques for correcting regular expressions to prevent Regular Expression Denial of Service (ReDoS) often result in poor readability of the corrected expressions, as multiple candidate expressions with fixed vulnerabilities may differ significantly in human readability.

Method used

A calculation unit determines a priority for each template by evaluating processing cost and character string properties, and a conversion unit converts these templates into a second regular expression with improved readability by replacing range characters with placeholders, ensuring the corrected expression runs in linear time relative to the string length.

Benefits of technology

The solution enhances the readability of corrected regular expressions by minimizing the use of costly operators, reducing character count, and maintaining similarity to the original expression, thus improving human understandability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007800680000001
    Figure 0007800680000001
  • Figure 0007800680000002
    Figure 0007800680000002
  • Figure 0007800680000003
    Figure 0007800680000003
Patent Text Reader

Abstract

A correction device according to an embodiment of the present invention calculates, for each template in which at least some of a range of characters in a first regular expression are replaced with placeholders, a priority that corresponds to at least one of a processing cost as a regular expression and properties as a character string of each of the templates. The correction device converts each of the templates, in descending order of priority, to a second regular expression in which a vulnerability in the first regular expression is eliminated.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical Field]

[0001] The present invention relates to a correction device, a correction method, and a correction program. [Background technology]

[0002] In the real world, regular expressions are implemented as regular expression engines and used in a variety of situations. For example, regular expression engines are used in web applications that have a screen for entering email addresses to verify whether the string entered by the user is an email address. Regular expression engines are also used, for example, to sanitize data sent from external sources, extract elements, and are included in standard libraries of general-purpose programming languages.

[0003] Here, the analysis algorithm based on the backtracking method adopted by many regular expression engines has the drawback that it can take an enormous amount of time to process depending on the combination of the data to be analyzed and the regular expression.Regular Expression Denial of Service (ReDoS) is a known cyber attack that exploits this drawback (Reference: "Regular expression Denial of Service - ReDoS", https: / / owasp.org / www-community / attacks / Regular_expression_Denial_of_Service_-_ReDoS).

[0004] A regular expression that runs in linear time on a regular expression engine relative to the length of the string to be matched is called a non-fragile regular expression. Conversely, a regular expression that runs in exponential time on a regular expression engine relative to the length of the string to be matched is called a fragile regular expression.

[0005] Conventionally, RFixer (see, for example, Non-Patent Document 1) is known as a technology for eliminating the threat of ReDoS, which corrects errors in the language accepted by regular expressions. Also known is a method of obtaining a non-vulnerable regular expression by converting a pure regular expression into a deterministic finite automaton and then converting it back (see, for example, Non-Patent Document 2). [Prior art documents] [Non-patent literature]

[0006] [Non-Patent Document 1] Rong Pan, Qinheping Hu, Gaowei Xu, and Loris D'Antoni. 2019. Automatic Repair of Regular Expressions. Proc. ACM Program. Lang. 3, OOPSLA, Article 139 (Oct. 2019), 29 pages. [Non-patent document 2] Brink van der Merwe, Nicolaas Weideman, and Martin Berglund. 2017. Turning Evil Regexes Harmless. In Proceedings of the South African Institute of Computer Scientists and Information Technologists (SAICSIT'17). Association for Computing Machinery, New York, NY, USA, Article 38, 10 pages. Summary of the Invention [Problem to be solved by the invention]

[0007] However, the conventional techniques have a problem in that the readability of the corrected regular expression may be poor.

[0008] For example, there may be multiple candidate regular expressions for which vulnerabilities have been fixed. Even if the candidate regular expressions after correction share the same functionality as regular expressions, they may differ in readability from a human perspective, and it is not always possible to obtain a highly readable regular expression. [Means for solving the problem]

[0009] In order to solve the above-mentioned problems and achieve the object, the correction device is characterized by having a calculation unit that calculates a priority for each template in which at least a portion of the range characters in a first regular expression have been replaced with placeholders, based on at least one of the processing cost of each of the templates as a regular expression or the properties of each of the templates as a character string, and a conversion unit that converts each of the templates in descending order of priority into a second regular expression in which the vulnerability of the first regular expression has been eliminated. [Effects of the Invention]

[0010] According to the present invention, the readability of the corrected regular expression can be improved. [Brief explanation of the drawings]

[0011] [Figure 1] FIG. 1 is a diagram illustrating an example of the configuration of a repair device according to the first embodiment. [Figure 2] FIG. 2 is a diagram showing an example of the syntax of a regular expression. [Figure 3] FIG. 3 is a diagram illustrating an example of cost information. [Figure 4] FIG. 4 is a diagram showing examples of Positive Examples and Negative Examples. [Figure 5] FIG. 5 is a diagram illustrating a method for generating a set of character strings. [Figure 6] FIG. 6 is a diagram for explaining a method for synthesizing regular expressions. [Figure 7] FIG. 7 is a diagram illustrating a method for calculating a score based on costs. [Figure 8]FIG. 8 is a diagram illustrating a method for calculating a score based on the number of characters. [Figure 9] FIG. 9 is a diagram illustrating a method for calculating a score based on the cost and the number of characters. [Figure 10] FIG. 10 is a diagram illustrating a method for calculating a score based on the degree of deviation as a character string. [Figure 11] FIG. 11 is a flowchart showing the flow of processing by the repair device according to the first embodiment. [Figure 12] FIG. 12 is a flowchart showing the flow of the regular expression correction process. [Figure 13] FIG. 13 is a flowchart showing the flow of the template storage process. [Figure 14] FIG. 14 is a diagram illustrating an example of a computer that executes a correction program. DETAILED DESCRIPTION OF THE INVENTION

[0012] DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Preferred embodiments of a repair device, a repair method, and a repair program according to the present invention will be described in detail below with reference to the accompanying drawings. However, the present invention is not limited to the following embodiments.

[0013] [Configuration of the first embodiment] First, the configuration of a correction device according to the first embodiment will be described with reference to Fig. 1. Fig. 1 is a diagram showing an example of the configuration of a correction device according to the first embodiment. As shown in Fig. 1, a correction device 10 receives an input of a regular expression before correction, corrects the input regular expression, and outputs the corrected regular expression.

[0014] Here, the regular expressions in this embodiment are regular expressions that have been extended to fit the real world, and comply with the syntax defined in Backus-Naur form (BNF). FIG. 2 is a diagram showing an example of the syntax of a regular expression. Regular expression r in FIG. 2 is an example of a regular expression in this embodiment. In the following description, "\" in a regular expression may be replaced with a backslash as appropriate.

[0015] In Figure 2, "C" is a set of characters, "x" is a string, and "i" is a natural number. The syntax in Figure 2 is used by existing regular expression engines (Reference: https: / / perldoc.perl.org / perlre.html).

[0016] Also, "." is a symbol that represents any single character. In other words, "." is syntactic sugar for the range character "[C]" in Figure 2. Also, a set of characters that does not match the range character "[C]" can be written as "[^C]". Also, the empty set is written as "[]", which means that it does not match any characters.

[0017] 1, the description will be given of each unit of the correction device 10. As shown in FIG.

[0018] The interface unit 11 is an interface for inputting, outputting, and communicating data. For example, the interface unit 11 accepts data input from input devices such as a keyboard and a mouse. Also, for example, the interface unit 11 outputs data to output devices such as a display and a speaker.

[0019] The interface unit 11 may also be a device for performing communication via a network (for example, a network interface card (NIC)).

[0020] The storage unit 12 is a storage device such as an HDD (Hard Disk Drive), an SSD (Solid State Drive), an optical disk, etc. The storage unit 12 may also be a data-rewritable semiconductor memory such as a RAM (Random Access Memory), a flash memory, or an NVSRAM (Non Volatile Static Random Access Memory). The storage unit 12 stores an OS (Operating System) and various programs executed by the correction device 10.

[0021] The memory unit 12 stores substitution candidate syntax information 121. The substitution candidate syntax information 121 is a set of regular expressions or templates, which are the syntax of regular expressions to be replaced with range characters or holes.

[0022] For example, the substitution candidate syntax information 121 is "□□, □|□, □*, (□), \i, (?=□), (?!□), (?<=□), (?<!□)". Here, "□" is a hole. Holes and templates will be described later.

[0023] The cost information 122 is information that defines the cost for processing each operator of the regular expression. Also, the cost information 122 includes the cost of holes. The cost is used in the calculation of the priority described later. FIG. 3 is a diagram showing an example of cost information. Also, the details of the cost will be described later.

[0024] The control unit 13 controls the entire correction device 10. The control unit 13 is, for example, an electronic circuit such as a CPU (Central Processing Unit), MPU (Micro Processing Unit), GPU (Graphics Processing Unit), or an integrated circuit such as an ASIC (Application Specific Integrated Circuit) or FPGA (Field Programmable Gate Array).

[0025] Also, the control unit 13 has an internal memory for storing programs and control data that define various processing procedures, and executes each process using the internal memory. Also, the control unit 13 functions as various processing units when various programs operate. For example, the control unit 13 has a generation unit 131 and a synthesis unit 132.

[0026] The generation unit 131 generates Positive Examples, which is a set of strings accepted by the regular expression before correction, and Negative Examples, which is a set of strings rejected by the regular expression before correction.

[0027] The Positive Examples are an example of the first set, the Negative Examples are an example of the second set, and the regular expression before correction is an example of the first regular expression.

[0028] Figure 4 shows examples of Positive Examples and Negative Examples. Here, we assume that the regular expression before correction is ".*.*=.*". In this case, "=", "abcd==", "==abcd", and "ab=c" included in the Positive Examples match the regular expression ".*.*=.*" (are accepted). On the other hand, "abc" included in the Negative Examples does not match the regular expression ".*.*=.*" (is rejected).

[0029] The generation unit 131 can enumerate all character strings that combine characters of a specific length or less, and classify each character string into a Positive Example if it is accepted by the regular expression, or into a Negative Example if it is rejected. Note that the generation unit 131 may generate Positive Examples and Negative Examples using the method described in Non-Patent Document 1.

[0030] If all the character strings were simply listed, an explosive number of examples would be generated. To avoid this, the generation unit 131 may generate character strings of Positive Examples and character strings of Negative Examples from only the characters that appear in the regular expression before correction.

[0031] For example, if the regular expression is "ab[cd]*", the generating unit 131 generates candidate character strings by combining "a" and "b" with one character randomly selected from "[c, d]".

[0032] FIG. 5 is a diagram illustrating a method for generating a set of character strings. In the example of FIG. 5, the regular expression before correction is ".*.*@example[.]com". In this case, the generation unit 131 classifies the character strings "@example.com", "a@example.com", and "gc@example.com", which are accepted by the regular expression ".*.*@example[.]com", into Positive Examples. On the other hand, the generation unit 131 classifies the character strings "example.com", "@.com", "@examplecom", "@example.", etc., which are rejected by the regular expression ".*.*@example[.]com", into Negative Examples.

[0033] The synthesis unit 132 synthesizes a modified regular expression, which is a regular expression in which the range character in the pre-modification regular expression is replaced with a predetermined syntax and which accepts character strings of the Positive Examples and rejects character strings of the Negative Examples. The modified regular expression is an example of a second regular expression.

[0034] The processing by the synthesis unit 132 can be roughly divided into a step of creating a template and a step of assigning to the template.

[0035] In the step of creating a template, the synthesis unit 132 creates the template by replacing range characters in the regular expression with placeholders.

[0036] In the step of assigning to a template, the synthesis unit 132 assigns a predetermined syntax to the placeholder to synthesize a non-vulnerable regular expression. Hereinafter, the placeholder will be called a hole and represented by "□".

[0037] The synthesis unit 132 performs processing while maintaining a priority queue. Priorities are assigned to templates stored in the queue.

[0038] When the synthesis unit 132 extracts an element from the queue, it preferentially extracts the template with the highest priority among the stored templates. At the start of processing, the synthesis unit 132 stores the regular expression before modification in the queue as a template. Note that the priority of the regular expression before modification stored in the queue is necessarily the highest.

[0039] First, the step of creating a template executed by the synthesis unit 132 will be described. When the template extracted by the synthesis unit 132 contains a range character, the synthesis unit 132 replaces the range character contained in the template with a hole. Note that the range character is represented, for example, as "[C]" or ". ". On the other hand, when the template extracted by the synthesis unit 132 contains a hole, any one of the holes may be replaced with a predetermined syntax.

[0040] For example, the synthesis unit 132 creates templates "□*.*=.*", ".*□*=.*", and ".*.*=□*" by replacing the range characters of the regular expression before modification ". *.*=.*" stored in the queue as a template, and stores them in the queue. Note that the template once extracted shall be discarded.

[0041] In this way, the synthesis unit 132 synthesizes the regular expression after modification based on the template obtained by replacing at least a part of the range characters in the regular expression before modification with holes and further replacing the replaced holes with a predetermined syntax.

[0042] Furthermore, the synthesis unit 132 can replace the hole with a syntax such as "□□", "□|□", "□*", "(□)", "\i", "(?=□)", "(?!□)", "(?<=□)", "(?<!□)" included in the replacement candidate syntax information 121. In this case, the synthesis unit 132 synthesizes the regular expression after modification based on the template obtained by replacing the hole contained in the template with any one of the predetermined syntaxes containing a hole, namely "□□", "□|□", "□*", "(□)", "\i", "(?=□)", "(?!□)", "(?<=□)", "(?<!□)" (where □ is a hole).

[0043] Next, we will explain the steps of assigning to templates, which are executed by the synthesis unit 132. Here, it is assumed that the synthesis unit 132 repeats the steps of creating templates, and creates, for example, a template "□*□*=.*" and stores it in the queue. For example, the synthesis unit 132 obtains the template "□*□*=.*" by replacing the range character "." on the left side of the template "□*.*=.*" with a hole.

[0044] The synthesis unit 132 searches for assignment of range characters that satisfy the conditions for holes included in the template. For example, the synthesis unit 132 performs the search using a Satisfiability Modulo Theories (SMT) solver (for example, a Z3 solver).

[0045] If the template is "□*□*=.*" and the Positive Examples and Negative Examples are as shown in Figure 4, the synthesis unit 132 can obtain the assignment "[]*[^=]*=.*" by searching. The synthesis unit 132 removes "[]", which is an empty set, and obtains the regular expression "[^=]*=.*".

[0046] Here, the synthesis unit 132 functions as a conversion unit. That is, the synthesis unit 132 converts each template, in descending order of priority, into a modified regular expression that eliminates the vulnerability of the pre-modification regular expression. For example, the synthesis unit 132 converts the template "□*□*=.*" into the regular expression "[^=]*=.*".

[0047] The regular expression "[^=]*=.*" accepts the Positive Examples and rejects the Negative Examples in Figure 4. In addition, the regular expression "[^=]*=.*" contains at most one match for the same character, so it can be said to have a non-vulnerable property.

[0048] As a result, the synthesis unit 132 can be said to convert the template into a modified regular expression, which is a regular expression in which the placeholders in the template are replaced with a predetermined syntax, and which accepts Positive Examples and rejects Negative Examples.

[0049] In this embodiment, as described above, a regular expression that runs on a regular expression engine in linear time relative to the length of the string to be matched is called a non-fragile regular expression. Conversely, a regular expression that runs on a regular expression engine in, for example, exponential time relative to the length of the string to be matched is called a fragile regular expression.

[0050] The synthesis of invulnerable regular expressions by the synthesis unit 132 utilizes the property of strongly one-unambiguous, which was devised by Koch and Scherzinger et al. (Reference: Christoph Koch and Stefanie Scherzinger. 2007. Attribute Grammars for Scalable Query Processing on XML Streams. The VLDB Journal 16, 3 (July 2007), 317-342.), which has been improved to suit real-world extensions.

[0051] Strongly one-unambiguous means that the next operation that the regular expression engine processes is uniquely determined once the character currently being parsed is determined.

[0052] Similarly, if the regular expression before correction is ".*.*@example[.]com", the synthesis unit 132 can obtain the non-vulnerable regular expression "[^@]*@example[.]com", as shown in FIG.

[0053] [Priority calculation] The synthesis unit 132 calculates the priority when storing a regular expression or a template in a queue. At this time, the synthesis unit 132 functions as a calculation unit.

[0054] The synthesis unit 132 calculates a priority for each template in which at least a part of the range characters in the first regular expression has been replaced with a placeholder, based on at least one of the processing cost of each template as a regular expression or the properties of the template as a character string.

[0055] The cost information 122 is an example of a processing cost for a regular expression. The properties of a character string include, for example, the number of characters (size, length), the degree of deviation or similarity from a specific character string, and the like.

[0056] Examples of score calculation methods will be described below. The synthesis unit 132 may use each of the calculation methods described here alone or may use a combination of the calculation methods. The smaller the score, the higher the priority. The synthesis unit 132 may use the reciprocal of the score or a value obtained by inverting the sign of the score as the priority.

[0057] Fig. 7 is a diagram illustrating a method for calculating a score based on cost. As shown in Fig. 7, the synthesis unit 132 can calculate a priority (score) according to the cost of each operator of a regular expression included in a predetermined template.

[0058] The cost for each operator is as shown in Figure 3. For example, the cost increases depending on the complexity of handling the operator and holes. In the example of Figure 3, the cost of a fixed character is 0, and the cost of an operator that indicates any character (for example, a range character) is 1. Note that fixed characters such as "a", "1", and " / " are abbreviations for "[a]", "[1]", and "[ / ]", respectively, and are a type of range character, but their complexity is extremely low, so their cost is set to 0.

[0059] Furthermore, operators that select or repeat characters and strings have a cost of 3. Operators that obtain, reference, or search for specified strings or patterns (capture, backreference, various lookaheads, various lookbehinds, etc.) have a cost of 7.

[0060] Also, the hole is replaced with any one of "□□, □|□, □*, (□), \i, (?=□), (?!□), (?<=□), (?<!□)", or the range characters are assigned as the result of the search. Therefore, the cost of the hole is determined to be 11, which is the sum of the maximum cost of 7 of the operators added after replacement, the cost of 1 of the range characters, and the cost of 3 of the selection operator since any one of them is selected.

[0061] Note that the method of determining the cost is not limited to what is described here and may be determined by any method.

[0062] Returning to FIG. 7, the template "(□|□)*.*=.*" includes two holes with a cost of 11, one capture with a cost of 7, one selection with a cost of 3, three repetitions with a cost of 3, and two range characters with a cost of 1. Therefore, the synthesis unit 132 sums up the costs and calculates the score of the template "(□|□)*.*=.*" to be 43.

[0063] Also, the template "□*□*=.*" includes two holes with a cost of 11, three repetitions with a cost of 3, and one range character with a cost of 1. Therefore, the synthesis unit 132 sums up the costs and calculates the score of the template "□*□*=.*" to be 32.

[0064] Also, the template "(?=□)*@hoge\.com" includes one hole with a cost of 11, one positive lookahead with a cost of 7, and one repetition with a cost of 3. Therefore, the synthesis unit 132 sums up the costs and calculates the score of the template "(?=□)*@hoge\.com" to be 21.

[0065] FIG. 8 is a diagram for explaining the method of calculating the score based on the number of characters. As shown in FIG. 8, the synthesis unit 132 calculates the priority according to the number of characters of the template.

[0066] As shown in FIG. 8, the number of characters in the template "(□|□)*.*=.*" is 11, and therefore the synthesis unit 132 calculates the score of the template "(□|□)*.*=.*" as 11.

[0067] Furthermore, since the number of characters in the template "□*□*=.*" is seven, the synthesis unit 132 calculates the score of the template "□*□*=.*" as seven.

[0068] Furthermore, since the number of characters in the template "(?=□)*@hoge\.com" is 16, the synthesis unit 132 calculates the score of the template "(?=□)*@hoge\.com" as 16.

[0069] Fig. 9 is a diagram illustrating a method for calculating a score based on the cost and the number of characters. As shown in Fig. 9, the synthesis unit 132 may calculate a final score by multiplying the score based on the cost described in Fig. 7 by the score based on the number of characters described in Fig. 8.

[0070] As shown in Figure 9, the cost-based score of the template "(□|□)*.*=.*" is 43 and the score based on the number of characters is 11, so the synthesis unit 132 multiplies each score and calculates a final score of 473.

[0071] Furthermore, the cost-based score of the template "□*□*=.*" is 32, and the score based on the number of characters is 7, so the synthesis unit 132 multiplies the scores together to calculate a final score of 224.

[0072] Furthermore, the cost-based score of the template "(?=□)*@hoge\.com" is 21, and the score based on the number of characters is 16, so the synthesis unit 132 multiplies the scores together to calculate a final score of 336.

[0073] FIG. 10 is a diagram illustrating a method for calculating a score based on the degree of deviation as a character string. Here, the synthesis unit 132 calculates the Levenshtein distance between the template and the regular expression before correction as the score. The Levenshtein distance is an example of the degree of deviation between character strings. It is assumed that the regular expression before correction is ".*.*=.*".

[0074] As shown in FIG. 10, the Levenshtein distance between the template "(□|□)*.*=.*" and the regular expression ".*.*=.*" is 5, so the synthesis unit 132 calculates the score as 5.

[0075] In this case, the transformation can be done in five steps: "(□|□)*.*=.*" → "□|□)*.*=.*" → "|□)*.*=.*" → "□)*.*=.*" → ")*.*=.*" → ".*.*=.*", so the Levenshtein distance is 5.

[0076] Furthermore, since the Levenshtein distance between the template "□*□*=.*" and the regular expression ".*.*=.*" is 2, the synthesis unit 132 calculates the score as 2.

[0077] According to the method described here, the better the readability, the higher the priority (the smaller the score). For example, the more costly an operator (lookahead, capture, etc.) is, the worse the readability is likely to be. Also, for example, the more characters there are, the worse the readability is likely to be. Also, for example, the more the corrected regular expression deviates from the regular expression before correction, the more difficult it is for humans to decipher the meaning of the corrected regular expression, and the worse the readability is likely to be.

[0078] [Processing of the first embodiment] 11 is a flowchart showing the flow of processing by the editing device according to the first embodiment. First, the editing device 10 receives an input of a regular expression (step S10).

[0079] Next, the modification device 10 generates a set of character strings (Positive Examples) that are accepted by the input regular expression (Step S20). The modification device 10 also generates a set of character strings (Negative Examples) that are rejected by the input regular expression (Step S30).

[0080] For example, the modifying device 10 can create an extended automaton from the input regular expression before modification, and generate a set of strings that covers all paths of the extended automaton.

[0081] Next, the editing device 10 generates (combines) a regular expression based on the input regular expression, the accepted string, and the rejected string (step S40), and then outputs the generated regular expression (step S50).

[0082] Fig. 12 is a flowchart showing the flow of the regular expression synthesis process. The process in Fig. 12 corresponds to step S40 in Fig. 11. First, the modifying device 10 stores the input regular expression in a queue as a template (step S401).

[0083] Next, the modifying device 10 acquires the template with the highest priority from the queue (step S402).

[0084] Next, the modifying device 10 searches for an assignment of range characters to holes that accepts accepted character strings, rejects rejected character strings, and satisfies the conditions regarding vulnerability (step S403).

[0085] The correction device 10 determines whether there is an assignment of search results (step S404). If there is no assignment of search results (step S404, No), the correction device 10 replaces the range characters with holes or replaces the holes with a predetermined pattern (step S405). The predetermined pattern is, for example, a syntax such as "□□", "□|□", "□*", "(□)", "\i", "(?=□)", "(?!□)", "(?<=□)", "(?<!□)". Note that if the input regular expression stored in the queue in step S401 becomes the target of the search in step S403, it is regarded as having no assignment (No) in step S404.

[0086] Then, the correction device 10 stores the processed template in step S405 in the queue (step S406). The processed template here is a template in which the range characters are replaced with holes or a template in which the holes are replaced with a predetermined pattern.

[0087] On the other hand, if there is an assignment of search results (step S404, Yes), the correction device 10 synthesizes a non-vulnerable regular expression based on the assignment of search results (step S407).

[0088] Figure 13 is a flowchart showing the flow of the template storage process. The process in Figure 13 corresponds to step S406 in Figure 12. As shown in Figure 13, first, the correction device 10 calculates the score of the template (step S4061). The correction device 10 can calculate the score according to the cost, the number of characters, the degree of separation between the template and the original regular expression, etc.

[0089] Next, the correction device 10 determines the priority based on the score (step S4062). For example, the correction device 10 determines that the lower the score, the higher the priority.

[0090] Then, the correction device 10 stores the template in the queue together with the priority (step S4063). The templates in the queue are taken out in descending order of priority.

[0091] [Advantages of the first embodiment] As described above, for each template in which at least some of the range characters in the first regular expression have been replaced with placeholders, the synthesis unit 132 calculates a priority based on at least one of the processing cost of each template as a regular expression and the properties of the template as a character string. The synthesis unit 132 converts each template in descending order of priority into a second regular expression in which the vulnerability of the first regular expression has been resolved. This makes it possible to improve the readability of the corrected regular expression.

[0092] Furthermore, generation unit 131 generates a first set that is a set of character strings accepted by the first regular expression, and a second set that is a set of character strings rejected by the first regular expression. Synthesis unit 132 converts the template into a second regular expression that is a regular expression in which placeholders in the template are replaced with predetermined syntax, and that accepts character strings in the first set and rejects character strings in the second set.

[0093] The synthesis unit 132 calculates the priority according to the cost of each operator in the regular expression included in the predetermined template. This makes it possible to avoid using operators with high costs (lookahead, capture, etc.) in the corrected regular expression as much as possible, thereby improving readability.

[0094] Furthermore, the synthesis unit 132 calculates the priority according to the number of characters in the template, thereby reducing the number of characters in the corrected regular expression as much as possible, thereby improving readability.

[0095] The synthesis unit 132 calculates a priority according to the degree of deviation between the template and the first regular expression as character strings. This allows the corrected regular expression to be as close as possible to the regular expression before correction, thereby improving readability. Furthermore, the higher the priority, the more likely it is to be adopted as the final output in subsequent processing, thereby improving the readability of the corrected regular expression.

[0096] [System configuration, etc.] Furthermore, the components of each device shown in the figure are functional concepts and do not necessarily have to be physically configured as shown. In other words, the specific form of distribution and integration of each device is not limited to that shown, and all or part of the devices can be functionally or physically distributed or integrated in any unit depending on various loads, usage conditions, etc. Furthermore, all or any part of the processing functions performed by each device can be realized by a CPU (Central Processing Unit) and a program analyzed and executed by the CPU, or can be realized as hardware using wired logic. Note that the program may be executed not only by the CPU but also by other processors such as a GPU.

[0097] Furthermore, among the processes described in this embodiment, all or part of the processes described as being performed automatically can be performed manually, or all or part of the processes described as being performed manually can be performed automatically using a known method.In addition, the information including the processing procedures, control procedures, specific names, various data and parameters shown in the above documents and drawings can be changed as desired unless otherwise specified.

[0098] [program] In one embodiment, the correction device 10 can be implemented by installing a correction program that executes the above correction process as package software or online software on a desired computer. For example, by executing the above correction program on an information processing device, the information processing device can function as the correction device 10. The information processing device referred to here includes desktop and notebook personal computers. In addition, the information processing device also includes mobile communication terminals such as smartphones, mobile phones, and PHS (Personal Handyphone Systems), as well as slate terminals such as PDAs (Personal Digital Assistants).

[0099] The correction device 10 can also be implemented as a correction server device that provides a service related to the above correction process to a client terminal device used by a user. For example, the correction server device is implemented as a server device that provides a correction service that takes an uncorrected regular expression as input and outputs a corrected regular expression. In this case, the correction server device may be implemented as a web server or as a cloud that provides a service related to the above correction process through outsourcing.

[0100] 14 is a diagram showing an example of a computer that executes a modification program. The computer 1000 includes, for example, a memory 1010 and a CPU 1020. The computer 1000 also includes a hard disk drive interface 1030, a disk drive interface 1040, a serial port interface 1050, a video adapter 1060, and a network interface 1070. These components are connected by a bus 1080.

[0101] The memory 1010 includes a ROM (Read Only Memory) 1011 and a RAM (Random Access Memory) 1012. The ROM 1011 stores a boot program such as a BIOS (Basic Input Output System). The hard disk drive interface 1030 is connected to a hard disk drive 1090. The disk drive interface 1040 is connected to a disk drive 1100. A removable storage medium such as a magnetic disk or optical disk is inserted into the disk drive 1100. The serial port interface 1050 is connected to a mouse 1110 and a keyboard 1120, for example. The video adapter 1060 is connected to a display 1130, for example.

[0102] The hard disk drive 1090 stores, for example, an OS 1091, an application program 1092, a program module 1093, and program data 1094. That is, a program that defines each process of the modification device 10 is implemented as a program module 1093 in which computer-executable code is written. The program module 1093 is stored, for example, in the hard disk drive 1090. For example, a program module 1093 for executing the same process as the functional configuration of the modification device 10 is stored in the hard disk drive 1090. The hard disk drive 1090 may be replaced by an SSD (Solid State Drive).

[0103] Furthermore, setting data used in the processing of the above-described embodiment is stored as program data 1094, for example, in the memory 1010 or the hard disk drive 1090. Then, the CPU 1020 reads the program module 1093 or the program data 1094 stored in the memory 1010 or the hard disk drive 1090 into the RAM 1012 as necessary, and executes the processing of the above-described embodiment.

[0104] The program module 1093 and program data 1094 are not limited to being stored in the hard disk drive 1090, but may also be stored in, for example, a removable storage medium and read by the CPU 1020 via the disk drive 1100 or the like. Alternatively, the program module 1093 and program data 1094 may be stored in another computer connected via a network (such as a local area network (LAN) or a wide area network (WAN)). The program module 1093 and program data 1094 may then be read by the CPU 1020 from the other computer via the network interface 1070. [Explanation of symbols]

[0105] 10 Correction device 11 Interface section 12 Storage section 13 Control Unit 121 Replacement candidate syntax information 122 Cost Information 131 Generation part 132 Synthesis Section

Claims

1. a calculation unit that calculates a priority for each template in which at least a part of range characters in a first regular expression is replaced with a placeholder, in accordance with a cost of each operator of the regular expression included in the template that is determined in advance; a conversion unit that converts each of the templates in descending order of priority into a second regular expression that eliminates the vulnerability of the first regular expression; A repair device comprising:

2. a generator that generates a first set of strings that are accepted by a first regular expression and a second set of strings that are rejected by the first regular expression; 2. The correction device according to claim 1, wherein the conversion unit converts the template into the second regular expression, which is a regular expression in which the placeholder in the template is replaced with a predetermined syntax, and which accepts character strings in the first set and rejects character strings in the second set.

3. 3. The correction device according to claim 1, wherein the calculation unit calculates the priority in accordance with the number of characters in the template.

4. 3. The correction device according to claim 1, wherein the calculation unit calculates the priority in accordance with a degree of deviation between the template and the first regular expression as character strings.

5. A repair method performed by a repair device, comprising: a calculation step of calculating a priority for each template in which at least a part of range characters in a first regular expression is replaced with a placeholder, in accordance with a predetermined cost for each operator of the regular expression included in the template; a conversion step of converting each of the templates in descending order of priority into a second regular expression in which the vulnerability of the first regular expression is eliminated; A correction method comprising:

6. a calculation step of calculating a priority for each template obtained by replacing at least a part of range characters in a first regular expression with a placeholder, in accordance with a predetermined cost for each operator of the regular expression included in the template; a conversion step of converting each of the templates in descending order of priority into a second regular expression in which the vulnerability of the first regular expression is eliminated; A fix program characterized by causing a computer to execute the following.

Citation Information

Patent Citations

  • Program, information processor, and method

    JP2015028699A

  • Regular Expression Generation Based on Positive and Negative Pattern Matching Examples

    JP2021527260A

  • Modification device, modification method, and modification program

    WO2022113308A1