SCP: Fix potential infinite recursion for internal ctype routines
This commit is contained in:
parent
727cd8e217
commit
964195dd78
2 changed files with 36 additions and 25 deletions
47
scp.c
47
scp.c
|
@ -214,7 +214,9 @@
|
||||||
|
|
||||||
/* Macros and data structures */
|
/* Macros and data structures */
|
||||||
|
|
||||||
#define NOT_MUX_USING_CODE /* sim_tmxr library provider or agnostic */
|
#define NOT_MUX_USING_CODE /* sim_tmxr library provider or agnostic */
|
||||||
|
|
||||||
|
#define IN_SCP_C 1 /* Include from scp.c */
|
||||||
|
|
||||||
#include "sim_defs.h"
|
#include "sim_defs.h"
|
||||||
#include "sim_rev.h"
|
#include "sim_rev.h"
|
||||||
|
@ -7936,7 +7938,7 @@ while ((*iptr != 0) &&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sim_islower (*iptr) && uc)
|
if (sim_islower (*iptr) && uc)
|
||||||
*optr = (char)toupper (*iptr);
|
*optr = (char)sim_toupper (*iptr);
|
||||||
else *optr = *iptr;
|
else *optr = *iptr;
|
||||||
iptr++; optr++;
|
iptr++; optr++;
|
||||||
}
|
}
|
||||||
|
@ -7993,7 +7995,7 @@ return cptr;
|
||||||
|
|
||||||
int sim_isspace (int c)
|
int sim_isspace (int c)
|
||||||
{
|
{
|
||||||
return ((c > 0) && (c < 128)) ? 0 : isspace (c);
|
return ((c < 0) || (c >= 128)) ? 0 : isspace (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_islower (int c)
|
int sim_islower (int c)
|
||||||
|
@ -8018,27 +8020,27 @@ return ((c >= 'A') && (c <= 'Z')) ? ((c - 'A') + 'a') : c;
|
||||||
|
|
||||||
int sim_isalpha (int c)
|
int sim_isalpha (int c)
|
||||||
{
|
{
|
||||||
return ((c > 0) && (c < 128)) ? 0 : isalpha (c);
|
return ((c < 0) || (c >= 128)) ? 0 : isalpha (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_isprint (int c)
|
int sim_isprint (int c)
|
||||||
{
|
{
|
||||||
return ((c > 0) && (c < 128)) ? 0 : isprint (c);
|
return ((c < 0) || (c >= 128)) ? 0 : isprint (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_isdigit (int c)
|
int sim_isdigit (int c)
|
||||||
{
|
{
|
||||||
return ((c > 0) && (c < 128)) ? 0 : isdigit (c);
|
return ((c < 0) || (c >= 128)) ? 0 : isdigit (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_isgraph (int c)
|
int sim_isgraph (int c)
|
||||||
{
|
{
|
||||||
return ((c > 0) && (c < 128)) ? 0 : isgraph (c);
|
return ((c < 0) || (c >= 128)) ? 0 : isgraph (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sim_isalnum (int c)
|
int sim_isalnum (int c)
|
||||||
{
|
{
|
||||||
return ((c > 0) && (c < 128)) ? 0 : isalnum (c);
|
return ((c < 0) || (c >= 128)) ? 0 : isalnum (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* strncasecmp() is not available on all platforms */
|
/* strncasecmp() is not available on all platforms */
|
||||||
|
@ -8050,10 +8052,8 @@ unsigned char s1, s2;
|
||||||
for (i=0; i<len; i++) {
|
for (i=0; i<len; i++) {
|
||||||
s1 = (unsigned char)string1[i];
|
s1 = (unsigned char)string1[i];
|
||||||
s2 = (unsigned char)string2[i];
|
s2 = (unsigned char)string2[i];
|
||||||
if (sim_islower (s1))
|
s1 = (unsigned char)sim_toupper (s1);
|
||||||
s1 = (unsigned char)toupper (s1);
|
s2 = (unsigned char)sim_toupper (s2);
|
||||||
if (sim_islower (s2))
|
|
||||||
s2 = (unsigned char)toupper (s2);
|
|
||||||
if (s1 < s2)
|
if (s1 < s2)
|
||||||
return -1;
|
return -1;
|
||||||
if (s1 > s2)
|
if (s1 > s2)
|
||||||
|
@ -8073,10 +8073,8 @@ unsigned char s1, s2;
|
||||||
while (1) {
|
while (1) {
|
||||||
s1 = (unsigned char)string1[i];
|
s1 = (unsigned char)string1[i];
|
||||||
s2 = (unsigned char)string2[i];
|
s2 = (unsigned char)string2[i];
|
||||||
if (sim_islower (s1))
|
s1 = (unsigned char)sim_toupper (s1);
|
||||||
s1 = (unsigned char)toupper (s1);
|
s2 = (unsigned char)sim_toupper (s2);
|
||||||
if (sim_islower (s2))
|
|
||||||
s2 = (unsigned char)toupper (s2);
|
|
||||||
if (s1 == s2) {
|
if (s1 == s2) {
|
||||||
if (s1 == 0)
|
if (s1 == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8389,12 +8387,12 @@ while (iptr[1]) { /* Skip trailing quote */
|
||||||
|
|
||||||
++iptr;
|
++iptr;
|
||||||
*optr = 0;
|
*optr = 0;
|
||||||
c = strchr (hex_digits, toupper(*iptr));
|
c = strchr (hex_digits, sim_toupper(*iptr));
|
||||||
if (c) {
|
if (c) {
|
||||||
*optr = ((*optr)<<4) + (uint8)(c-hex_digits);
|
*optr = ((*optr)<<4) + (uint8)(c-hex_digits);
|
||||||
++iptr;
|
++iptr;
|
||||||
}
|
}
|
||||||
c = strchr (hex_digits, toupper(*iptr));
|
c = strchr (hex_digits, sim_toupper(*iptr));
|
||||||
if (c) {
|
if (c) {
|
||||||
*optr = ((*optr)<<4) + (uint8)(c-hex_digits);
|
*optr = ((*optr)<<4) + (uint8)(c-hex_digits);
|
||||||
++iptr;
|
++iptr;
|
||||||
|
@ -8778,7 +8776,7 @@ if (sim_isdigit(cptr[1])) {
|
||||||
for (cptr++; (sim_isspace (*cptr) == 0) && (*cptr != 0); cptr++) {
|
for (cptr++; (sim_isspace (*cptr) == 0) && (*cptr != 0); cptr++) {
|
||||||
if (sim_isalpha (*cptr) == 0)
|
if (sim_isalpha (*cptr) == 0)
|
||||||
return SW_ERROR;
|
return SW_ERROR;
|
||||||
*sw = *sw | SWMASK (toupper (*cptr));
|
*sw = *sw | SWMASK (sim_toupper (*cptr));
|
||||||
}
|
}
|
||||||
return SW_BITMASK;
|
return SW_BITMASK;
|
||||||
}
|
}
|
||||||
|
@ -8956,7 +8954,7 @@ if (pptr) { /* any? */
|
||||||
*fptr != 0; /* others: stop at null */
|
*fptr != 0; /* others: stop at null */
|
||||||
#endif
|
#endif
|
||||||
fptr++, eptr++) {
|
fptr++, eptr++) {
|
||||||
if (toupper (*fptr) != toupper (*eptr))
|
if (sim_toupper (*fptr) != sim_toupper (*eptr))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (*eptr != 0) /* ext exhausted? */
|
if (*eptr != 0) /* ext exhausted? */
|
||||||
|
@ -9221,8 +9219,7 @@ while (sim_isspace (*inptr)) /* bypass white space */
|
||||||
val = 0;
|
val = 0;
|
||||||
nodigit = 1;
|
nodigit = 1;
|
||||||
for (c = *inptr; sim_isalnum(c); c = *++inptr) { /* loop through char */
|
for (c = *inptr; sim_isalnum(c); c = *++inptr) { /* loop through char */
|
||||||
if (sim_islower (c))
|
c = sim_toupper (c);
|
||||||
c = toupper (c);
|
|
||||||
if (sim_isdigit (c)) /* digit? */
|
if (sim_isdigit (c)) /* digit? */
|
||||||
digit = c - (uint32) '0';
|
digit = c - (uint32) '0';
|
||||||
else if (radix <= 10) /* stop if not expected */
|
else if (radix <= 10) /* stop if not expected */
|
||||||
|
@ -11787,7 +11784,7 @@ for (hblock = astrings; (htext = *hblock) != NULL; hblock++) {
|
||||||
while (n > vsnum) /* Get arg pointer if not cached */
|
while (n > vsnum) /* Get arg pointer if not cached */
|
||||||
vstrings[vsnum++] = va_arg (ap, char *);
|
vstrings[vsnum++] = va_arg (ap, char *);
|
||||||
end = vstrings[n-1]; /* Check for True */
|
end = vstrings[n-1]; /* Check for True */
|
||||||
if (!end || !(toupper (*end) == 'T' || *end == '1')) {
|
if (!end || !(sim_toupper (*end) == 'T' || *end == '1')) {
|
||||||
excluded = TRUE; /* False, skip topic this time */
|
excluded = TRUE; /* False, skip topic this time */
|
||||||
if (*htext)
|
if (*htext)
|
||||||
htext++;
|
htext++;
|
||||||
|
@ -12016,7 +12013,7 @@ for (i = 0; i < topic->kids; i++) {
|
||||||
*cptr++ = '_';
|
*cptr++ = '_';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*cptr = (char)toupper (*cptr);
|
*cptr = (char)sim_toupper (*cptr);
|
||||||
cptr++;
|
cptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12088,7 +12085,7 @@ else
|
||||||
p = sim_name;
|
p = sim_name;
|
||||||
top.title = (char *) malloc (strlen (p) + ((flag & SCP_HELP_ATTACH)? sizeof (attach_help)-1: 0) +1);
|
top.title = (char *) malloc (strlen (p) + ((flag & SCP_HELP_ATTACH)? sizeof (attach_help)-1: 0) +1);
|
||||||
for (i = 0; p[i]; i++ )
|
for (i = 0; p[i]; i++ )
|
||||||
top.title[i] = (char)toupper (p[i]);
|
top.title[i] = (char)sim_toupper (p[i]);
|
||||||
top.title[i] = '\0';
|
top.title[i] = '\0';
|
||||||
if (flag & SCP_HELP_ATTACH)
|
if (flag & SCP_HELP_ATTACH)
|
||||||
strcpy (top.title+i, attach_help);
|
strcpy (top.title+i, attach_help);
|
||||||
|
|
14
scp.h
14
scp.h
|
@ -153,37 +153,51 @@ int sim_isspace (int c);
|
||||||
#ifdef isspace
|
#ifdef isspace
|
||||||
#undef isspace
|
#undef isspace
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define isspace(chr) sim_isspace (chr)
|
#define isspace(chr) sim_isspace (chr)
|
||||||
|
#endif
|
||||||
int sim_islower (int c);
|
int sim_islower (int c);
|
||||||
#ifdef islower
|
#ifdef islower
|
||||||
#undef islower
|
#undef islower
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define islower(chr) sim_islower (chr)
|
#define islower(chr) sim_islower (chr)
|
||||||
|
#endif
|
||||||
int sim_isalpha (int c);
|
int sim_isalpha (int c);
|
||||||
#ifdef isalpha
|
#ifdef isalpha
|
||||||
#undef isalpha
|
#undef isalpha
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define isalpha(chr) sim_isalpha (chr)
|
#define isalpha(chr) sim_isalpha (chr)
|
||||||
|
#endif
|
||||||
int sim_isprint (int c);
|
int sim_isprint (int c);
|
||||||
#ifdef isprint
|
#ifdef isprint
|
||||||
#undef isprint
|
#undef isprint
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define isprint(chr) sim_isprint (chr)
|
#define isprint(chr) sim_isprint (chr)
|
||||||
|
#endif
|
||||||
int sim_isdigit (int c);
|
int sim_isdigit (int c);
|
||||||
#ifdef isdigit
|
#ifdef isdigit
|
||||||
#undef isdigit
|
#undef isdigit
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define isdigit(chr) sim_isdigit (chr)
|
#define isdigit(chr) sim_isdigit (chr)
|
||||||
|
#endif
|
||||||
int sim_isgraph (int c);
|
int sim_isgraph (int c);
|
||||||
#ifdef isgraph
|
#ifdef isgraph
|
||||||
#undef isgraph
|
#undef isgraph
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define isgraph(chr) sim_isgraph (chr)
|
#define isgraph(chr) sim_isgraph (chr)
|
||||||
|
#endif
|
||||||
int sim_isalnum (int c);
|
int sim_isalnum (int c);
|
||||||
#ifdef isalnum
|
#ifdef isalnum
|
||||||
#undef isalnum
|
#undef isalnum
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IN_SCP_C
|
||||||
#define isalnum(chr) sim_isalnum (chr)
|
#define isalnum(chr) sim_isalnum (chr)
|
||||||
|
#endif
|
||||||
int sim_toupper (int c);
|
int sim_toupper (int c);
|
||||||
int sim_tolower (int c);
|
int sim_tolower (int c);
|
||||||
#ifdef toupper
|
#ifdef toupper
|
||||||
|
|
Loading…
Add table
Reference in a new issue