Skip to contentSkip to conversation

Do not disable _FORTIFY_SOURCE

PATCH In review Kirill A. Shutemov 5 participants 30 messages Dec 20, 2009 – Dec 22, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/18 Do not disable _FORTIFY_SOURCE

Let's fix code instead!

---
 configure |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
configure +0 -1
index d815c7a..17f3d42 100755
@@ -97,7 +97,6 @@ CFLAGS="-g $CFLAGS"
 QEMU_CFLAGS="-Wall -Wundef -Wendif-labels -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
-QEMU_CFLAGS="-U_FORTIFY_SOURCE $QEMU_CFLAGS"
 QEMU_CFLAGS="-I. -I\$(SRC_PATH) $QEMU_CFLAGS"
 LDFLAGS="-g $LDFLAGS"
 
Signature · 1 line
1.6.5.6
#1 lore raw

PATCH 2/18 block.c: fix warning with _FORTIFY_SOURCE

CC block.o
cc1: warnings being treated as errors
block.c: In function 'bdrv_open2':
block.c:400: error: ignoring return value of 'realpath', declared with attribute warn_unused_result

---
 block.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
block.c +2 -2
index 3f3496e..30ae2b1 100644
@@ -396,8 +396,8 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
         if (is_protocol)
             snprintf(backing_filename, sizeof(backing_filename),
                      "%s", filename);
-        else
-            realpath(filename, backing_filename);
+        else if (!realpath(filename, backing_filename))
+            return -errno;
 
         bdrv_qcow2 = bdrv_find_format("qcow2");
         options = parse_option_parameters("", bdrv_qcow2->create_options, NULL);
Signature · 1 line
1.6.5.6
#2 lore raw

PATCH 3/18 posix-aio-compat.c: fix warning with _FORTIFY_SOURCE

CC posix-aio-compat.o
cc1: warnings being treated as errors
posix-aio-compat.c: In function 'aio_signal_handler':
posix-aio-compat.c:505: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [posix-aio-compat.o] Error 1

---
 posix-aio-compat.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
posix-aio-compat.c +2 -1
index dc14f53..555e263 100644
@@ -502,7 +502,8 @@ static void aio_signal_handler(int signum)
     if (posix_aio_state) {
         char byte = 0;
 
-        write(posix_aio_state->wfd, &byte, sizeof(byte));
+        if (write(posix_aio_state->wfd, &byte, sizeof(byte)) != sizeof(byte))
+            die("write()");
     }
 
     qemu_service_io();
Signature · 1 line
1.6.5.6
#3 lore raw

PATCH 4/18 block/cow.c: fix warnings with _FORTIFY_SOURCE

CC block/cow.o
cc1: warnings being treated as errors
block/cow.c: In function 'cow_create':
block/cow.c:251: error: ignoring return value of 'write', declared with attribute warn_unused_result block/cow.c:253: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result
make: *** [block/cow.o] Error 1

---
 block/cow.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
block/cow.c +16 -3
index a70854e..1132614 100644
@@ -209,6 +209,7 @@ static int cow_create(const char *filename, QEMUOptionParameter *options)
     struct stat st;
     int64_t image_sectors = 0;
     const char *image_filename = NULL;
+    int ret;
 
     /* Read out options */
     while (options && options->name) {
@@ -248,11 +249,23 @@ static int cow_create(const char *filename, QEMUOptionParameter *options)
     }
     cow_header.sectorsize = cpu_to_be32(512);
     cow_header.size = cpu_to_be64(image_sectors * 512);
-    write(cow_fd, &cow_header, sizeof(cow_header));
+    ret = write(cow_fd, &cow_header, sizeof(cow_header));
+    if (ret != sizeof(cow_header)) {
+        ret = -errno;
+        goto exit;
+    }
+
     /* resize to include at least all the bitmap */
-    ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3));
+    ret = ftruncate(cow_fd, sizeof(cow_header) + ((image_sectors + 7) >> 3));
+    if (ret) {
+        ret = -errno;
+        goto exit;
+    }
+
+    ret = 0;
+exit:
     close(cow_fd);
-    return 0;
+    return ret;
 }
 
 static void cow_flush(BlockDriverState *bs)
Signature · 1 line
1.6.5.6
#4 lore raw

PATCH 5/18 block/qcow.c: fix warnings with _FORTIFY_SOURCE

CC block/qcow.o
cc1: warnings being treated as errors
block/qcow.c: In function 'qcow_create':
block/qcow.c:804: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow.c:806: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow.c:811: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [block/qcow.o] Error 1

---
 block/qcow.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)
block/qcow.c +22 -4
index 7fc85ae..db5a0e2 100644
@@ -750,6 +750,7 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
     int64_t total_size = 0;
     const char *backing_file = NULL;
     int flags = 0;
+    int ret;
 
     /* Read out options */
     while (options && options->name) {
@@ -801,17 +802,34 @@ static int qcow_create(const char *filename, QEMUOptionParameter *options)
     }
 
     /* write all the data */
-    write(fd, &header, sizeof(header));
+    ret = write(fd, &header, sizeof(header));
+    if (ret != sizeof(header)) {
+        ret = -errno;
+        goto exit;
+    }
+
     if (backing_file) {
-        write(fd, backing_file, backing_filename_len);
+        ret = write(fd, backing_file, backing_filename_len);
+        if (ret != backing_filename_len) {
+            ret = -errno;
+            goto exit;
+        }
+
     }
     lseek(fd, header_size, SEEK_SET);
     tmp = 0;
     for(i = 0;i < l1_size; i++) {
-        write(fd, &tmp, sizeof(tmp));
+        ret = write(fd, &tmp, sizeof(tmp));
+        if (ret != sizeof(tmp)) {
+            ret = -errno;
+            goto exit;
+        }
     }
