Browse Source

Add a helper function for safely checking if a buffer matches a command

master
Con Kolivas 10 years ago
parent
commit
8dbc90fbaf
  1. 16
      src/libckpool.c
  2. 1
      src/libckpool.h

16
src/libckpool.c

@ -1081,6 +1081,22 @@ int safecmp(const char *a, const char *b)
return (strcmp(a, 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+/"; static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

1
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); char *http_base64(const char *src);
void b58tobin(char *b58bin, const char *b58); void b58tobin(char *b58bin, const char *b58);
int safecmp(const char *a, const char *b); 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); void address_to_pubkeytxn(char *pkh, const char *addr);
int ser_number(uchar *s, int32_t val); int ser_number(uchar *s, int32_t val);

Loading…
Cancel
Save