Skip to contentSkip to conversation

secilc.c: Don't fail if input file is empty

PATCH Applied Yi-Yo Chiang 2 participants 3 messages Apr 14, 2021 – Apr 19, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 secilc.c: Don't fail if input file is empty

fread(3) returns zero if |size| is zero. This confuses secilc, and causes it to fail with a "Failure reading file" error, even though there is no error.

Add a shortcut that closes and skips an input file if file size is zero.

---
 secilc/secilc.c | 6 ++++++
 1 file changed, 6 insertions(+)
secilc/secilc.c +6 -0
index 186c5a73..9c78e425 100644
@@ -268,6 +268,12 @@ int main(int argc, char *argv[])
 		}
 		file_size = filedata.st_size;
 
+		if (!file_size) {
+			fclose(file);
+			file = NULL;
+			continue;
+		}
+
 		buffer = malloc(file_size);
 		rc = fread(buffer, file_size, 1, file);
 		if (rc != 1) {
Signature · 1 line
2.31.1.295.g9ea45b61b8-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Yi-Yo Chiang

fread(3) returns zero if |size| is zero. This confuses secilc, and causes it to fail with a "Failure reading file" error, even though there is no error.

Add a shortcut that closes and skips an input file if file size is zero.

Quoted 24 lines
---
 secilc/secilc.c | 6 ++++++
 1 file changed, 6 insertions(+)
secilc/secilc.c +6 -1
index 186c5a73..9c78e425 100644
@@ -268,6 +268,12 @@ int main(int argc, char *argv[])
                }
                file_size = filedata.st_size;
 
+               if (!file_size) {
+                       fclose(file);
+                       file = NULL;
+                       continue;
+               }
+
                buffer = malloc(file_size);
                rc = fread(buffer, file_size, 1, file);
                if (rc != 1) {
--

2.31.1.295.g9ea45b61b8-goog

Applied
#2 lore raw
Quoted 7 lines · James Carter
Quoted 5 lines · Yi-Yo Chiang

fread(3) returns zero if |size| is zero. This confuses secilc, and causes it to fail with a "Failure reading file" error, even though there is no error.

Quoted 6 lines
Quoted 3 lines

Add a shortcut that closes and skips an input file if file size is zero.

Applied.
Thanks,
Jim

Quoted 24 lines
Quoted 24 lines
---
 secilc/secilc.c | 6 ++++++
 1 file changed, 6 insertions(+)
secilc/secilc.c +6 -1
index 186c5a73..9c78e425 100644
@@ -268,6 +268,12 @@ int main(int argc, char *argv[])
                }
                file_size = filedata.st_size;
 
+               if (!file_size) {
+                       fclose(file);
+                       file = NULL;
+                       continue;
+               }
+
                buffer = malloc(file_size);
                rc = fread(buffer, file_size, 1, file);
                if (rc != 1) {
--

2.31.1.295.g9ea45b61b8-goog