+
+    ret = 0;
+exit:
     close(fd);
-    return 0;
+    return ret;
 }
 
 static int qcow_make_empty(BlockDriverState *bs)
Signature · 1 line
1.6.5.6
#5 lore raw

PATCH 6/18 block/vmdk.o: fix warnings with _FORTIFY_SOURCE

CC block/vmdk.o
cc1: warnings being treated as errors
block/vmdk.c: In function 'vmdk_snapshot_create':
block/vmdk.c:236: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result block/vmdk.c: In function 'vmdk_create':
block/vmdk.c:775: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:776: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:778: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result block/vmdk.c:784: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:790: error: ignoring return value of 'write', declared with attribute warn_unused_result block/vmdk.c:807: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [block/vmdk.o] Error 1

---
 block/vmdk.c |   50 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 40 insertions(+), 10 deletions(-)
block/vmdk.c +40 -10
index 4e48622..38e6c62 100644
@@ -233,7 +233,8 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
     memset(&header, 0, sizeof(header));
     memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC
 
-    ftruncate(snp_fd, header.grain_offset << 9);
+    if (ftruncate(snp_fd, header.grain_offset << 9))
+        goto fail;
     /* the descriptor offset = 0x200 */
     if (lseek(p_fd, 0x200, SEEK_SET) == -1)
         goto fail;
@@ -716,6 +717,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
     int64_t total_size = 0;
     const char *backing_file = NULL;
     int flags = 0;
+    int ret;
 
     // Read out options
     while (options && options->name) {
@@ -772,22 +774,44 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
     header.check_bytes[3] = 0xa;
 
     /* write all the data */
-    write(fd, &magic, sizeof(magic));
-    write(fd, &header, sizeof(header));
+    ret = write(fd, &magic, sizeof(magic));
+    if (ret != sizeof(magic)) {
+        ret = -errno;
+        goto exit;
+    }
+    ret = write(fd, &header, sizeof(header));
+    if (ret != sizeof(header)) {
+        ret = -errno;
+        goto exit;
+    }
 
-    ftruncate(fd, header.grain_offset << 9);
+    ret = ftruncate(fd, header.grain_offset << 9);
+    if (ret < 0) {
+        ret = -errno;
+        goto exit;
+    }
 
     /* write grain directory */
     lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET);
     for (i = 0, tmp = header.rgd_offset + gd_size;
-         i < gt_count; i++, tmp += gt_size)
-        write(fd, &tmp, sizeof(tmp));
+         i < gt_count; i++, tmp += gt_size) {
+        ret = write(fd, &tmp, sizeof(tmp));
+        if (ret != sizeof(tmp)) {
+            ret = -errno;
+            goto exit;
+        }
+    }
 
     /* write backup grain directory */
     lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET);
     for (i = 0, tmp = header.gd_offset + gd_size;
-         i < gt_count; i++, tmp += gt_size)
-        write(fd, &tmp, sizeof(tmp));
+         i < gt_count; i++, tmp += gt_size) {
+        ret = write(fd, &tmp, sizeof(tmp));
+        if (ret != sizeof(tmp)) {
+            ret = -errno;
+            goto exit;
+        }
+    }
 
     /* compose the descriptor */
     real_filename = filename;
@@ -804,10 +828,16 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
 
     /* write the descriptor */
     lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET);
-    write(fd, desc, strlen(desc));
+    ret = write(fd, desc, strlen(desc));
+    if (ret != strlen(desc)) {
+        ret = -errno;
+        goto exit;
+    }
 
+    ret = 0;
+exit:
     close(fd);
-    return 0;
+    return ret;
 }
 
 static void vmdk_close(BlockDriverState *bs)
Signature · 1 line
1.6.5.6
#6 lore raw

PATCH 7/18 block/bochs.c: fix warning with _FORTIFY_SOURCE

CC block/bochs.o
cc1: warnings being treated as errors
block/bochs.c: In function 'seek_to_sector':
block/bochs.c:202: error: ignoring return value of 'read', declared with attribute warn_unused_result
make: *** [block/bochs.o] Error 1

---
 block/bochs.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
block/bochs.c +2 -1
index bac81c4..f6a18f2 100644
@@ -199,7 +199,8 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
     // read in bitmap for current extent
     lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET);
 
