HTMLv: safe string copy

git-svn-id: svn://kolibrios.org@3128 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2012-12-19 17:37:24 +00:00
parent 11b018514c
commit 2793582a69
7 changed files with 180 additions and 143 deletions

View File

@ -24,10 +24,10 @@ struct TWebBrowser {
void DrawScroller();
};
TWebBrowser WB1;
byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text,
link, ignor_text, li_tab, first_line_drawed, cur_encoding;
link, ignor_text, li_tab, first_line_drawed, cur_encoding;
TWebBrowser WB1;
dword text_colors[300],

View File

@ -31,11 +31,11 @@ void UrlsHistory::AddUrl() //
history_current/=2;
for (i=0; i<history_current; i++;)
{
strcpy(#history_list[i].Item, #history_list[MAX_HISTORY_NUM-i].Item);
strlcpy(#history_list[i].Item, #history_list[MAX_HISTORY_NUM-i].Item, sizeof(history_list[0].Item));
}
}
history_current++;
strcpy(#history_list[history_current].Item, #URL);
strlcpy(#history_list[history_current].Item, #URL, sizeof(history_list[0].Item));
history_num=history_current;
}
@ -45,7 +45,7 @@ byte UrlsHistory::GoBack()
if (history_current<=1) return 0;
history_current--;
strcpy(#URL, #history_list[history_current].Item);
strlcpy(#URL, #history_list[history_current].Item, sizeof(URL));
return 1;
}
@ -54,6 +54,6 @@ byte UrlsHistory::GoForward()
{
if (history_current==history_num) return 0;
history_current++;
strcpy(#URL, #history_list[history_current].Item);
strlcpy(#URL, #history_list[history_current].Item, sizeof(URL));
return 1;
}

View File

@ -15,19 +15,13 @@ unsigned int GetNextParam()
if (kavichki)
{
i=strrchr(#tagparam, kavichki);
if (i>sizeof(options))
strcpy(#options, #tagparam + sizeof(options));
else
strcpy(#options, #tagparam + i);
strlcpy(#options, #tagparam + i, sizeof(options));
}
else
{
WHILE((i > 0) && (tagparam[i] <>'=')) i--; //i=strrchr(#tagparam, '=')+1;
i++;
if (i>sizeof(options))
strcpy(#options, #tagparam + sizeof(options));
else
strcpy(#options, #tagparam + i);
strlcpy(#options, #tagparam + i, sizeof(options));
WHILE (options[0] == ' ') strcpy(#options, #options+1);
}
@ -38,13 +32,7 @@ unsigned int GetNextParam()
IF (tagparam[i] == '=') //äåğçêàÿ çàãëóøêà
tagparam[i + 1] = 0x00;
}
if (i>sizeof(parametr))
strcpy(#parametr, #tagparam + sizeof(parametr));
else
strcpy(#parametr, #tagparam + i + 1);
strlcpy(#parametr, #tagparam + i + 1, sizeof(parametr));
tagparam[i] = 0x00;
return 1;
}

View File

@ -325,6 +325,7 @@ inline fastcall int PlaySpeaker( ESI)
inline fastcall void debug( EDX)
{
$push eax
$push ebx
$push ecx
$mov eax, 63
@ -343,13 +344,18 @@ DONE:
$int 0x40
$pop ecx
$pop ebx
$pop eax
}
inline fastcall void debugch( ECX)
{
$push eax
$push ebx
$mov eax,63
$mov ebx,1
$int 0x40
$pop ebx
$pop eax
}
//------------------------------------------------------------------------------

View File

@ -16,14 +16,18 @@ char aIconv[6] = "iconv\0";
dword ChangeCharset(dword from_chs, to_chs, conv_buf)
{
dword cd, in_len, out_len, new_buf;
debug (from_chs);
debug (to_chs);
iconv_open stdcall (from_chs, to_chs); //CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5
if (EAX==-1) { debug("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5"); return 0; }
if (EAX==-1)
{
debug (from_chs);
debug (to_chs);
debug("iconv: wrong charset,\nuse only CP866, CP1251, CP1252, KOI8-RU, UTF-8, ISO8859-5");
return 0;
}
cd = EAX;
in_len = out_len = strlen(conv_buf);
in_len = out_len = strlen(conv_buf)+1;
new_buf = mem_Alloc(in_len);
iconv stdcall (cd, #conv_buf, #in_len, #new_buf, #out_len);
cd = EAX;
@ -36,6 +40,9 @@ dword ChangeCharset(dword from_chs, to_chs, conv_buf)
debug("out_len");
debug(itoa(out_len));
new_buf = 0;
return 0;
}
return new_buf;
strcpy(conv_buf, new_buf);
free(new_buf);
return conv_buf;
}

View File

@ -89,6 +89,8 @@ L2:
}
}
#define mem_Alloc malloc
#define mem_ReAlloc realloc
#define mem_Free free
@ -123,18 +125,6 @@ L2:
}
}
:void fastcall memcpy( EDI, ESI, ECX)
{
asm {
MOV EDX, ECX
SHR ECX, 2
REP MOVSD
MOV ECX, EDX
AND ECX, 3
REP MOVSB
}
}
:void fastcall memsetd( EDI, ECX, EAX)
{
asm {

View File

@ -13,7 +13,7 @@
// strttl( EDX)
// strtok( ESI)
// strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings
//chrnum(dword searchin, char symbol) --- count of symbol in string
// strnumb(dword searchin, startstr, endstr) --- get number between strings
//------------------------------------------------------------------------------
inline fastcall signed int strcmp( ESI, EDI)
@ -71,6 +71,21 @@ L2:
}
inline fastcall int strlcpy(dword ESI, EDI, EBX)
{
EDX=0;
do {
DSBYTE[ESI]=DSBYTE[EDI];
ESI++;
EDI++;
EDX++;
if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;}
} while(DSBYTE[EDI-1]!='\0');
return 0;
}
inline fastcall strcat( EDI, ESI)
{
asm {
@ -99,6 +114,119 @@ inline fastcall strcat( EDI, ESI)
}
}
inline fastcall signed int strchr( ESI,BL)
{
int jj=0;
do{
jj++;
$lodsb
IF(AL==BL) return jj;
} while(AL!=0);
return 0;
}
inline fastcall signed int strrchr( ESI,BL)
{
int jj=0, last=0;
do{
jj++;
$lodsb
IF(AL==BL) last=jj;
} while(AL!=0);
return last;
}
int chrnum(dword searchin, char symbol)
{
int num = 0;
while(DSBYTE[searchin])
{
if (DSBYTE[searchin] == symbol) num++;
searchin++;
}
return num;
}
inline fastcall dword strstr( EBX, EDX)
{
asm {
MOV EDI, EDX
XOR ECX, ECX
XOR EAX, EAX
DEC ECX
REPNE SCASB
NOT ECX
DEC ECX
JE LS2
MOV ESI, ECX
XOR ECX, ECX
MOV EDI, EBX
DEC ECX
REPNE SCASB
NOT ECX
SUB ECX, ESI
JBE LS2
MOV EDI, EBX
LEA EBX, DSDWORD[ ESI-1]
LS1: MOV ESI, EDX
LODSB
REPNE SCASB
JNE LS2
MOV EAX, ECX
PUSH EDI
MOV ECX, EBX
REPE CMPSB
POP EDI
MOV ECX, EAX
JNE LS1
LEA EAX, DSDWORD[ EDI-1]
JMP SHORT LS3
LS2: XOR EAX, EAX
LS3:
}
}
dword strstri(dword searchin, usestr_s)
{
dword usestr_e = usestr_s;
char si, ue;
while(DSBYTE[searchin])
{
si = DSBYTE[searchin];
ue = DSBYTE[usestr_e];
if (si>='A') && (si<='Z') si +=32;
if (ue>='A') && (ue<='Z') ue +=32;
if (si == ue) usestr_e++; else usestr_e = usestr_s;
searchin++;
if (DSBYTE[usestr_e]=='\0') return searchin;
}
return 0;
}
void strcpyb(dword searchin, copyin, startstr, endstr)
{
dword startp, endp;
startp = strstr(searchin, startstr) + strlen(startstr);
endp = strstr(startp, endstr);
if (startp==endp) return;
do
{
DSBYTE[copyin] = DSBYTE[startp];
copyin++;
startp++;
}
while (startp<endp);
DSBYTE[copyin] = '\0';
}
/*void strcat(char *to, char *from) //òîæå ðàáîòàåò
{
while(*to) to++;
@ -147,45 +275,28 @@ F3:
}
inline fastcall dword atoi( EDI)
{
$push ebx
$push esi
ESI=EDI;
IF(DSBYTE[ESI]=='-')ESI++;
while (DSBYTE[ESI]==' ') ESI++;
if (DSBYTE[ESI]=='-') ESI++;
EAX=0;
BH=AL;
do{
BL=DSBYTE[ESI]-'0';
EAX=EAX*10+EBX;
while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9')
{
$xor ebx, ebx
EBX = DSBYTE[ESI]-'0';
EAX *= 10;
EAX += EBX;
ESI++;
}while(DSBYTE[ESI]>='0');
IF(DSBYTE[EDI]=='-') -EAX;
}
IF (DSBYTE[EDI]=='-') -EAX;
$pop esi
$pop ebx
}
inline fastcall signed int strchr( ESI,BL)
{
int jj=0;
do{
jj++;
$lodsb
IF(AL==BL) return jj;
} while(AL!=0);
return 0;
}
inline fastcall signed int strrchr( ESI,BL)
{
int jj=0, last=0;
do{
jj++;
$lodsb
IF(AL==BL) last=jj;
} while(AL!=0);
return last;
}
inline fastcall strupr( ESI)
{
@ -225,78 +336,13 @@ inline fastcall strttl( EDX)
}while(AL!=0);
}
inline fastcall dword strstr( EBX, EDX)
void debugi(dword d_int)
{
asm {
MOV EDI, EDX
XOR ECX, ECX
XOR EAX, EAX
DEC ECX
REPNE SCASB
NOT ECX
DEC ECX
JE LS2
MOV ESI, ECX
XOR ECX, ECX
MOV EDI, EBX
DEC ECX
REPNE SCASB
NOT ECX
SUB ECX, ESI
JBE LS2
MOV EDI, EBX
LEA EBX, DSDWORD[ ESI-1]
LS1: MOV ESI, EDX
LODSB
REPNE SCASB
JNE LS2
MOV EAX, ECX
PUSH EDI
MOV ECX, EBX
REPE CMPSB
POP EDI
MOV ECX, EAX
JNE LS1
LEA EAX, DSDWORD[ EDI-1]
JMP SHORT LS3
LS2: XOR EAX, EAX
LS3:
}
char tmpch[11];
strcpy(#tmpch, itoa(d_int));
debug(#tmpch);
}
//
void strcpyb(dword searchin, copyin, startstr, endstr)
{
dword startp, endp;
startp = strstr(searchin, startstr) + strlen(startstr);
endp = strstr(startp, endstr);
if (startp==endp) return;
do
{
DSBYTE[copyin] = DSBYTE[startp];
copyin++;
startp++;
}
while (startp<endp);
DSBYTE[copyin] = '\0';
}
int chrnum(dword searchin, char symbol)
{
int num = 0;
while(DSBYTE[searchin])
{
if (DSBYTE[searchin] == symbol) num++;
searchin++;
}
return num;
}
/* strtok( LPSTR dest, src, divs);
src - óêàçàòåëü íà èñõîäíóþ ñòðîêó èëè ðåçóëüòàò ïðåäûäóùåãî âûçîâà
dest - óêàçàòåëü íà áóôåð, êóäà áóäåò ñêîïèðîâàíî ñëîâî