From 75ac0cbb4f9f532eb5cf6fdf8c62fd398bdff0c7 Mon Sep 17 00:00:00 2001 From: sagitario Date: Sun, 24 Oct 2010 09:21:52 +0000 Subject: * fixed error with nested types longer than 255 characters --- CHANGES | 3 +++ VERSION | 2 +- src/cv2pdb.cpp | 30 ++++++++++++++++-------------- src/symutil.cpp | 12 ++++++++++-- src/symutil.h | 2 ++ 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/CHANGES b/CHANGES index 4cf0904..5a2c2fb 100644 --- a/CHANGES +++ b/CHANGES @@ -128,4 +128,7 @@ Version history * fixed crash that could occur for user-defined types longer than 90 characters +2010-10-24 Version 0.18 + + * fixed error with nested types longer than 255 characters diff --git a/VERSION b/VERSION index 4b77f15..abadf6a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -VERSION = 0.17 +VERSION = 0.18 diff --git a/src/cv2pdb.cpp b/src/cv2pdb.cpp index fea4020..c02d25e 100644 --- a/src/cv2pdb.cpp +++ b/src/cv2pdb.cpp @@ -312,9 +312,11 @@ int CV2PDB::copy_leaf(unsigned char* dp, int& dpos, const unsigned char* p, int& static int copy_p2dsym(unsigned char* dp, int& dpos, const unsigned char* p, int& pos, int maxdlen) { - int len = dsym2c(p + pos + 1, p[pos], (char*) dp + dpos, maxdlen - dpos) + 1; - dpos += len; - pos += p[pos] + 1; + const BYTE* q = p + pos; + int plen = pstrlen(q); + int len = dsym2c(q, plen, (char*) dp + dpos, maxdlen - dpos); + dpos += len + 1; + pos = q - p + len; return len; } @@ -366,7 +368,7 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft else { leaf_len = numeric_leaf(&value, &fieldtype->enumerate_v1.value); - copylen = 2 + 2 + leaf_len + p[pos + 4 + leaf_len] + 1; // id,attr,value,name + copylen = 2 + 2 + leaf_len + pstrmemlen(p + pos + 4 + leaf_len); // id,attr,value,name } break; @@ -392,14 +394,14 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft else { leaf_len = numeric_leaf(&value, &fieldtype->member_v1.offset); - copylen = leaf_len + p[pos + leaf_len] + 1; // value,name + copylen = leaf_len + pstrmemlen(p + pos + leaf_len); // value,name } break; case LF_MEMBER_V2: leaf_len = numeric_leaf(&value, &fieldtype->member_v1.offset); copylen = sizeof(dfieldtype->member_v2) - sizeof(dfieldtype->member_v2.offset); - copylen += leaf_len + p[pos + copylen + leaf_len] + 1; // value,name + copylen += leaf_len + pstrmemlen(p + pos + copylen + leaf_len); // value,name break; case LF_MEMBER_V3: @@ -460,7 +462,7 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft if (v3 && dp) copy_p2dsym(dp, dpos, p, pos, maxdlen); else - copylen = fieldtype->method_v1.p_name.namelen + 1; + copylen = pstrmemlen(&fieldtype->method_v1.p_name.namelen); if(cmd == kCmdOffsetFirstVirtualMethod) if(const codeview_type* cvtype = getTypeData(fieldtype->method_v1.mlist)) @@ -476,7 +478,7 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft case LF_METHOD_V2: copylen = sizeof(dfieldtype->method_v2) - sizeof(dfieldtype->method_v2.p_name); - copylen += fieldtype->method_v2.p_name.namelen + 1; + copylen += pstrmemlen(&fieldtype->method_v2.p_name.namelen); break; case LF_METHOD_V3: @@ -496,12 +498,12 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft if (v3 && dp) copy_p2dsym(dp, dpos, p, pos, maxdlen); else - copylen = fieldtype->stmember_v1.p_name.namelen + 1; + copylen = pstrmemlen(&fieldtype->stmember_v1.p_name.namelen); break; case LF_STMEMBER_V2: copylen = sizeof(dfieldtype->stmember_v2) - sizeof(dfieldtype->stmember_v2.p_name); - copylen += fieldtype->stmember_v2.p_name.namelen + 1; + copylen += pstrmemlen(&fieldtype->stmember_v2.p_name.namelen); break; case LF_STMEMBER_V3: @@ -521,7 +523,7 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft if (v3 && dp) copy_p2dsym(dp, dpos, p, pos, maxdlen); else - copylen = fieldtype->nesttype_v1.p_name.namelen + 1; + copylen = pstrmemlen(&fieldtype->nesttype_v1.p_name.namelen); if(test_nested_type == 0 || test_nested_type == fieldtype->nesttype_v1.type) nested_types++; if(cmd == kCmdHasClassTypeEnum && p2ccmp(fieldtype->nesttype_v1.p_name, CLASSTYPEENUM_TYPE)) @@ -530,7 +532,7 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft case LF_NESTTYPE_V2: copylen = sizeof(dfieldtype->nesttype_v2) - sizeof(dfieldtype->nesttype_v2.p_name); - copylen += fieldtype->nesttype_v2.p_name.namelen + 1; + copylen += pstrmemlen(&fieldtype->nesttype_v2.p_name.namelen); if(test_nested_type == 0 || test_nested_type == fieldtype->nesttype_v1.type) nested_types++; if(cmd == kCmdHasClassTypeEnum && p2ccmp(fieldtype->nesttype_v2.p_name, CLASSTYPEENUM_TYPE)) @@ -563,10 +565,10 @@ int CV2PDB::_doFields(int cmd, codeview_reftype* dfieldlist, const codeview_reft // throw away friend function declarations, there is no v3 replacement and the debugger won't need them case LF_FRIENDFCN_V1: - pos += sizeof(fieldtype->friendfcn_v1) + fieldtype->friendfcn_v1.p_name.namelen - 1; + pos += sizeof(fieldtype->friendfcn_v1) + pstrmemlen(&fieldtype->friendfcn_v1.p_name.namelen) - 2; continue; case LF_FRIENDFCN_V2: - copylen = sizeof(fieldtype->friendfcn_v2) + fieldtype->friendfcn_v2.p_name.namelen - 1; + copylen = sizeof(fieldtype->friendfcn_v2) + pstrmemlen(&fieldtype->friendfcn_v2.p_name.namelen) - 2; continue; case LF_FRIENDCLS_V1: diff --git a/src/symutil.cpp b/src/symutil.cpp index 0c2c3ee..0331dfd 100644 --- a/src/symutil.cpp +++ b/src/symutil.cpp @@ -76,6 +76,13 @@ int pstrlen(const BYTE* &p) return len; } +int pstrmemlen(const BYTE* p) +{ + const BYTE* q = p; + int len = pstrlen(p); + return len + (p - q); +} + int dstrlen(const BYTE* &p, bool cstr) { if(cstr) @@ -198,9 +205,10 @@ int cstrcpy_v(bool v3, BYTE* d, const char* s) { int len = strlen(s); if(!v3) - *d++ = len; - else + { assert(len < 256); + *d++ = len; + } memcpy(d, s, len + 1); return len + 1; diff --git a/src/symutil.h b/src/symutil.h index 2fd483d..9d39c4d 100644 --- a/src/symutil.h +++ b/src/symutil.h @@ -13,6 +13,8 @@ struct p_string; int dsym2c(const BYTE* p, int len, char* cname, int maxclen); +int pstrmemlen(const BYTE* p); +int pstrlen(const BYTE* &p); char* p2c(const BYTE* p, int idx = 0); char* p2c(const p_string& p, int idx = 0); int p2ccpy(char* p, const BYTE* s); -- cgit v0.12