-    read(s->fd, &bitmap_entry, 1);
+    if (read(s->fd, &bitmap_entry, 1) != 1)
+        return -1;
 
     if (!((bitmap_entry >> (extent_offset % 8)) & 1))
     {
Signature · 1 line
1.6.5.6
#7 lore raw

PATCH 8/18 block/vvfat.c: fix warnings with _FORTIFY_SOURCE

CC block/vvfat.o
cc1: warnings being treated as errors
block/vvfat.c: In function 'commit_one_file':
block/vvfat.c:2259: error: ignoring return value of 'ftruncate', declared with attribute warn_unused_result
make: *** [block/vvfat.o] Error 1
CC block/vvfat.o
In file included from /usr/include/stdio.h:912,

                 from ./qemu-common.h:19,
                 from block/vvfat.c:27:

In function 'snprintf',
inlined from 'init_directories' at block/vvfat.c:871,
inlined from 'vvfat_open' at block/vvfat.c:1068:
/usr/include/bits/stdio2.h:65: error: call to __builtin___snprintf_chk will always overflow destination buffer
make: *** [block/vvfat.o] Error 1

---
 block/vvfat.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
block/vvfat.c +3 -2
index 063f731..7b6a405 100644
@@ -868,7 +868,8 @@ static int init_directories(BDRVVVFATState* s,
     {
 	direntry_t* entry=array_get_next(&(s->directory));
 	entry->attributes=0x28; /* archive | volume label */
-	snprintf((char*)entry->name,11,"QEMU VVFAT");
+	snprintf((char*)entry->name,8,"QEMU VV");
+	snprintf((char*)entry->extension,3,"FAT");
     }
 
     /* Now build FAT, and write back information into directory */
@@ -2256,7 +2257,7 @@ static int commit_one_file(BDRVVVFATState* s,
 	c = c1;
     }
 
-    ftruncate(fd, size);
+    assert(!ftruncate(fd, size));
     close(fd);
 
     return commit_mappings(s, first_cluster, dir_index);
Signature · 1 line
1.6.5.6
#8 lore raw

PATCH 9/18 block/qcow2.c: fix warnings with _FORTIFY_SOURCE

CC block/qcow2.o
cc1: warnings being treated as errors
block/qcow2.c: In function 'qcow_create2':
block/qcow2.c:829: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:838: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:839: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:841: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:844: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:849: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:852: error: ignoring return value of 'write', declared with attribute warn_unused_result block/qcow2.c:855: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [block/qcow2.o] Error 1

---
 block/qcow2.c |   54 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 10 deletions(-)
block/qcow2.c +44 -10
index 984264b..70287f2 100644
@@ -743,7 +743,7 @@ static int qcow_create2(const char *filename, int64_t total_size,
     uint64_t tmp, offset;
     QCowCreateState s1, *s = &s1;
     QCowExtension ext_bf = {0, 0};
-
+    int ret;
 
     memset(s, 0, sizeof(*s));
 
@@ -826,7 +826,11 @@ static int qcow_create2(const char *filename, int64_t total_size,
         ref_clusters * s->cluster_size);
 
     /* write all the data */
-    write(fd, &header, sizeof(header));
+    ret = write(fd, &header, sizeof(header));
+    if (ret != sizeof(header)) {
+        ret = -errno;
+        goto exit;
+    }
     if (backing_file) {
         if (backing_format_len) {
             char zero[16];
@@ -835,25 +839,55 @@ static int qcow_create2(const char *filename, int64_t total_size,
             memset(zero, 0, sizeof(zero));
             cpu_to_be32s(&ext_bf.magic);
             cpu_to_be32s(&ext_bf.len);
-            write(fd, &ext_bf, sizeof(ext_bf));
-            write(fd, backing_format, backing_format_len);
+            ret = write(fd, &ext_bf, sizeof(ext_bf));
+            if (ret != sizeof(ext_bf)) {
+                ret = -errno;
+                goto exit;
+            }
+            ret = write(fd, backing_format, backing_format_len);
+            if (ret != backing_format_len) {
+                ret = -errno;
+                goto exit;
+            }
             if (padding > 0) {
-                write(fd, zero, padding);
+                ret = write(fd, zero, padding);
+                if (ret != padding) {
+                    ret = -errno;
+                    goto exit;
+                }
             }
         }
-        write(fd, backing_file, backing_filename_len);
+        ret = write(fd, backing_file, backing_filename_len);
+        if (ret != backing_filename_len) {
+            ret = -errno;
+            goto exit;
+        }
     }
     lseek(fd, s->l1_table_offset, SEEK_SET);
     tmp = 0;
     for(i = 0;i < l1_size; i++) {
-        write(fd, &tmp, sizeof(tmp));
+        ret = write(fd, &tmp, sizeof(tmp));
+        if (ret != sizeof(tmp)) {
+            ret = -errno;
+            goto exit;
+        }
     }
     lseek(fd, s->refcount_table_offset, SEEK_SET);
-    write(fd, s->refcount_table, s->cluster_size);
+    ret = write(fd, s->refcount_table, s->cluster_size);
+    if (ret != s->cluster_size) {
+        ret = -errno;
+        goto exit;
+    }
 
     lseek(fd, s->refcount_block_offset, SEEK_SET);
-    write(fd, s->refcount_block, ref_clusters * s->cluster_size);
+    ret = write(fd, s->refcount_block, ref_clusters * s->cluster_size);
+    if (ret != s->cluster_size) {
+        ret = -errno;
+        goto exit;
+    }
 
+    ret = 0;
+exit:
     qemu_free(s->refcount_table);
     qemu_free(s->refcount_block);
     close(fd);
@@ -867,7 +901,7 @@ static int qcow_create2(const char *filename, int64_t total_size,
         bdrv_close(bs);
     }
 
-    return 0;
+    return ret;
 }
 
 static int qcow_create(const char *filename, QEMUOptionParameter *options)
Signature · 1 line
1.6.5.6
#9 lore raw

PATCH 10/18 net/slirp.c: fix warning with _FORTIFY_SOURCE

CC net/slirp.o
cc1: warnings being treated as errors
net/slirp.c: In function 'slirp_smb_cleanup':
net/slirp.c:470: error: ignoring return value of 'system', declared with attribute warn_unused_result
make: *** [net/slirp.o] Error 1

---
 net/slirp.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
net/slirp.c +6 -1
index 3f91c4b..1f16814 100644
@@ -464,10 +464,15 @@ int net_slirp_redir(const char *redir_str)
 static void slirp_smb_cleanup(SlirpState *s)
 {
     char cmd[128];
+    int ret;
 
     if (s->smb_dir[0] != '\0') {
         snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir);
-        system(cmd);
+        ret = system(cmd);
+        if (ret) {
+            qemu_error("'%s' failed. Error code: %d\n", cmd, ret);
+            /* abort() ? */
+        }
         s->smb_dir[0] = '\0';
     }
 }
Signature · 1 line
1.6.5.6
#10 lore raw

PATCH 11/18 usb-linux.c: fix warning with _FORTIFY_SOURCE

CC usb-linux.o
cc1: warnings being treated as errors
usb-linux.c: In function 'usb_host_read_file':
usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
make: *** [usb-linux.o] Error 1

---
 usb-linux.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
usb-linux.c +5 -2
index 88728e9..67bfa7a 100644
@@ -1201,9 +1201,12 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f
              device_file);
     f = fopen(filename, "r");
     if (f) {
-        fgets(line, line_size, f);
+        if (fgets(line, line_size, f))
+            ret = 1;
+        else
+            ret = 0;
+
         fclose(f);
-        ret = 1;
 #if 0
     } else {
         if (mon)
Signature · 1 line
1.6.5.6
#11 lore raw

PATCH 12/18 savevm.c: fix warning with _FORTIFY_SOURCE

CC savevm.o
cc1: warnings being treated as errors
savevm.c: In function 'file_put_buffer':
savevm.c:342: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result
make: *** [savevm.o] Error 1

---
 savevm.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
savevm.c +1 -2
index aefe052..829f735 100644
@@ -339,8 +339,7 @@ static int file_put_buffer(void *opaque, const uint8_t *buf,
 {
     QEMUFileStdio *s = opaque;
     fseek(s->stdio_file, pos, SEEK_SET);
-    fwrite(buf, 1, size, s->stdio_file);
-    return size;
+    return fwrite(buf, 1, size, s->stdio_file);
 }
 
 static int file_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
Signature · 1 line
1.6.5.6
#12 lore raw

PATCH 13/18 slirp/misc.c: fix warning with _FORTIFY_SOURCE

CC slirp/misc.o
cc1: warnings being treated as errors
slirp/misc.c: In function 'fork_exec':
slirp/misc.c:209: error: ignoring return value of 'write', declared with attribute warn_unused_result
make: *** [slirp/misc.o] Error 1

---
 slirp/misc.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
slirp/misc.c +2 -8
index c76ad8f..05f4fb3 100644
@@ -200,14 +200,8 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
 		execvp(argv[0], (char **)argv);
 
 		/* Ooops, failed, let's tell the user why */
-		  {
-			  char buff[256];
-
-			  snprintf(buff, sizeof(buff),
-                                   "Error: execvp of %s failed: %s\n",
-                                   argv[0], strerror(errno));
-			  write(2, buff, strlen(buff)+1);
-		  }
+        fprintf(stderr, "Error: execvp of %s failed: %s\n",
+                argv[0], strerror(errno));
 		close(0); close(1); close(2); /* XXX */
 		exit(1);
 
Signature · 1 line
1.6.5.6
#13 lore raw

PATCH 14/18 vl.c: fix warning with _FORTIFY_SOURCE

CC i386-softmmu/vl.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/vl.c: In function 'qemu_event_increment':
/usr/src/RPM/BUILD/qemu-0.11.92/vl.c:3404: error: ignoring return value of 'write', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c: In function 'main':
/usr/src/RPM/BUILD/qemu-0.11.92/vl.c:5774: error: ignoring return value of 'write', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:6064: error: ignoring return value of 'chdir', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:6083: error: ignoring return value of 'chdir', declared with attribute warn_unused_result make[1]: *** [vl.o] Error 1

---
 vl.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
vl.c +11 -4
index e606903..60a2c5e 100644
@@ -3383,7 +3383,11 @@ static void qemu_event_increment(void)
     if (io_thread_fd == -1)
         return;
 
-    write(io_thread_fd, &byte, sizeof(byte));
+    if (write(io_thread_fd, &byte, sizeof(byte)) != sizeof(byte)){
+        fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
+                strerror(errno));
+        exit (1);
+    }
 }
 
 static void qemu_event_read(void *opaque)
@@ -5767,7 +5771,8 @@ int main(int argc, char **argv, char **envp)
 #ifndef _WIN32
         if (daemonize) {
             uint8_t status = 1;
-            write(fds[1], &status, 1);
+            if (write(fds[1], &status, 1) != 1)
+                perror("write()");
         } else
 #endif
             fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
@@ -6064,7 +6069,8 @@ int main(int argc, char **argv, char **envp)
 	if (len != 1)
 	    exit(1);
 
-	chdir("/");
+	if (chdir("/"))
+        exit(1);
 	TFR(fd = qemu_open("/dev/null", O_RDWR));
 	if (fd == -1)
 	    exit(1);
@@ -6083,7 +6089,8 @@ int main(int argc, char **argv, char **envp)
             fprintf(stderr, "chroot failed\n");
             exit(1);
         }
