Prevent crash in gettok() and similar functions by checking for NULL
input. Return NULL instead.
This commit is contained in:
parent
2126230b64
commit
e6772f4e4e
|
|
@ -393,6 +393,9 @@ gettok(char **s)
|
||||||
int paren;
|
int paren;
|
||||||
const char *token, *token_e;
|
const char *token, *token_e;
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
paren = 0;
|
paren = 0;
|
||||||
|
|
||||||
*s = skip_ws(*s);
|
*s = skip_ws(*s);
|
||||||
|
|
@ -599,6 +602,10 @@ void findtok_noparen(char **p_str, char **p_token, char **p_token_end)
|
||||||
char *gettok_noparens(char **s)
|
char *gettok_noparens(char **s)
|
||||||
{
|
{
|
||||||
char *token, *token_e;
|
char *token, *token_e;
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
findtok_noparen(s, &token, &token_e);
|
findtok_noparen(s, &token, &token_e);
|
||||||
if (token == (char *) NULL) {
|
if (token == (char *) NULL) {
|
||||||
return (char *) NULL; /* return NULL if we come to end of line */
|
return (char *) NULL; /* return NULL if we come to end of line */
|
||||||
|
|
@ -654,6 +661,10 @@ void findtok_np(char** p_str, char** p_token, char** p_token_end)
|
||||||
char* gettok_np(char** s)
|
char* gettok_np(char** s)
|
||||||
{
|
{
|
||||||
char* token, * token_e;
|
char* token, * token_e;
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
findtok_np(s, &token, &token_e);
|
findtok_np(s, &token, &token_e);
|
||||||
if (token == (char*)NULL) {
|
if (token == (char*)NULL) {
|
||||||
return (char*)NULL; /* return NULL if we come to end of line */
|
return (char*)NULL; /* return NULL if we come to end of line */
|
||||||
|
|
@ -673,6 +684,9 @@ gettok_model(char **s)
|
||||||
char c;
|
char c;
|
||||||
const char *token, *token_e;
|
const char *token, *token_e;
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*s = skip_ws(*s);
|
*s = skip_ws(*s);
|
||||||
|
|
||||||
if (!**s)
|
if (!**s)
|
||||||
|
|
@ -706,6 +720,9 @@ gettok_instance(char **s)
|
||||||
char c;
|
char c;
|
||||||
const char *token, *token_e;
|
const char *token, *token_e;
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*s = skip_ws(*s);
|
*s = skip_ws(*s);
|
||||||
|
|
||||||
if (!**s)
|
if (!**s)
|
||||||
|
|
@ -740,6 +757,9 @@ gettok_char(char **s, char p, bool inc_p, bool nested)
|
||||||
char c;
|
char c;
|
||||||
const char *token, *token_e;
|
const char *token, *token_e;
|
||||||
|
|
||||||
|
if (!*s)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
*s = skip_ws(*s);
|
*s = skip_ws(*s);
|
||||||
|
|
||||||
if (!**s)
|
if (!**s)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue