diff --git a/src/libckpool.c b/src/libckpool.c index 0a478649..af3633a1 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -1081,6 +1081,22 @@ int safecmp(const char *a, const char *b) return (strcmp(a, b)); } +/* Returns whether there is a case insensitive match of buf to cmd, safely + * handling NULL or zero length strings. */ +bool cmdmatch(const char *buf, const char *cmd) +{ + int cmdlen, buflen; + + if (!buf) + return false; + buflen = strlen(buf); + if (!buflen) + return false; + cmdlen = strlen(cmd); + if (buflen < cmdlen) + return false; + return !strncasecmp(buf, cmd, cmdlen); +} static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; diff --git a/src/libckpool.h b/src/libckpool.h index 08d30242..e2af60c9 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -415,6 +415,7 @@ bool _hex2bin(void *p, const void *vhexstr, size_t len, const char *file, const char *http_base64(const char *src); void b58tobin(char *b58bin, const char *b58); int safecmp(const char *a, const char *b); +bool cmdmatch(const char *buf, const char *cmd); void address_to_pubkeytxn(char *pkh, const char *addr); int ser_number(uchar *s, int32_t val);