diff options
| -rw-r--r-- | openalias.c | 36 | ||||
| -rw-r--r-- | premake5.lua | 4 |
2 files changed, 23 insertions, 17 deletions
diff --git a/openalias.c b/openalias.c index 136578d..45bf446 100644 --- a/openalias.c +++ b/openalias.c @@ -47,39 +47,46 @@ static void normalize_ticker(char* s) { *s = (char)toupper((unsigned char)*s); } -static int is_valid_label(const char* s, size_t len) { - if (len == 0 || len > LABEL_MAX) return 0; - if (s[0] == '-' || s[len - 1] == '-') return 0; +static int is_valid_label(const char* s, size_t len) +{ + if (len == 0 || len > LABEL_MAX) + return 0; + for (size_t i = 0; i < len; i++) { - if (!(isalnum((unsigned char)s[i]) || s[i] == '-')) + unsigned char c = (unsigned char)s[i]; + + if (!isalnum(c) && c != '-') + return 0; + + if ((i == 0 || i == len - 1) && c == '-') return 0; } + return 1; } -static int is_valid_fqdn(const char* s) { +static int is_valid_fqdn(const char* s) +{ size_t len = strlen(s); - if (len < 3 || len > FQDN_MAX) return 0; + if (len < 3 || len > FQDN_MAX) + return 0; const char* label = s; - const char* p = s; - while (1) { + for (const char* p = s; ; ++p) { if (*p == '.' || *p == '\0') { - if (!is_valid_label(label, (size_t)(p - label))) + if (!is_valid_label(label, p - label)) return 0; - if (*p == '\0') break; + if (*p == '\0') + return 1; label = p + 1; } - p++; } - return 1; } static int starts_with(const char* s, const char* prefix) { return str_nicmp(s, prefix, strlen(prefix)) == 0; } - static int parse_openalias(const char* txt, openalias_record* rec, const char* filter) { @@ -108,7 +115,7 @@ static int parse_openalias(const char* txt, if (rec->address[0] == '\0') return 0; - strncpy(rec->currency, currency, STR_TICKER_MAX - 1); + snprintf(rec->currency, STR_TICKER_MAX, "%s", currency); rec->currency[STR_TICKER_MAX - 1] = '\0'; return 1; } @@ -238,4 +245,3 @@ int main(int argc, char** argv) { return EXIT_SUCCESS; } - diff --git a/premake5.lua b/premake5.lua index 161cd06..a3482c9 100644 --- a/premake5.lua +++ b/premake5.lua @@ -8,8 +8,8 @@ project "openalias" kind "ConsoleApp" language "C" targetdir "bin/%{cfg.buildcfg}" - files { "openalias.c" } + staticruntime "On" filter "system:windows" defines {"_WIN32", "_CRT_SECURE_NO_WARNINGS"} @@ -18,7 +18,7 @@ project "openalias" filter "system:linux" defines { "_POSIX_C_SOURCE=200112L" } - links { "resolv" } + links { "resolv:static" } buildoptions { "-Wall", "-Wextra" } filter "configurations:Debug" |
