ucode: check for errors in ftruncate() master
authorFelix Fietkau <nbd@nbd.name>
Wed, 6 Dec 2023 13:00:35 +0000 (14:00 +0100)
committerFelix Fietkau <nbd@nbd.name>
Wed, 6 Dec 2023 13:00:35 +0000 (14:00 +0100)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
lib-ucode.c

index d50fd905c716ebe2b14585194d5e079412c5b093..c2ce3b24ea0c3d9763cfa4760d334b7b9df5e04b 100644 (file)
@@ -327,7 +327,10 @@ uc_udebug_pcap_file(uc_vm_t *vm, size_t nargs)
 
        if (ucv_type(file) == UC_STRING) {
                fd = open(ucv_string_get(file), O_WRONLY | O_CREAT, 0644);
-               ftruncate(fd, 0);
+               if (ftruncate(fd, 0) < 0) {
+                       close(fd);
+                       return NULL;
+               }
        } else if (!file)
                fd = STDOUT_FILENO;