-        chdir("/");
+        if (chdir("/"))
+            exit(1);
     }
 
     if (run_as) {
Signature · 1 line
1.6.5.6
#14 lore raw

PATCH 15/18 monitor.c: fix warnings with _FORTIFY_SOURCE

CC i386-softmmu/monitor.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c: In function 'do_memory_save':
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c:1318: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/monitor.c: In function 'do_physical_memory_save':
/usr/src/RPM/BUILD/qemu-0.11.92/monitor.c:1345: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result make[1]: *** [monitor.o] Error 1

---
 monitor.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
monitor.c +10 -2
index c0dc48e..54c7323 100644
@@ -1320,10 +1320,14 @@ static void do_memory_save(Monitor *mon, const QDict *qdict, QObject **ret_data)
         if (l > size)
             l = size;
         cpu_memory_rw_debug(env, addr, buf, l, 0);
-        fwrite(buf, 1, l, f);
+        if (fwrite(buf, 1, l, f) != l) {
+            monitor_printf(mon, "fwrite() failed\n");
+            goto exit;
+        }
         addr += l;
         size -= l;
     }
+exit:
     fclose(f);
 }
 
@@ -1347,11 +1351,15 @@ static void do_physical_memory_save(Monitor *mon, const QDict *qdict,
         if (l > size)
             l = size;
         cpu_physical_memory_rw(addr, buf, l, 0);
-        fwrite(buf, 1, l, f);
+        if (fwrite(buf, 1, l, f) != l) {
+            monitor_printf(mon, "fwrite() failed\n");
+            goto exit;
+        }
         fflush(f);
         addr += l;
         size -= l;
     }
