coverity 177410: check seek return value inside fops-zip
authorAndy Green <andy@warmcat.com>
Mon, 6 Mar 2017 05:59:27 +0000 (13:59 +0800)
committerAndy Green <andy@warmcat.com>
Mon, 6 Mar 2017 06:46:05 +0000 (14:46 +0800)
Truncated or corrupted zip on server side would read garbage instead of fail.

lib/fops-zip.c

index 02f4999..140419b 100644 (file)
@@ -147,6 +147,7 @@ enum {
        LWS_FZ_ERR_CENTRAL_READ,
        LWS_FZ_ERR_CENTRAL_SANITY,
        LWS_FZ_ERR_NAME_TOO_LONG,
+       LWS_FZ_ERR_NAME_SEEK,
        LWS_FZ_ERR_NAME_READ,
        LWS_FZ_ERR_CONTENT_SANITY,
        LWS_FZ_ERR_CONTENT_SEEK,
@@ -256,7 +257,8 @@ lws_fops_zip_scan(lws_fops_zip_t priv, const char *name, int len)
                        goto next;
 
                /* we found a match */
-               lws_vfs_file_seek_set(priv->zip_fop_fd, priv->hdr.offset);
+               if (lws_vfs_file_seek_set(priv->zip_fop_fd, priv->hdr.offset) < 0)
+                       return LWS_FZ_ERR_NAME_SEEK;
                if (priv->zip_fop_fd->fops->LWS_FOP_READ(priv->zip_fop_fd,
                                                        &amount, buf,
                                                        ZL_HEADER_LENGTH))