Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
hggq committed Feb 16, 2024
1 parent 0ad84f0 commit cd6219d
Show file tree
Hide file tree
Showing 15 changed files with 934 additions and 919 deletions.
2 changes: 2 additions & 0 deletions conf/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ directorylist=1
index=index.html
;usehtmlcache=1
;usehtmlcachetime=3600
staticfile_cache_num=0 ;0 not cache, min 10 begin
rewrite_404=0 ;1 file 2 action url path
rewrite_404_action=index.html
method_pre=
method_after=
show_visitinfo=0
upload_max_size=16777216

[www.869869.com]
wwwpath=/Users/hzq/paozhu/www/default
http2_enable=1
Expand Down
2 changes: 1 addition & 1 deletion libs/markdown/markdown2html.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void markdown2html::process_hr()
break;
}
}
if (mdcontent[j] != 0x0A)
if (j > 0 && mdcontent[j] != 0x0A)
{
process_p();
return;
Expand Down
6 changes: 3 additions & 3 deletions vendor/httpcli/controllerparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class controllerparse
break;
}
}
if (readcontent[ij] == '"')
if (ij < readcontent.size() && readcontent[ij] == '"')
{
ij++;
std::string cppincludefilename;
Expand Down Expand Up @@ -365,7 +365,7 @@ class controllerparse
}
break;
}
if (readcontent[i] == '#')
if (i < readcontent.size() && readcontent[i] == '#')
{
for (; i < readcontent.size(); i++)
{
Expand All @@ -384,7 +384,7 @@ class controllerparse
}
break;
}
if (readcontent[i] == '#')
if (i < readcontent.size() && readcontent[i] == '#')
{
for (; i < readcontent.size(); i++)
{
Expand Down
4 changes: 2 additions & 2 deletions vendor/httpcli/modelfun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8584,7 +8584,7 @@ std::vector<mysqlconnect_t> getmysqlconfig(std::string filename)
}
}
}
if (s[i] == 0x0A)
if (i < s.size() && s[i] == 0x0A)
{
readkey = false;
// myconfig[linestr]=strval;
Expand Down Expand Up @@ -9450,7 +9450,7 @@ dbtype=mysql
}
}

if (command[0] == 'x')
if (command.size() > 0 && command[0] == 'x')
{
break;
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/httpcli/templateparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class viewtemplate
}
break;
}
if (readcontent[i] == '#')
if (i < readcontent.size() && readcontent[i] == '#')
{
for (; i < readcontent.size(); i++)
{
Expand All @@ -525,7 +525,7 @@ class viewtemplate
}
break;
}
if (readcontent[i] == '#')
if (i < readcontent.size() && readcontent[i] == '#')
{
for (; i < readcontent.size(); i++)
{
Expand Down
17 changes: 12 additions & 5 deletions vendor/httpcli/typestatement.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* @author 黄自权 huangziquan
* @date 2023-04-24
* @dest struct json reflect file
*/
#pragma once
#include <map>
#include <vector>
Expand Down Expand Up @@ -488,7 +493,7 @@ class typejsonfiles
break;
}
}
if (filecontent[offset] == '}')
if (offset < filecontent.size() && filecontent[offset] == '}')
{
offset += 1;
for (; offset < filecontent.size(); offset++)
Expand Down Expand Up @@ -827,7 +832,7 @@ class typejsonfiles
}

std::string defaultvalue;
if (linecontent[offset] == '=')
if (offset < linecontent.size() && linecontent[offset] == '=')
{
offset += 1;
for (; offset < linecontent.size(); offset++)
Expand All @@ -852,7 +857,7 @@ class typejsonfiles
}
}
temp.value = defaultvalue;
if (linecontent[offset] == ';')
if (offset < linecontent.size() && linecontent[offset] == ';')
{
offset += 1;
}
Expand Down Expand Up @@ -1032,8 +1037,10 @@ class typejsonfiles

header_content.append("\n}\n");
}

