- check the length of the select result value if the run_select returned 0
to catch the empty string (res->s might be NULL if res->len==0)
- check whether the /0 put behind the string is really neccessary
STR_STATIC_INITed str is already delimited, write behind causes segfault
... | ... |
@@ -665,7 +665,7 @@ inline static int comp_str(int op, str* left, int rtype, union exp_op* r, struct |
665 | 665 |
* janakj: AVPs are zero terminated too so this is not problem either |
666 | 666 |
*/ |
667 | 667 |
backup=left->s[left->len]; |
668 |
- left->s[left->len]='\0'; |
|
668 |
+ if (backup) left->s[left->len]='\0'; |
|
669 | 669 |
if (rtype == AVP_ST || rtype == SELECT_ST) { |
670 | 670 |
/* For AVPs we need to compile the RE on the fly */ |
671 | 671 |
re=(regex_t*)pkg_malloc(sizeof(regex_t)); |
... | ... |
@@ -686,7 +686,7 @@ inline static int comp_str(int op, str* left, int rtype, union exp_op* r, struct |
686 | 686 |
} else { |
687 | 687 |
ret=(regexec(r->re, left->s, 0, 0, 0)==0); |
688 | 688 |
} |
689 |
- left->s[left->len] = backup; |
|
689 |
+ if (backup) left->s[left->len] = backup; |
|
690 | 690 |
break; |
691 | 691 |
default: |
692 | 692 |
LOG(L_CRIT, "BUG: comp_str: unknown op %d\n", op); |
... | ... |
@@ -814,9 +814,10 @@ inline static int comp_select(int op, select_t* sel, int rtype, union exp_op* r, |
814 | 814 |
ret = run_select(&val, sel, msg); |
815 | 815 |
if (ret < 0) return -1; |
816 | 816 |
if (ret > 0) return 0; |
817 |
+ if (val.len==0) return 0; |
|
817 | 818 |
|
818 | 819 |
switch(op) { |
819 |
- case NO_OP: return (val.len>0); |
|
820 |
+ case NO_OP: return 1; |
|
820 | 821 |
case BINOR_OP: |
821 | 822 |
case BINAND_OP: |
822 | 823 |
ERR("Binary operators cannot be used with string selects\n"); |