summaryrefslogtreecommitdiff
path: root/src/analysis/scan/rule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/scan/rule.c')
-rw-r--r--src/analysis/scan/rule.c77
1 files changed, 61 insertions, 16 deletions
diff --git a/src/analysis/scan/rule.c b/src/analysis/scan/rule.c
index 05fc657..d3acbc2 100644
--- a/src/analysis/scan/rule.c
+++ b/src/analysis/scan/rule.c
@@ -370,13 +370,13 @@ void g_scan_rule_add_local_variable(GScanRule *rule, GSearchPattern *pattern)
* *
* Retour : Motif de détection retrouvé ou NULL en cas d'échec. *
* *
-* Remarques : - *
+* Remarques : La propriétée de l'instance renvoyée est partagée ! *
* *
******************************************************************************/
-GSearchPattern *g_scan_rule_get_local_variable(GScanRule *rule, const char *target)
+const GSearchPattern *g_scan_rule_get_local_variable(GScanRule *rule, const char *target)
{
- GSearchPattern *result; /* Variable à retourner */
+ const GSearchPattern *result; /* Variable à retourner */
size_t i; /* Boucle de parcours */
const char *name; /* Désignation d'un motif */
@@ -394,9 +394,6 @@ GSearchPattern *g_scan_rule_get_local_variable(GScanRule *rule, const char *targ
}
- if (result != NULL)
- g_object_ref(G_OBJECT(result));
-
return result;
}
@@ -412,13 +409,16 @@ GSearchPattern *g_scan_rule_get_local_variable(GScanRule *rule, const char *targ
* *
* Retour : Motifs de détection retrouvés ou NULL en cas d'échec. *
* *
-* Remarques : - *
+* Remarques : La propriétée des instances renvoyées est partagée ! *
* *
******************************************************************************/
-GSearchPattern **g_scan_rule_get_local_variables(GScanRule *rule, const char *target, size_t *count)
+const GSearchPattern **g_scan_rule_get_local_variables(GScanRule *rule, const char *target, size_t *count)
{
- GSearchPattern **result; /* Variables à retourner */
+ const GSearchPattern **result; /* Variables à retourner */
+ size_t target_len; /* Nbre de caractères à évaluer*/
+ size_t len_without_star; /* Taille sans masque */
+ bool need_regex; /* Traitement complexe requis */
size_t i; /* Boucle de parcours */
char *regex; /* Définition complète */
regex_t preg; /* Expression compilée */
@@ -433,20 +433,68 @@ GSearchPattern **g_scan_rule_get_local_variables(GScanRule *rule, const char *ta
if (target == NULL)
{
+ need_all_of_them:
+
*count = rule->bytes_used;
result = malloc(*count * sizeof(GSearchPattern *));
+ memcpy(result, rule->bytes_locals, *count);
+
+ }
+
+ /* Second cas de figure : identification au cas par cas */
+
+ else
+ {
+ target_len = strlen(target);
+
+ len_without_star = 0;
+
+ need_regex = false;
+
+ for (i = 0; i < target_len; i++)
+ if (target[i] == '*')
+ break;
+ else
+ len_without_star++;
+
+ for (i++; i < target_len; i++)
+ if (target[i] != '*')
+ {
+ need_regex = true;
+ goto try_harder;
+ }
+
+ if (len_without_star == 0)
+ goto need_all_of_them;
+
+ result = malloc(rule->bytes_used * sizeof(GSearchPattern *));
+
for (i = 0; i < rule->bytes_used; i++)
{
- result[i] = rule->bytes_locals[i];
- g_object_ref(G_OBJECT(result[i]));
+ name = g_search_pattern_get_name(rule->bytes_locals[i]);
+
+ if (strncmp(name, target, len_without_star) == 0)
+ {
+ result[*count] = rule->bytes_locals[i];
+ (*count)++;
+ }
+
+ }
+
+ if (*count == 0)
+ {
+ free(result);
+ result = NULL;
}
}
- /* Second cas de figure : une expression régulière est vraisemblablement de mise */
+ try_harder:
- else
+ /* Dernier cas de figure : une expression régulière est vraisemblablement de mise */
+
+ if (need_regex)
{
regex = strdup(target);
@@ -473,10 +521,7 @@ GSearchPattern **g_scan_rule_get_local_variables(GScanRule *rule, const char *ta
if (ret != REG_NOMATCH)
{
result[*count] = rule->bytes_locals[i];
- g_object_ref(G_OBJECT(result[*count]));
-
(*count)++;
-
}
}