Skip to content

Commit 7b75157

Browse files
committed
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches: - qemu-img convert: Don't pre-zero images (removes nowadays counterproductive optimisation) - qemu-storage-daemon: Fix object-del, cleaner shutdown - vvfat: Check that the guest doesn't escape the given host directory with read-write vvfat drives - vvfat: Fix crash by out-of-bounds array writes for read-write drives - iotests fixes # gpg: Signature made Fri 03 Jul 2020 10:20:46 BST # gpg: using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6 # gpg: issuer "[email protected]" # gpg: Good signature from "Kevin Wolf <[email protected]>" [full] # Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6 * remotes/kevin/tags/for-upstream: iotests: Fix 051 output after qdev_init_nofail() removal iotests.py: Do not wait() before communicate() vvfat: Fix array_remove_slice() vvfat: Check that updated filenames are valid qemu-storage-daemon: add missing cleanup calls qemu-storage-daemon: remember to add qemu_object_opts qemu-img convert: Don't pre-zero images Signed-off-by: Peter Maydell <[email protected]>
2 parents 5f42c33 + 4f071a9 commit 7b75157

File tree

4 files changed

+51
-64
lines changed

4 files changed

+51
-64
lines changed

block/vvfat.c

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -140,48 +140,16 @@ static inline void* array_insert(array_t* array,unsigned int index,unsigned int
140140
return array->pointer+index*array->item_size;
141141
}
142142

143-
/* this performs a "roll", so that the element which was at index_from becomes
144-
* index_to, but the order of all other elements is preserved. */
145-
static inline int array_roll(array_t* array,int index_to,int index_from,int count)
146-
{
147-
char* buf;
148-
char* from;
149-
char* to;
150-
int is;
151-
152-
if(!array ||
153-
index_to<0 || index_to>=array->next ||
154-
index_from<0 || index_from>=array->next)
155-
return -1;
156-
157-
if(index_to==index_from)
158-
return 0;
159-
160-
is=array->item_size;
161-
from=array->pointer+index_from*is;
162-
to=array->pointer+index_to*is;
163-
buf=g_malloc(is*count);
164-
memcpy(buf,from,is*count);
165-
166-
if(index_to<index_from)
167-
memmove(to+is*count,to,from-to);
168-
else
169-
memmove(from,from+is*count,to-from);
170-
171-
memcpy(to,buf,is*count);
172-
173-
g_free(buf);
174-
175-
return 0;
176-
}
177-
178143
static inline int array_remove_slice(array_t* array,int index, int count)
179144
{
180145
assert(index >=0);
181146
assert(count > 0);
182147
assert(index + count <= array->next);
183-
if(array_roll(array,array->next-1,index,count))
184-
return -1;
148+
149+
memmove(array->pointer + index * array->item_size,
150+
array->pointer + (index + count) * array->item_size,
151+
(array->next - index - count) * array->item_size);
152+
185153
array->next -= count;
186154
return 0;
187155
}
@@ -520,12 +488,31 @@ static void set_begin_of_direntry(direntry_t* direntry, uint32_t begin)
520488
direntry->begin_hi = cpu_to_le16((begin >> 16) & 0xffff);
521489
}
522490

491+
static bool valid_filename(const unsigned char *name)
492+
{
493+
unsigned char c;
494+
if (!strcmp((const char*)name, ".") || !strcmp((const char*)name, "..")) {
495+
return false;
496+
}
497+
for (; (c = *name); name++) {
498+
if (!((c >= '0' && c <= '9') ||
499+
(c >= 'A' && c <= 'Z') ||
500+
(c >= 'a' && c <= 'z') ||
501+
c > 127 ||
502+
strchr("$%'-_@~`!(){}^#&.+,;=[]", c) != NULL))
503+
{
504+
return false;
505+
}
506+
}
507+
return true;
508+
}
509+
523510
static uint8_t to_valid_short_char(gunichar c)
524511
{
525512
c = g_unichar_toupper(c);
526513
if ((c >= '0' && c <= '9') ||
527514
(c >= 'A' && c <= 'Z') ||
528-
strchr("$%'-_@~`!(){}^#&", c) != 0) {
515+
strchr("$%'-_@~`!(){}^#&", c) != NULL) {
529516
return c;
530517
} else {
531518
return 0;
@@ -2098,6 +2085,10 @@ DLOG(fprintf(stderr, "check direntry %d:\n", i); print_direntry(direntries + i))
20982085
}
20992086
lfn.checksum = 0x100; /* cannot use long name twice */
21002087

2088+
if (!valid_filename(lfn.name)) {
2089+
fprintf(stderr, "Invalid file name\n");
2090+
goto fail;
2091+
}
21012092
if (path_len + 1 + lfn.len >= PATH_MAX) {
21022093
fprintf(stderr, "Name too long: %s/%s\n", path, lfn.name);
21032094
goto fail;

qemu-img.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,15 +2084,6 @@ static int convert_do_copy(ImgConvertState *s)
20842084
s->has_zero_init = bdrv_has_zero_init(blk_bs(s->target));
20852085
}
20862086

2087-
if (!s->has_zero_init && !s->target_has_backing &&
2088-
bdrv_can_write_zeroes_with_unmap(blk_bs(s->target)))
2089-
{
2090-
ret = blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK);
2091-
if (ret == 0) {
2092-
s->has_zero_init = true;
2093-
}
2094-
}
2095-
20962087
/* Allocate buffer for copied data. For compressed images, only one cluster
20972088
* can be copied at a time. */
20982089
if (s->compressed) {

qemu-storage-daemon.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ int main(int argc, char *argv[])
316316

317317
module_call_init(MODULE_INIT_QOM);
318318
module_call_init(MODULE_INIT_TRACE);
319+
qemu_add_opts(&qemu_object_opts);
319320
qemu_add_opts(&qemu_trace_opts);
320321
qcrypto_init(&error_fatal);
321322
bdrv_init();
@@ -334,5 +335,9 @@ int main(int argc, char *argv[])
334335
main_loop_wait(false);
335336
}
336337