fwrite(&header_content[0], 1, header_content.size(), fp.get());
if (header_content.size() > 0)
{
fwrite(&header_content[0], 1, header_content.size(), fp.get());
}
}
std::string createjsonobj(const struct obj_reflect_type &json_reflect_data)
{
Expand Down
54 changes: 30 additions & 24 deletions vendor/httpserver/src/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::string get_gmttime(time_t inputtime)
{
curr_time = inputtime;
}
tm *timeInfo;
const tm *timeInfo;

char timestr[30] = {};
timeInfo = gmtime(&curr_time);
Expand All @@ -33,7 +33,7 @@ std::string get_gmttime(time_t inputtime)
}
std::string get_utctime(time_t inputtime)
{
time_t curr_time;
std::time_t curr_time;
if (inputtime == 0)
{
curr_time = time((time_t *)NULL);
Expand All @@ -42,7 +42,7 @@ std::string get_utctime(time_t inputtime)
{
curr_time = inputtime;
}
tm *timeInfo;
const tm *timeInfo;

char timestr[30] = {};
timeInfo = gmtime(&curr_time);
Expand Down Expand Up @@ -130,7 +130,7 @@ unsigned int timeid() { return time((time_t *)NULL); }

std::string get_date(const std::string &format, unsigned int inputtime)
{
time_t curr_time;
std::time_t curr_time;
if (inputtime == 0)
{
curr_time = time((time_t *)NULL);
Expand All @@ -139,7 +139,7 @@ std::string get_date(const std::string &format, unsigned int inputtime)
{
curr_time = inputtime;
}
tm *timeInfo;
const tm *timeInfo;
std::string temp(36, 0x00);
timeInfo = localtime(&curr_time);
strftime(temp.data(), temp.length(), format.c_str(), timeInfo);
Expand Down Expand Up @@ -233,7 +233,7 @@ unsigned int strgmttotime(const std::string &gmtstr)
default: timeInfo.tm_mon = 0;
}
i += 4;
if (i >= gmtstr.length())
if ((i + 13) > gmtstr.length())
{
return temp;
}
Expand Down Expand Up @@ -297,7 +297,7 @@ unsigned int strgmttotime(const std::string &gmtstr)
if (gmtstr[i] == 'G' && gmtstr[i + 1] == 'M' && gmtstr[i + 2] == 'T')
{
std::time_t rt = std::mktime(&timeInfo);
std::tm *tm = std::gmtime((const time_t *)&rt);
std::tm *tm = std::gmtime((const std::time_t *)&rt);
std::time_t gt = std::mktime(tm);
temp = rt + (rt - gt);
}
Expand All @@ -324,6 +324,11 @@ unsigned int strtotime(const std::string &str)
}
}

if ((i + 5) > str.length())
{
return 0;
}

tc[0] = str[i] - '0';
i++;
tc[1] = str[i] - '0';
Expand All @@ -342,12 +347,13 @@ unsigned int strtotime(const std::string &str)
{
i++;
}
if (str[i] >= '0' && str[i] <= '9')

if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[0] = str[i] - '0';
}
i++;
if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[1] = str[i] - '0';
i++;
Expand All @@ -363,7 +369,7 @@ unsigned int strtotime(const std::string &str)
datetime.tm_mon = datetime.tm_mon - 1;
}

if ((unsigned char)str[i] > 0x7F)
if (i < str.length() && (unsigned char)str[i] > 0x7F)
{
i += 3;
}
Expand All @@ -372,12 +378,12 @@ unsigned int strtotime(const std::string &str)
i++;
}

if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[0] = str[i] - '0';
}
i++;
if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[1] = str[i] - '0';
i++;
Expand All @@ -393,7 +399,7 @@ unsigned int strtotime(const std::string &str)
datetime.tm_mday = 1;
}

if ((unsigned char)str[i] > 0x7F)
if (i < str.length() && (unsigned char)str[i] > 0x7F)
{
i += 3;
}
Expand All @@ -419,13 +425,13 @@ unsigned int strtotime(const std::string &str)
}
}

if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[0] = str[i] - '0';
}
i++;

if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[1] = str[i] - '0';
i++;
Expand Down Expand Up @@ -453,12 +459,12 @@ unsigned int strtotime(const std::string &str)
else
{

if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[0] = str[i] - '0';
}
i++;
if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[1] = str[i] - '0';
i++;
Expand All @@ -469,7 +475,7 @@ unsigned int strtotime(const std::string &str)
datetime.tm_min = tc[0];
}

if ((unsigned char)str[i] > 0x7F)
if (i < str.length() && (unsigned char)str[i] > 0x7F)
{
i += 3;
}
Expand All @@ -487,12 +493,12 @@ unsigned int strtotime(const std::string &str)
else
{

if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[0] = str[i] - '0';
}
i++;
if (str[i] >= '0' && str[i] <= '9')
if (i < str.length() && str[i] >= '0' && str[i] <= '9')
{
tc[1] = str[i] - '0';
i++;
Expand All @@ -516,16 +522,16 @@ std::string get_uuid()

std::uniform_int_distribution<int> dist(0, 15);

const char *v = "0123456789abcdef";
const bool dash[] = {0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0};
static const unsigned char str[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
static const bool dash[] = {0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0};

std::string res;
for (int i = 0; i < 16; i++)
{
if (dash[i])
res += "-";
res += v[dist(rng)];
res += v[dist(rng)];
res += str[dist(rng)];
res += str[dist(rng)];
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/httpserver/src/directory_fun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ std::string displaydirectory(std::string localpath, std::string urlpath, std::st
struct directorylist_t
{
std::string filename;
long long size;
long long size = 0;
std::string time;
std::string ext;
};
Expand Down
4 changes: 4 additions & 0 deletions vendor/httpserver/src/fastcgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ asio::awaitable<void> fastcgi::co_send()
}
break;
}
if (ret >= respbody.size())
{
break;
}
}
line_header.push_back(respbody[ret]);
}
Expand Down
Loading

0 comments on commit cd6219d

Please sign in to comment.