+exit:
     fclose(f);
 }
 
Signature · 1 line
1.6.5.6
#15 lore raw

PATCH 16/18 hw/pc.c: fix warnings with _FORTIFY_SOURCE

CC i386-softmmu/pc.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c: In function 'load_multiboot':
/usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c:614: error: ignoring return value of 'fread', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c: In function 'load_linux':
/usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c:888: error: ignoring return value of 'fread', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c:889: error: ignoring return value of 'fread', declared with attribute warn_unused_result make[1]: *** [pc.o] Error 1

---
 hw/pc.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
hw/pc.c +12 -3
index db7d58e..83f8dd0 100644
@@ -613,7 +613,10 @@ static int load_multiboot(void *fw_cfg,
 
         mb_kernel_data = qemu_malloc(mb_kernel_size);
         fseek(f, mb_kernel_text_offset, SEEK_SET);
-        fread(mb_kernel_data, 1, mb_kernel_size, f);
+        if (fread(mb_kernel_data, 1, mb_kernel_size, f) != mb_kernel_size) {
+            fprintf(stderr, "fread() failed\n");
+            exit(1);
+        }
         fclose(f);
     }
 
@@ -887,8 +890,14 @@ static void load_linux(void *fw_cfg,
     setup  = qemu_malloc(setup_size);
     kernel = qemu_malloc(kernel_size);
     fseek(f, 0, SEEK_SET);
-    fread(setup, 1, setup_size, f);
-    fread(kernel, 1, kernel_size, f);
+    if (fread(setup, 1, setup_size, f) != setup_size) {
+        fprintf(stderr, "fread() failed\n");
+        exit(1);
+    }
+    if (fread(kernel, 1, kernel_size, f) != kernel_size) {
+        fprintf(stderr, "fread() failed\n");
+        exit(1);
+    }
     fclose(f);
     memcpy(setup, header, MIN(sizeof(header), setup_size));
 
Signature · 1 line
1.6.5.6
#16 lore raw

PATCH 17/18 path.c fix warning with _FORTIFY_SOURCE

CC libuser/path.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/path.c: In function 'new_entry':
/usr/src/RPM/BUILD/qemu-0.11.92/path.c:49: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result make[1]: *** [path.o] Error 1

---
 path.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
path.c +4 -1
index cc9e007..0d2bf14 100644
@@ -46,7 +46,10 @@ static struct pathelem *new_entry(const char *root,
 {
     struct pathelem *new = malloc(sizeof(*new));
     new->name = strdup(name);
-    asprintf(&new->pathname, "%s/%s", root, name);
+    if (asprintf(&new->pathname, "%s/%s", root, name) == -1) {
+        printf("Cannot allocate memory\n");
+        exit(1);
+    }
     new->num_entries = 0;
     return new;
 }
Signature · 1 line
1.6.5.6
#17 lore raw

PATCH 18/18 linux-user/mmap.c: fix warnings with _FORTIFY_SOURCE

CC i386-linux-user/mmap.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c: In function 'mmap_frag':
/usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c:253: error: ignoring return value of 'pread', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c: In function 'target_mmap':
/usr/src/RPM/BUILD/qemu-0.11.92/linux-user/mmap.c:477: error: ignoring return value of 'pread', declared with attribute warn_unused_result make[1]: *** [mmap.o] Error 1

---
 linux-user/mmap.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
linux-user/mmap.c +4 -2
index 144fb7c..e496c64 100644
@@ -250,7 +250,8 @@ static int mmap_frag(abi_ulong real_start,
             mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
 
         /* read the corresponding file data */
-        pread(fd, g2h(start), end - start, offset);
+        if (pread(fd, g2h(start), end - start, offset) == -1)
+            return -errno;
 
         /* put final protection */
         if (prot_new != (prot1 | PROT_WRITE))
@@ -474,7 +475,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
                                   -1, 0);
             if (retaddr == -1)
                 goto fail;
-            pread(fd, g2h(start), len, offset);
+            if (pread(fd, g2h(start), len, offset) == -1)
+                return -errno;
             if (!(prot & PROT_WRITE)) {
                 ret = target_mprotect(start, len, prot);
                 if (ret != 0) {
Signature · 1 line
1.6.5.6
#18 lore raw

Re: [Qemu-devel] [PATCH 17/18] path.c fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 17 lines · Kirill A. Shutemov

 CC    libuser/path.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/path.c: In function 'new_entry':
/usr/src/RPM/BUILD/qemu-0.11.92/path.c:49: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result make[1]: *** [path.o] Error 1

---
 path.c |    5 ++++-

 1 files changed, 4 insertions(+), 1 deletions(-)
path.c +0 -0
index cc9e007..0d2bf14 100644
@@ -46,7 +46,10 @@ static struct pathelem *new_entry(const char *root,
  {

path.c static struct pathelem *new_entry(const char *root, · line 55

Quoted 10 lines
path.c +4 -1
     struct pathelem *new = malloc(sizeof(*new));
     new->name = strdup(name);
-    asprintf(&new->pathname, "%s/%s", root, name);
+    if (asprintf(&new->pathname, "%s/%s", root, name) == -1) {
+        printf("Cannot allocate memory\n");
+        exit(1);
+    }
     new->num_entries = 0;
     return new;
  }

Looks OK.

#19 lore raw

Re: [Qemu-devel] [PATCH 16/18] hw/pc.c: fix warnings with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 36 lines · Kirill A. Shutemov

 CC    i386-softmmu/pc.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c: In function 'load_multiboot':
/usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c:614: error: ignoring return value of 'fread', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c: In function 'load_linux':
/usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c:888: error: ignoring return value of 'fread', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/hw/pc.c:889: error: ignoring return value of 'fread', declared with attribute warn_unused_result make[1]: *** [pc.o] Error 1

---
 hw/pc.c |   15 ++++++++++++---

 1 files changed, 12 insertions(+), 3 deletions(-)
hw/pc.c +4 -3
index db7d58e..83f8dd0 100644
@@ -613,7 +613,10 @@ static int load_multiboot(void *fw_cfg,
 
         mb_kernel_data = qemu_malloc(mb_kernel_size);
         fseek(f, mb_kernel_text_offset, SEEK_SET);
-        fread(mb_kernel_data, 1, mb_kernel_size, f);
+        if (fread(mb_kernel_data, 1, mb_kernel_size, f) != mb_kernel_size) {
+            fprintf(stderr, "fread() failed\n");
+            exit(1);
+        }
         fclose(f);
     }
 
@@ -887,8 +890,14 @@ static void load_linux(void *fw_cfg,
     setup  = qemu_malloc(setup_size);
     kernel = qemu_malloc(kernel_size);
     fseek(f, 0, SEEK_SET);
-    fread(setup, 1, setup_size, f);
-    fread(kernel, 1, kernel_size, f);

hw/pc.c static void load_linux(void *fw_cfg, · line 902

Quoted 10 lines
hw/pc.c +8 -0
+    if (fread(setup, 1, setup_size, f) != setup_size) {
+        fprintf(stderr, "fread() failed\n");
+        exit(1);
+    }
+    if (fread(kernel, 1, kernel_size, f) != kernel_size) {
+        fprintf(stderr, "fread() failed\n");
+        exit(1);
+    }
     fclose(f);
     memcpy(setup, header, MIN(sizeof(header), setup_size));

Looks fine to me. If we can't read the kernel, PEBCAK.

#20 lore raw

Re: [Qemu-devel] [PATCH 14/18] vl.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 53 lines · Kirill A. Shutemov

 CC    i386-softmmu/vl.o
cc1: warnings being treated as errors
/usr/src/RPM/BUILD/qemu-0.11.92/vl.c: In function 'qemu_event_increment':
/usr/src/RPM/BUILD/qemu-0.11.92/vl.c:3404: error: ignoring return value of 'write', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c: In function 'main':
/usr/src/RPM/BUILD/qemu-0.11.92/vl.c:5774: error: ignoring return value of 'write', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:6064: error: ignoring return value of 'chdir', declared with attribute warn_unused_result /usr/src/RPM/BUILD/qemu-0.11.92/vl.c:6083: error: ignoring return value of 'chdir', declared with attribute warn_unused_result make[1]: *** [vl.o] Error 1

---
 vl.c |   15 +++++++++++----

 1 files changed, 11 insertions(+), 4 deletions(-)
vl.c +9 -3
index e606903..60a2c5e 100644
@@ -3383,7 +3383,11 @@ static void qemu_event_increment(void)
     if (io_thread_fd == -1)
         return;
 
-    write(io_thread_fd, &byte, sizeof(byte));
+    if (write(io_thread_fd, &byte, sizeof(byte)) != sizeof(byte)){
+        fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
+                strerror(errno));
+        exit (1);
+    }
  }
 
  static void qemu_event_read(void *opaque)
@@ -5767,7 +5771,8 @@ int main(int argc, char **argv, char **envp)
  #ifndef _WIN32
         if (daemonize) {
             uint8_t status = 1;
-            write(fds[1], &status, 1);
+            if (write(fds[1], &status, 1) != 1)
+                perror("write()");
         } else
  #endif
             fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
@@ -6064,7 +6069,8 @@ int main(int argc, char **argv, char **envp)
        if (len != 1)
            exit(1);
 
-       chdir("/");
+       if (chdir("/"))
+        exit(1);
        TFR(fd = qemu_open("/dev/null", O_RDWR));
        if (fd == -1)
            exit(1);

vl.c int main(int argc, char **argv, char **envp) · line 6093

Quoted 6 lines
vl.c +2 -1
@@ -6083,7 +6089,8 @@ int main(int argc, char **argv, char **envp)
             fprintf(stderr, "chroot failed\n");
             exit(1);
         }
-        chdir("/");
+        if (chdir("/"))
+            exit(1);

Can't comment much on write() parts. chdir() checks are OK, except an error message would be in order.

#21 lore raw

Re: [Qemu-devel] [PATCH 12/18] savevm.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 16 lines · Kirill A. Shutemov

 CC    savevm.o
cc1: warnings being treated as errors
savevm.c: In function 'file_put_buffer':
savevm.c:342: error: ignoring return value of 'fwrite', declared with attribute warn_unused_result
make: *** [savevm.o] Error 1

---
 savevm.c |    3 +--

 1 files changed, 1 insertions(+), 2 deletions(-)
savevm.c +0 -0
index aefe052..829f735 100644

savevm.c static int file_put_buffer(void *opaque, const uint8_t *buf, · line 342

Quoted 6 lines
savevm.c +1 -2
@@ -339,8 +339,7 @@ static int file_put_buffer(void *opaque, const uint8_t *buf,
  {
     QEMUFileStdio *s = opaque;
     fseek(s->stdio_file, pos, SEEK_SET);
-    fwrite(buf, 1, size, s->stdio_file);
-    return size;
+    return fwrite(buf, 1, size, s->stdio_file);

Looks OK.

The callers do not handle partial writes, but that's because the return value is not used correctly. They should be fixed some time.

We are truncating size_t to int, but that is OK given that the input size is also int. The interfaces should be cleaned up to use size_t/ssize_t later.

#22 lore raw

Re: [Qemu-devel] [PATCH 11/18] usb-linux.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 17 lines · Kirill A. Shutemov

 CC    usb-linux.o
cc1: warnings being treated as errors
usb-linux.c: In function 'usb_host_read_file':
usb-linux.c:1204: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
make: *** [usb-linux.o] Error 1

---
 usb-linux.c |    7 +++++--

 1 files changed, 5 insertions(+), 2 deletions(-)
usb-linux.c +0 -0
index 88728e9..67bfa7a 100644
@@ -1201,9 +1201,12 @@ static int usb_host_read_file(char *line, size_t line_size, const char *device_f
              device_file);

usb-linux.c static int usb_host_read_file(char *line, size_t line_size, const char *device_f · line 1206

Quoted 10 lines
usb-linux.c +5 -2
     f = fopen(filename, "r");
     if (f) {
-        fgets(line, line_size, f);
+        if (fgets(line, line_size, f))
+            ret = 1;
+        else
+            ret = 0;
+
         fclose(f);
-        ret = 1;

Considering the return values of fgets() and usb_host_read_file(), this patch looks OK except for the CODING_STYLE violation.

#23 lore raw

Re: [Qemu-devel] [PATCH 10/18] net/slirp.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 18 lines · Kirill A. Shutemov

 CC    net/slirp.o
cc1: warnings being treated as errors
net/slirp.c: In function 'slirp_smb_cleanup':
net/slirp.c:470: error: ignoring return value of 'system', declared with attribute warn_unused_result
make: *** [net/slirp.o] Error 1

---
 net/slirp.c |    7 ++++++-

 1 files changed, 6 insertions(+), 1 deletions(-)
net/slirp.c +0 -0
index 3f91c4b..1f16814 100644
@@ -464,10 +464,15 @@ int net_slirp_redir(const char *redir_str)
  static void slirp_smb_cleanup(SlirpState *s)
  {

net/slirp.c int net_slirp_redir(const char *redir_str) · line 474

Quoted 10 lines
net/slirp.c +5 -1
     char cmd[128];
+    int ret;
 
     if (s->smb_dir[0] != '\0') {
         snprintf(cmd, sizeof(cmd), "rm -rf %s", s->smb_dir);
-        system(cmd);
+        ret = system(cmd);
+        if (ret) {
+            qemu_error("'%s' failed. Error code: %d\n", cmd, ret);
+            /* abort() ? */

This is not correct.

- system() returns -1 on error and the command exit status otherwise, which may also be nonzero.
- the exit status should be retrieved with WEXITSTATUS() macro, or in case of error via errno.
- in no case abort() is warranted for smb cleanup.

#24 lore raw

[Qemu-devel] Re: [PATCH 09/18] block/qcow2.c: fix warnings with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov

block/qcow2.c static int qcow_create2(const char *filename, int64_t total_size, · line 887

Quoted 7 lines · Kirill A. Shutemov
     lseek(fd, s->refcount_block_offset, SEEK_SET);
block/qcow2.c +5 -1
-    write(fd, s->refcount_block, ref_clusters * s->cluster_size);
+    ret = write(fd, s->refcount_block, ref_clusters * s->cluster_size);
+    if (ret != s->cluster_size) {
+        ret = -errno;
+        goto exit;
+    }

If you have a short write you'll get an undefined errno.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#25 lore raw

Re: [Qemu-devel] [PATCH 08/18] block/vvfat.c: fix warnings with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov

Am Sonntag, 20. Dezember 2009 02:39 schrieb Kirill A. Shutemov:

Quoted 4 lines

CC block/vvfat.o
cc1: warnings being treated as errors
block/vvfat.c: In function 'commit_one_file':
block/vvfat.c:2259: error: ignoring return value of 'ftruncate', declared

with attribute warn_unused_result

Quoted 9 lines

make: *** [block/vvfat.o] Error 1
CC block/vvfat.o
In file included from /usr/include/stdio.h:912,

                 from ./qemu-common.h:19,
                 from block/vvfat.c:27:

In function 'snprintf',
inlined from 'init_directories' at block/vvfat.c:871, inlined from 'vvfat_open' at block/vvfat.c:1068:
/usr/include/bits/stdio2.h:65: error: call to __builtin___snprintf_chk will

always overflow destination buffer

Quoted 22 lines

make: *** [block/vvfat.o] Error 1

---
 block/vvfat.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
block/vvfat.c +2 -1
index 063f731..7b6a405 100644
@@ -868,7 +868,8 @@ static int init_directories(BDRVVVFATState* s,
     {
 	direntry_t* entry=array_get_next(&(s->directory));
 	entry->attributes=0x28; /* archive | volume label */
-	snprintf((char*)entry->name,11,"QEMU VVFAT");
+	snprintf((char*)entry->name,8,"QEMU VV");
+	snprintf((char*)entry->extension,3,"FAT");
     }
 
     /* Now build FAT, and write back information into directory */

block/vvfat.c static int commit_one_file(BDRVVVFATState* s, · line 2260

Quoted 5 lines
block/vvfat.c +1 -1
@@ -2256,7 +2257,7 @@ static int commit_one_file(BDRVVVFATState* s,
 	c = c1;
     }
 
-    ftruncate(fd, size);
+    assert(!ftruncate(fd, size));

Don't use expressions with side effects for assertions. If anyone compiles with NDEBUG defined, the ftruncate will be missing.

Kevin

#26 lore raw

Re: [Qemu-devel] [PATCH 07/18] block/bochs.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 16 lines · Kirill A. Shutemov

 CC    block/bochs.o
cc1: warnings being treated as errors
block/bochs.c: In function 'seek_to_sector':
block/bochs.c:202: error: ignoring return value of 'read', declared with attribute warn_unused_result
make: *** [block/bochs.o] Error 1

---
 block/bochs.c |    3 ++-

 1 files changed, 2 insertions(+), 1 deletions(-)
block/bochs.c +0 -0
index bac81c4..f6a18f2 100644

block/bochs.c static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num) · line 203

Quoted 6 lines
block/bochs.c +2 -1
@@ -199,7 +199,8 @@ static inline int seek_to_sector(BlockDriverState *bs, int64_t sector_num)
     // read in bitmap for current extent
     lseek(s->fd, bitmap_offset + (extent_offset / 8), SEEK_SET);
 
-    read(s->fd, &bitmap_entry, 1);
+    if (read(s->fd, &bitmap_entry, 1) != 1)
+        return -1;

I think a short read can't happen with 1 bytes, so this looks fine.

Though error checking is incomplete unless it is extended to lseek() calls too.

#27 lore raw

Re: [Qemu-devel] [PATCH 03/18] posix-aio-compat.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov

posix-aio-compat.c static void aio_signal_handler(int signum) · line 506

Quoted 9 lines
posix-aio-compat.c +2 -1
@@ -502,7 +502,8 @@ static void aio_signal_handler(int signum)
     if (posix_aio_state) {
         char byte = 0;
 
-  write(posix_aio_state->wfd, &byte, sizeof(byte));
+  if (write(posix_aio_state->wfd, &byte, sizeof(byte)) != sizeof(byte))
+    die("write()");

I'm pretty sure this change is wrong, and shows why you should never blindly believe dumb analysis tools.

The write may fail harmlessly if the pipe is already full.

Paul

#28 lore raw

Re: [Qemu-devel] [PATCH 02/18] block.c: fix warning with _FORTIFY_SOURCE

In reply to Kirill A. Shutemov
Quoted 15 lines · Kirill A. Shutemov

 CC    block.o
cc1: warnings being treated as errors
block.c: In function 'bdrv_open2':
block.c:400: error: ignoring return value of 'realpath', declared with attribute warn_unused_result

---
 block.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
block.c +0 -0
index 3f3496e..30ae2b1 100644

block.c int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, · line 403

Quoted 10 lines
block.c +2 -2
@@ -396,8 +396,8 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
         if (is_protocol)
             snprintf(backing_filename, sizeof(backing_filename),
                      "%s", filename);
-        else
-            realpath(filename, backing_filename);
+        else if (!realpath(filename, backing_filename))
+            return -errno;
 
         bdrv_qcow2 = bdrv_find_format("qcow2");
         options = parse_option_parameters("", bdrv_qcow2->create_options, NULL);

This patch appears to be correct considering:
- return value of realpath
- errno codes in the error case (as advertised by Linux man page and the functions referenced by OpenBSD man page: lstat(), readlink(2) and getcwd())
- return value of bdrv_open2().