338+
monitor_cleanup();
339+
qemu_chr_cleanup();
340+
user_creatable_cleanup();
341+
337342
return EXIT_SUCCESS;
338343
}

tests/qemu-iotests/iotests.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ def qemu_img_pipe(*args):
146146
stdout=subprocess.PIPE,
147147
stderr=subprocess.STDOUT,
148148
universal_newlines=True)
149-
exitcode = subp.wait()
150-
if exitcode < 0:
149+
output = subp.communicate()[0]
150+
if subp.returncode < 0:
151151
sys.stderr.write('qemu-img received signal %i: %s\n'
152-
% (-exitcode, ' '.join(qemu_img_args + list(args))))
153-
return subp.communicate()[0]
152+
% (-subp.returncode,
153+
' '.join(qemu_img_args + list(args))))
154+
return output
154155

155156
def qemu_img_log(*args):
156157
result = qemu_img_pipe(*args)
@@ -177,11 +178,11 @@ def qemu_io(*args):
177178
subp = subprocess.Popen(args, stdout=subprocess.PIPE,
178179
stderr=subprocess.STDOUT,
179180
universal_newlines=True)
180-
exitcode = subp.wait()
181-
if exitcode < 0:
181+
output = subp.communicate()[0]
182+
if subp.returncode < 0:
182183
sys.stderr.write('qemu-io received signal %i: %s\n'
183-
% (-exitcode, ' '.join(args)))
184-
return subp.communicate()[0]
184+
% (-subp.returncode, ' '.join(args)))
185+
return output
185186

186187
def qemu_io_log(*args):
187188
result = qemu_io(*args)
@@ -257,15 +258,14 @@ def qemu_nbd_early_pipe(*args):
257258
and its output in case of an error'''
258259
subp = subprocess.Popen(qemu_nbd_args + ['--fork'] + list(args),
259260
stdout=subprocess.PIPE,
260-
stderr=subprocess.STDOUT,
261261
universal_newlines=True)
262-
exitcode = subp.wait()
263-
if exitcode < 0:
262+
output = subp.communicate()[0]
263+
if subp.returncode < 0:
264264
sys.stderr.write('qemu-nbd received signal %i: %s\n' %
265-
(-exitcode,
265+
(-subp.returncode,
266266
' '.join(qemu_nbd_args + ['--fork'] + list(args))))
267267

268-
return exitcode, subp.communicate()[0] if exitcode else ''
268+
return subp.returncode, output if subp.returncode else ''
269269

270270
def qemu_nbd_popen(*args):
271271
'''Run qemu-nbd in daemon mode and return the parent's exit code'''
@@ -1062,11 +1062,11 @@ def qemu_pipe(*args):
10621062
subp = subprocess.Popen(args, stdout=subprocess.PIPE,
10631063
stderr=subprocess.STDOUT,
10641064
universal_newlines=True)
1065-
exitcode = subp.wait()
1066-
if exitcode < 0:
1065+
output = subp.communicate()[0]
1066+
if subp.returncode < 0:
10671067
sys.stderr.write('qemu received signal %i: %s\n' %
1068-
(-exitcode, ' '.join(args)))
1069-
return subp.communicate()[0]
1068+
(-subp.returncode, ' '.join(args)))
1069+
return output
10701070

10711071
def supported_formats(read_only=False):
10721072
'''Set 'read_only' to True to check ro-whitelist

0 commit comments

Comments
 (0)