mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-08 06:31:50 +00:00
Fix garbage from list-bundles
The directory reading routines do not promise that the entries remain valid whilst the directory is open. In particular if the directory is more than 4k (one stdio buffer) in size then the names will be invalid. Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
This commit is contained in:
committed by
Matthew Johnson
parent
9200cb88dc
commit
e441c38462
+10
-4
@@ -932,21 +932,27 @@ int list_local_bundles()
|
||||
(strcmp(ent->d_name, "..") == 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bundles = list_append_data(bundles, ent->d_name);
|
||||
/* Need to dup the strings as the directory
|
||||
* may be bigger than the size of the I/O buffer */
|
||||
char * name = strdup(ent->d_name);
|
||||
if (!name) {
|
||||
abort();
|
||||
}
|
||||
bundles = list_append_data(bundles, name);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
item = bundles = list_sort(bundles, lex_sort);
|
||||
|
||||
while (item) {
|
||||
printf("%s\n", (char *)item->data);
|
||||
free(item->data);
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
list_free_list(bundles);
|
||||
|
||||
/* closedir only after we use the strings from readdir. */
|
||||
closedir(dir);
|
||||
free_string(&path);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user