Skip to content

Commit df113a5

Browse files
committed
RDKB-63834: Reject and Remove Corrupted Config Files In Persistance
Signed-off-by: Yogeswaran K <yogeswaransky@gmail.com>
1 parent d1b156b commit df113a5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

source/utils/persistence.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ T2ERROR fetchLocalConfigs(const char* path, Vector *configList)
112112
if(status == 0)
113113
{
114114
T2Info("Filename : %s Size : %ld\n", entry->d_name, (long int)filestat.st_size);
115+
// Skip empty profile files
116+
if(filestat.st_size == 0)
117+
{
118+
T2Warning("Skipping empty config file : %s\n", entry->d_name);
119+
close(fp);
120+
removeProfileFromDisk(path, entry->d_name);
121+
continue;
122+
}
115123

116124
Config *config = (Config *)malloc(sizeof(Config));
117125
memset(config, 0, sizeof(Config));
@@ -168,7 +176,13 @@ T2ERROR saveConfigToFile(const char* path, const char *profileName, const char*
168176
T2Error("Unable to write to file : %s\n", filePath);
169177
return T2ERROR_FAILURE;
170178
}
171-
fprintf(fp, "%s", configuration);
179+
if(fprintf(fp, "%s", configuration) < 0)
180+
{
181+
T2Error("Failed to write to file : %s\n", filePath);
182+
fclose(fp);
183+
removeProfileFromDisk(path, profileName);
184+
return T2ERROR_FAILURE;
185+
}
172186
if(fclose(fp) != 0)
173187
{
174188
T2Error("Unable to close file : %s\n", filePath);

0 commit comments

Comments
 (0)