fixed a potential in set_err_with_syserr in hcl-s.c

This commit is contained in:
hyung-hwan 2018-03-14 14:54:10 +00:00
parent de534fed83
commit b7434aa976
2 changed files with 15 additions and 17 deletions

View File

@ -244,7 +244,7 @@ struct hcl_server_t
hcl_errnum_t errnum; hcl_errnum_t errnum;
struct struct
{ {
hcl_ooch_t buf[2048]; hcl_ooch_t buf[HCL_ERRMSG_CAPA];
hcl_oow_t len; hcl_oow_t len;
} errmsg; } errmsg;
int stopreq; int stopreq;
@ -1748,13 +1748,12 @@ static void set_err_with_syserr (hcl_server_t* server, int syserr, const char* b
va_end (ap); va_end (ap);
#if defined(HCL_OOCH_IS_BCH) #if defined(HCL_OOCH_IS_BCH)
hcl->errmsg.len += hcl_copybcstr (&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, b_dash); hcl->errmsg.len += hcl_copybcstr(&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, b_dash);
hcl->errmsg.len += hcl_copybcstr (&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, hcl->errmsg.tmpbuf.bch); hcl->errmsg.len += hcl_copybcstr(&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, hcl->errmsg.tmpbuf.bch);
#else #else
hcl->errmsg.len += hcl_copyucstr (&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, u_dash); hcl->errmsg.len += hcl_copyucstr(&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, u_dash);
tmplen = hcl_countbcstr(hcl->errmsg.tmpbuf.bch);
tmplen2 = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len; tmplen2 = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len;
hcl_convbtouchars (hcl, hcl->errmsg.tmpbuf.bch, &tmplen, &hcl->errmsg.buf[hcl->errmsg.len], &tmplen2); hcl_convbtoucstr (hcl, hcl->errmsg.tmpbuf.bch, &tmplen, &hcl->errmsg.buf[hcl->errmsg.len], &tmplen2);
hcl->errmsg.len += tmplen2; /* ignore conversion errors */ hcl->errmsg.len += tmplen2; /* ignore conversion errors */
#endif #endif
} }
@ -1769,17 +1768,14 @@ static void set_err_with_syserr (hcl_server_t* server, int syserr, const char* b
va_end (ap); va_end (ap);
#if defined(HCL_OOCH_IS_BCH) #if defined(HCL_OOCH_IS_BCH)
hcl->errmsg.len += hcl_copybcstr (&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, b_dash); hcl->errmsg.len += hcl_copybcstr(&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, b_dash);
tmplen = hcl_countucstr(hcl->errmsg.tmpbuf.uch);
tmplen2 = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len; tmplen2 = HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len;
hcl_convutobchars (hcl, hcl->errmsg.tmpbuf.uch, &tmplen, &hcl->errmsg.buf[hcl->errmsg.len], &tmplen2); hcl_convutobcstr (hcl, hcl->errmsg.tmpbuf.uch, &tmplen, &hcl->errmsg.buf[hcl->errmsg.len], &tmplen2);
hcl->errmsg.len += tmplen2; /* ignore conversion errors */ hcl->errmsg.len += tmplen2; /* ignore conversion errors */
#else #else
hcl->errmsg.len += hcl_copyucstr (&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, u_dash); hcl->errmsg.len += hcl_copyucstr(&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, u_dash);
hcl->errmsg.len += hcl_copyucstr (&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, hcl->errmsg.tmpbuf.uch); hcl->errmsg.len += hcl_copyucstr(&hcl->errmsg.buf[hcl->errmsg.len], HCL_COUNTOF(hcl->errmsg.buf) - hcl->errmsg.len, hcl->errmsg.tmpbuf.uch);
#endif #endif
} }
server->errnum = errnum; server->errnum = errnum;

View File

@ -992,6 +992,8 @@ struct hcl_synerr_t
typedef struct hcl_compiler_t hcl_compiler_t; typedef struct hcl_compiler_t hcl_compiler_t;
#endif #endif
#define HCL_ERRMSG_CAPA 2048
struct hcl_t struct hcl_t
{ {
hcl_mmgr_t* mmgr; hcl_mmgr_t* mmgr;
@ -1002,11 +1004,11 @@ struct hcl_t
{ {
union union
{ {
hcl_ooch_t ooch[2048]; hcl_ooch_t ooch[HCL_ERRMSG_CAPA];
hcl_bch_t bch[2048]; hcl_bch_t bch[HCL_ERRMSG_CAPA];
hcl_uch_t uch[2048]; hcl_uch_t uch[HCL_ERRMSG_CAPA];
} tmpbuf; } tmpbuf;
hcl_ooch_t buf[2048]; hcl_ooch_t buf[HCL_ERRMSG_CAPA];
hcl_oow_t len; hcl_oow_t len;
} errmsg; } errmsg;
int shuterr; int shuterr;