Skip to content

Commit

Permalink
Fix corrupted INI file cause application crash (issue #144).
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 30, 2019
1 parent 92ad725 commit febf552
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
32 changes: 20 additions & 12 deletions metapath/src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ BOOL IniSectionParseArray(IniSection *section, LPWSTR lpCachedIniSection) {
do {
IniKeyValueNode *node = &section->nodeList[count];
LPWSTR v = StrChr(p, L'=');
*v++ = L'\0';
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
if (v != NULL) {
*v++ = L'\0';
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
} else {
p = StrDup(p) + 1;
}
} while (*p && count < capacity);

section->count = count;
Expand All @@ -99,13 +103,17 @@ BOOL IniSectionParse(IniSection *section, LPWSTR lpCachedIniSection) {
do {
IniKeyValueNode *node = &section->nodeList[count];
LPWSTR v = StrChr(p, L'=');
*v++ = L'\0';
const UINT keyLen = (UINT)(v - p - 1);
node->hash = keyLen | (p[0] << 8) | (p[1] << 16);
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
if (v != NULL) {
*v++ = L'\0';
const UINT keyLen = (UINT)(v - p - 1);
node->hash = keyLen | (p[0] << 8) | (p[1] << 16);
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
} else {
p = StrEnd(p) + 1;
}
} while (*p && count < capacity);

section->count = count;
Expand Down
32 changes: 20 additions & 12 deletions src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ BOOL IniSectionParseArray(IniSection *section, LPWSTR lpCachedIniSection) {
do {
IniKeyValueNode *node = &section->nodeList[count];
LPWSTR v = StrChr(p, L'=');
*v++ = L'\0';
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
if (v != NULL) {
*v++ = L'\0';
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
} else {
p = StrEnd(p) + 1;
}
} while (*p && count < capacity);

section->count = count;
Expand All @@ -126,13 +130,17 @@ BOOL IniSectionParse(IniSection *section, LPWSTR lpCachedIniSection) {
do {
IniKeyValueNode *node = &section->nodeList[count];
LPWSTR v = StrChr(p, L'=');
*v++ = L'\0';
const UINT keyLen = (UINT)(v - p - 1);
node->hash = keyLen | (p[0] << 8) | (p[1] << 16);
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
if (v != NULL) {
*v++ = L'\0';
const UINT keyLen = (UINT)(v - p - 1);
node->hash = keyLen | (p[0] << 8) | (p[1] << 16);
node->key = p;
node->value = v;
++count;
p = StrEnd(v) + 1;
} else {
p = StrEnd(p) + 1;
}
} while (*p && count < capacity);

section->count = count;
Expand Down

0 comments on commit febf552

Please sign in to comment.