Commit 712e78744e3a0332825a80298f38225b30dec88c

Authored by bellard
1 parent 7c35359c

probing fixes


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1425 c046a42c-6fe2-441c-8c8c-71466251a162
block-cow.c
... ... @@ -54,7 +54,8 @@ static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
54 54 {
55 55 const struct cow_header_v2 *cow_header = (const void *)buf;
56 56  
57   - if (be32_to_cpu(cow_header->magic) == COW_MAGIC &&
  57 + if (buf_size >= sizeof(struct cow_header_v2) &&
  58 + be32_to_cpu(cow_header->magic) == COW_MAGIC &&
58 59 be32_to_cpu(cow_header->version) == COW_VERSION)
59 60 return 100;
60 61 else
... ...
block-qcow.c
... ... @@ -80,8 +80,9 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset);
80 80 static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
81 81 {
82 82 const QCowHeader *cow_header = (const void *)buf;
83   -
84   - if (be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
  83 +
  84 + if (buf_size >= sizeof(QCowHeader) &&
  85 + be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
85 86 be32_to_cpu(cow_header->version) == QCOW_VERSION)
86 87 return 100;
87 88 else
... ... @@ -551,9 +552,19 @@ static int qcow_create(const char *filename, int64_t total_size,
551 552 header_size = sizeof(header);
552 553 backing_filename_len = 0;
553 554 if (backing_file) {
554   - realpath(backing_file, backing_filename);
555   - if (stat(backing_filename, &st) != 0) {
556   - return -1;
  555 + const char *p;
  556 + /* XXX: this is a hack: we do not attempt to check for URL
  557 + like syntax */
  558 + p = strchr(backing_file, ':');
  559 + if (p && (p - backing_file) >= 2) {
  560 + /* URL like but exclude "c:" like filenames */
  561 + pstrcpy(backing_filename, sizeof(backing_filename),
  562 + backing_file);
  563 + } else {
  564 + realpath(backing_file, backing_filename);
  565 + if (stat(backing_filename, &st) != 0) {
  566 + return -1;
  567 + }
557 568 }
558 569 header.mtime = cpu_to_be32(st.st_mtime);
559 570 header.backing_file_offset = cpu_to_be64(header_size);
... ...
block-vpc.c
... ... @@ -81,9 +81,8 @@ typedef struct BDRVVPCState {
81 81  
82 82 static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
83 83 {
84   - if (!strncmp(buf, "conectix", 8))
  84 + if (buf_size >= 8 && !strncmp(buf, "conectix", 8))
85 85 return 100;
86   -
87 86 return 0;
88 87 }
89 88  
... ...
... ... @@ -106,26 +106,29 @@ static BlockDriver *find_image_format(const char *filename)
106 106 size_t bufsize = 1024;
107 107  
108 108 fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
109   - if (fd < 0)
110   - return NULL;
  109 + if (fd < 0) {
  110 + buf = NULL;
  111 + ret = 0;
  112 + } else {
111 113 #ifdef DIOCGSECTORSIZE
112   - {
113   - unsigned int sectorsize = 512;
114   - if (!ioctl(fd, DIOCGSECTORSIZE, &sectorsize) &&
115   - sectorsize > bufsize)
116   - bufsize = sectorsize;
117   - }
  114 + {
  115 + unsigned int sectorsize = 512;
  116 + if (!ioctl(fd, DIOCGSECTORSIZE, &sectorsize) &&
  117 + sectorsize > bufsize)
  118 + bufsize = sectorsize;
  119 + }
118 120 #endif
119   - buf = malloc(bufsize);
120   - if (!buf)
121   - return NULL;
122   - ret = read(fd, buf, bufsize);
123   - if (ret < 0) {
  121 + buf = qemu_malloc(bufsize);
  122 + if (!buf)
  123 + return NULL;
  124 + ret = read(fd, buf, bufsize);
  125 + if (ret < 0) {
  126 + close(fd);
  127 + qemu_free(buf);
  128 + return NULL;
  129 + }
124 130 close(fd);
125   - free(buf);
126   - return NULL;
127 131 }
128   - close(fd);
129 132  
130 133 drv = NULL;
131 134 score_max = 0;
... ... @@ -136,7 +139,7 @@ static BlockDriver *find_image_format(const char *filename)
136 139 drv = drv1;
137 140 }
138 141 }
139   - free(buf);
  142 + qemu_free(buf);
140 143 return drv;
141 144 }
142 145  
... ... @@ -154,7 +157,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
154 157 bs->read_only = 0;
155 158 bs->is_temporary = 0;
156 159 bs->encrypted = 0;
157   -
  160 +
158 161 if (snapshot) {
159 162 BlockDriverState *bs1;
160 163 int64_t total_size;
... ... @@ -183,7 +186,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
183 186 filename = tmp_filename;
184 187 bs->is_temporary = 1;
185 188 }
186   -
  189 +
187 190 pstrcpy(bs->filename, sizeof(bs->filename), filename);
188 191 if (!drv) {
189 192 drv = find_image_format(filename);
... ... @@ -653,4 +656,5 @@ void bdrv_init(void)
653 656 bdrv_register(&bdrv_dmg);
654 657 bdrv_register(&bdrv_bochs);
655 658 bdrv_register(&bdrv_vpc);
  659 + bdrv_register(&bdrv_vvfat);
656 660 }
... ...