| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From b6cf29f98adce7355e8c51a6af1e338a5f94e16e Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com> |
| 3 | Date: Tue, 11 Apr 2023 15:29:59 +0200 |
| 4 | Subject: [PATCH] Ensure each label is at least one byte long |
| 5 | |
| 6 | The only allowed exception is single dot, where it should return empty |
| 7 | string. |
| 8 | |
| 9 | Fixes #454. |
| 10 | --- |
| 11 | avahi-common/domain-test.c | 14 ++++++++++++++ |
| 12 | avahi-common/domain.c | 2 +- |
| 13 | 2 files changed, 15 insertions(+), 1 deletion(-) |
| 14 | |
| 15 | --- a/avahi-common/domain-test.c |
| 16 | +++ b/avahi-common/domain-test.c |
| 17 | @@ -45,6 +45,20 @@ int main(AVAHI_GCC_UNUSED int argc, AVAH |
| 18 | printf("%s\n", s = avahi_normalize_name_strdup("fo\\\\o\\..f oo.")); |
| 19 | avahi_free(s); |
| 20 | |
| 21 | + printf("%s\n", s = avahi_normalize_name_strdup(".")); |
| 22 | + avahi_free(s); |
| 23 | + |
| 24 | + s = avahi_normalize_name_strdup(",.=.}.=.?-.}.=.?.?.}.}.?.?.?.z.?.?.}.}." |
| 25 | + "}.?.?.?.r.=.=.}.=.?.}}.}.?.?.?.zM.=.=.?.?.}.}.?.?.}.}.}" |
| 26 | + ".?.?.?.r.=.=.}.=.?.}}.}.?.?.?.zM.=.=.?.?.}.}.?.?.?.zM.?`" |
| 27 | + "?.}.}.}.?.?.?.r.=.?.}.=.?.?.}.?.?.?.}.=.?.?.}??.}.}.?.?." |
| 28 | + "?.z.?.?.}.}.}.?.?.?.r.=.=.}.=.?.}}.}.?.?.?.zM.?`?.}.}.}." |
| 29 | + "??.?.zM.?`?.}.}.}.?.?.?.r.=.?.}.=.?.?.}.?.?.?.}.=.?.?.}?" |
| 30 | + "?.}.}.?.?.?.z.?.?.}.}.}.?.?.?.r.=.=.}.=.?.}}.}.?.?.?.zM." |
| 31 | + "?`?.}.}.}.?.?.?.r.=.=.?.?`.?.?}.}.}.?.?.?.r.=.?.}.=.?.?." |
| 32 | + "}.?.?.?.}.=.?.?.}"); |
| 33 | + assert(s == NULL); |
| 34 | + |
| 35 | printf("%i\n", avahi_domain_equal("\\065aa bbb\\.\\046cc.cc\\\\.dee.fff.", "Aaa BBB\\.\\.cc.cc\\\\.dee.fff")); |
| 36 | printf("%i\n", avahi_domain_equal("A", "a")); |
| 37 | |
| 38 | --- a/avahi-common/domain.c |
| 39 | +++ b/avahi-common/domain.c |
| 40 | @@ -201,7 +201,7 @@ char *avahi_normalize_name(const char *s |
| 41 | } |
| 42 | |
| 43 | if (!empty) { |
| 44 | - if (size < 1) |
| 45 | + if (size < 2) |
| 46 | return NULL; |
| 47 | |
| 48 | *(r++) = '.'; |