Skip to content
Snippets Groups Projects
Commit 2995f851 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Bugfix and more paranoia in ini*SString() functions.

Bugfis:   Be sure to terminate value if returning deflt.
Paranoia: Terminate value if iniGetString() returns NULL

I think the only way to trigger the paranoia is to pass NULL as the
default when reading a key that's not present.
parent 129dd7db
No related branches found
No related tags found
No related merge requests found
Pipeline #5908 passed
......@@ -1020,10 +1020,11 @@ char* iniReadSString(FILE* fp, const char* section, const char* key, const char*
size_t pos;
ret = iniReadString(fp, section, key, deflt, fval);
if (ret == NULL)
if (ret == NULL) {
if (sz > 0 && value != NULL)
value[0] = 0;
return NULL;
if (ret == deflt)
return (char*)deflt;
}
if (sz < 1 || value == NULL)
return value;
for (pos = 0; ret[pos]; pos++) {
......@@ -1032,6 +1033,8 @@ char* iniReadSString(FILE* fp, const char* section, const char* key, const char*
value[pos] = ret[pos];
}
value[pos] = 0;
if (ret == deflt)
return (char*)deflt;
return value;
}
......@@ -1067,10 +1070,11 @@ char* iniGetSString(str_list_t list, const char* section, const char* key, const
size_t pos;
ret = iniGetString(list, section, key, deflt, fval);
if (ret == NULL)
if (ret == NULL) {
if (sz > 0 && value != NULL)
value[0] = 0;
return NULL;
if (ret == deflt)
return (char*)deflt;
}
if (sz < 1 || value == NULL)
return value;
for (pos = 0; ret[pos]; pos++) {
......@@ -1079,6 +1083,8 @@ char* iniGetSString(str_list_t list, const char* section, const char* key, const
value[pos] = ret[pos];
}
value[pos] = 0;
if (ret == deflt)
return (char*)deflt;
return value;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment