diff options
author | Haru <haru@dotalux.com> | 2020-05-10 20:35:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-10 20:35:59 +0200 |
commit | 0d66a7243aa6e129cddea4ca09c2616354c23ffa (patch) | |
tree | 56fe416e50f56c2265d72b920efd238538ac22ab /src/char | |
parent | 944d8489f1bcca93e6b2ff06a159084f064dce12 (diff) | |
parent | 66f9a2a1bc2fd509d13729ad6bc586a3b7ad2347 (diff) | |
download | hercules-0d66a7243aa6e129cddea4ca09c2616354c23ffa.tar.gz hercules-0d66a7243aa6e129cddea4ca09c2616354c23ffa.tar.bz2 hercules-0d66a7243aa6e129cddea4ca09c2616354c23ffa.tar.xz hercules-0d66a7243aa6e129cddea4ca09c2616354c23ffa.zip |
Merge pull request #2705 from Kenpachi2k13/string_var_size
Cap string variable value length and unify corresponding SQL columns size
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/char.c | 8 | ||||
-rw-r--r-- | src/char/inter.c | 8 | ||||
-rw-r--r-- | src/char/mapif.c | 7 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/char/char.c b/src/char/char.c index 0406dbecf..c61b6107a 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2902,13 +2902,13 @@ static void char_global_accreg_to_login_add(const char *key, unsigned int index, if( val ) { char *sval = (char*)val; - len = strlen(sval)+1; + len = strlen(sval); - WFIFOB(chr->login_fd, nlen) = (unsigned char)len;/* won't be higher; the column size is 254 */ + WFIFOB(chr->login_fd, nlen) = (unsigned char)len; // Won't be higher; the column size is 255. nlen += 1; - safestrncpy(WFIFOP(chr->login_fd,nlen), sval, len); - nlen += len; + safestrncpy(WFIFOP(chr->login_fd, nlen), sval, len + 1); + nlen += len + 1; } } else { WFIFOB(chr->login_fd, nlen) = val ? 0 : 1; diff --git a/src/char/inter.c b/src/char/inter.c index 2d8d06a9c..5252b3315 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -676,13 +676,13 @@ static int inter_accreg_fromsql(int account_id, int char_id, int fd, int type) plen += 4; SQL->GetData(inter->sql_handle, 2, &data, NULL); - len = strlen(data)+1; + len = strlen(data); - WFIFOB(fd, plen) = (unsigned char)len;/* won't be higher; the column size is 254 */ + WFIFOB(fd, plen) = (unsigned char)len; // Won't be higher; the column size is 255. plen += 1; - safestrncpy(WFIFOP(fd,plen), data, len); - plen += len; + safestrncpy(WFIFOP(fd, plen), data, len + 1); + plen += len + 1; WFIFOW(fd, 14) += 1; diff --git a/src/char/mapif.c b/src/char/mapif.c index 9077afae4..f0c886586 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -2030,7 +2030,8 @@ static int mapif_parse_Registry(int fd) if (count != 0) { int cursor = 14, i; - char key[SCRIPT_VARNAME_LENGTH+1], sval[254]; + char key[SCRIPT_VARNAME_LENGTH + 1]; + char sval[SCRIPT_STRING_VAR_LENGTH + 1]; bool isLoginActive = sockt->session_is_active(chr->login_fd); if (isLoginActive) @@ -2057,8 +2058,8 @@ static int mapif_parse_Registry(int fd) /* str */ case 2: len = RFIFOB(fd, cursor); - safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); - cursor += len + 1; + safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len + 1)); + cursor += len + 2; inter->savereg(account_id, char_id, key, index, (intptr_t)sval, true); break; case 3: |