projects
/
freeradius.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixes from clang / scan-build
[freeradius.git]
/
src
/
lib
/
token.c
diff --git
a/src/lib/token.c
b/src/lib/token.c
index
c57a5a0
..
47fb90a
100644
(file)
--- a/
src/lib/token.c
+++ b/
src/lib/token.c
@@
-29,7
+29,7
@@
RCSID("$Id$")
#include <ctype.h>
#include <ctype.h>
-static const
LRAD
_NAME_NUMBER tokens[] = {
+static const
FR
_NAME_NUMBER tokens[] = {
{ "=~", T_OP_REG_EQ, }, /* order is important! */
{ "!~", T_OP_REG_NE, },
{ "{", T_LCBRACE, },
{ "=~", T_OP_REG_EQ, }, /* order is important! */
{ "!~", T_OP_REG_NE, },
{ "{", T_LCBRACE, },
@@
-69,15
+69,15
@@
static const LRAD_NAME_NUMBER tokens[] = {
* At end-of-line, buf[0] is set to '\0'.
* Returns 0 or special token value.
*/
* At end-of-line, buf[0] is set to '\0'.
* Returns 0 or special token value.
*/
-static
LRAD_TOKEN getthing(
char **ptr, char *buf, int buflen, int tok,
-
const LRAD
_NAME_NUMBER *tokenlist)
+static
FR_TOKEN getthing(const
char **ptr, char *buf, int buflen, int tok,
+
const FR
_NAME_NUMBER *tokenlist)
{
{
- char
*s, *p
;
-
int quote
;
- int
escape
;
+ char
*s
;
+
const char *p
;
+ int
quote, end = 0
;
unsigned int x;
unsigned int x;
- const
LRAD
_NAME_NUMBER*t;
-
LRAD
_TOKEN rcode;
+ const
FR
_NAME_NUMBER*t;
+
FR
_TOKEN rcode;
buf[0] = 0;
buf[0] = 0;
@@
-101,7
+101,7
@@
static LRAD_TOKEN getthing(char **ptr, char *buf, int buflen, int tok,
while (isspace((int) *p))
p++;
*ptr = p;
while (isspace((int) *p))
p++;
*ptr = p;
- return (
LRAD
_TOKEN) t->number;
+ return (
FR
_TOKEN) t->number;
}
}
}
}
@@
-111,10
+111,10
@@
static LRAD_TOKEN getthing(char **ptr, char *buf, int buflen, int tok,
(*p == '\'') ||
(*p == '`')) {
quote = *p;
(*p == '\'') ||
(*p == '`')) {
quote = *p;
+ end = 0;
p++;
}
s = buf;
p++;
}
s = buf;
- escape = 0;
while (*p && buflen-- > 1) {
if (quote && (*p == '\\')) {
while (*p && buflen-- > 1) {
if (quote && (*p == '\\')) {
@@
-147,6
+147,7
@@
static LRAD_TOKEN getthing(char **ptr, char *buf, int buflen, int tok,
continue;
}
if (quote && (*p == quote)) {
continue;
}
if (quote && (*p == quote)) {
+ end = 1;
p++;
break;
}
p++;
break;
}
@@
-165,6
+166,11
@@
static LRAD_TOKEN getthing(char **ptr, char *buf, int buflen, int tok,
}
*s++ = 0;
}
*s++ = 0;
+ if (quote && !end) {
+ fr_strerror_printf("Unterminated string");
+ return T_OP_INVALID;
+ }
+
/* Skip whitespace again. */
while (*p && isspace((int) *p))
p++;
/* Skip whitespace again. */
while (*p && isspace((int) *p))
p++;
@@
-196,7
+202,7
@@
static LRAD_TOKEN getthing(char **ptr, char *buf, int buflen, int tok,
* Read a "word" - this means we don't honor
* tokens as delimiters.
*/
* Read a "word" - this means we don't honor
* tokens as delimiters.
*/
-int getword(char **ptr, char *buf, int buflen)
+int getword(c
onst c
har **ptr, char *buf, int buflen)
{
return getthing(ptr, buf, buflen, 0, tokens) == T_EOL ? 0 : 1;
}
{
return getthing(ptr, buf, buflen, 0, tokens) == T_EOL ? 0 : 1;
}
@@
-205,9
+211,9
@@
int getword(char **ptr, char *buf, int buflen)
* Read a bare "word" - this means we don't honor
* tokens as delimiters.
*/
* Read a bare "word" - this means we don't honor
* tokens as delimiters.
*/
-int getbareword(char **ptr, char *buf, int buflen)
+int getbareword(c
onst c
har **ptr, char *buf, int buflen)
{
{
-
LRAD
_TOKEN token;
+
FR
_TOKEN token;
token = getthing(ptr, buf, buflen, 0, NULL);
if (token != T_BARE_WORD) {
token = getthing(ptr, buf, buflen, 0, NULL);
if (token != T_BARE_WORD) {
@@
-220,7
+226,7
@@
int getbareword(char **ptr, char *buf, int buflen)
/*
* Read the next word, use tokens as delimiters.
*/
/*
* Read the next word, use tokens as delimiters.
*/
-
LRAD_TOKEN gettoken(
char **ptr, char *buf, int buflen)
+
FR_TOKEN gettoken(const
char **ptr, char *buf, int buflen)
{
return getthing(ptr, buf, buflen, 1, tokens);
}
{
return getthing(ptr, buf, buflen, 1, tokens);
}
@@
-228,9
+234,13
@@
LRAD_TOKEN gettoken(char **ptr, char *buf, int buflen)
/*
* Expect a string.
*/
/*
* Expect a string.
*/
-
LRAD_TOKEN getstring(
char **ptr, char *buf, int buflen)
+
FR_TOKEN getstring(const
char **ptr, char *buf, int buflen)
{
{
- char *p = *ptr;
+ const char *p;
+
+ if (!ptr || !*ptr || !buf) return T_OP_INVALID;
+
+ p = *ptr;
while (p && (isspace((int)*p))) p++;
while (p && (isspace((int)*p))) p++;
@@
-246,9
+256,9
@@
LRAD_TOKEN getstring(char **ptr, char *buf, int buflen)
/*
* Convert a string to an integer
*/
/*
* Convert a string to an integer
*/
-int
lrad_str2int(const LRAD
_NAME_NUMBER *table, const char *name, int def)
+int
fr_str2int(const FR
_NAME_NUMBER *table, const char *name, int def)
{
{
- const
LRAD
_NAME_NUMBER *this;
+ const
FR
_NAME_NUMBER *this;
for (this = table; this->name != NULL; this++) {
if (strcasecmp(this->name, name) == 0) {
for (this = table; this->name != NULL; this++) {
if (strcasecmp(this->name, name) == 0) {
@@
-262,10
+272,10
@@
int lrad_str2int(const LRAD_NAME_NUMBER *table, const char *name, int def)
/*
* Convert an integer to a string.
*/
/*
* Convert an integer to a string.
*/
-const char *
lrad_int2str(const LRAD
_NAME_NUMBER *table, int number,
+const char *
fr_int2str(const FR
_NAME_NUMBER *table, int number,
const char *def)
{
const char *def)
{
- const
LRAD
_NAME_NUMBER *this;
+ const
FR
_NAME_NUMBER *this;
for (this = table; this->name != NULL; this++) {
if (this->number == number) {
for (this = table; this->name != NULL; this++) {
if (this->number == number) {