]>
Commit | Line | Data |
---|---|---|
907c9f0e DM |
1 | From dfaedec7890069b35f513e4a8ab4071ca54259ff Mon Sep 17 00:00:00 2001 |
2 | From: Frediano Ziglio <fziglio@redhat.com> | |
3 | Date: Tue, 8 Sep 2015 10:05:20 +0100 | |
4 | Subject: [PATCH 10/19] Fix race condition in red_get_string | |
5 | ||
6 | Do not read multiple time an array size that can be changed. | |
7 | ||
8 | Signed-off-by: Frediano Ziglio <fziglio@redhat.com> | |
9 | Acked-by: Christophe Fergeau <cfergeau@redhat.com> | |
10 | --- | |
11 | server/red_parse_qxl.c | 15 +++++++++------ | |
12 | 1 file changed, 9 insertions(+), 6 deletions(-) | |
13 | ||
14 | --- a/server/red_parse_qxl.c | |
15 | +++ b/server/red_parse_qxl.c | |
16 | @@ -810,6 +810,7 @@ static SpiceString *red_get_string(RedMe | |
17 | size_t chunk_size, qxl_size, red_size, glyph_size; | |
18 | int glyphs, bpp = 0, i; | |
19 | int error; | |
20 | + uint16_t qxl_flags, qxl_length; | |
21 | ||
22 | qxl = (QXLString *)get_virt(slots, addr, sizeof(*qxl), group_id, &error); | |
23 | if (error) { | |
24 | @@ -826,13 +827,15 @@ static SpiceString *red_get_string(RedMe | |
25 | red_put_data_chunks(&chunks); | |
26 | ||
27 | qxl_size = qxl->data_size; | |
28 | + qxl_flags = qxl->flags; | |
29 | + qxl_length = qxl->length; | |
30 | spice_assert(chunk_size == qxl_size); | |
31 | ||
32 | - if (qxl->flags & SPICE_STRING_FLAGS_RASTER_A1) { | |
33 | + if (qxl_flags & SPICE_STRING_FLAGS_RASTER_A1) { | |
34 | bpp = 1; | |
35 | - } else if (qxl->flags & SPICE_STRING_FLAGS_RASTER_A4) { | |
36 | + } else if (qxl_flags & SPICE_STRING_FLAGS_RASTER_A4) { | |
37 | bpp = 4; | |
38 | - } else if (qxl->flags & SPICE_STRING_FLAGS_RASTER_A8) { | |
39 | + } else if (qxl_flags & SPICE_STRING_FLAGS_RASTER_A8) { | |
40 | bpp = 8; | |
41 | } | |
42 | spice_assert(bpp != 0); | |
43 | @@ -849,11 +852,11 @@ static SpiceString *red_get_string(RedMe | |
44 | start = (QXLRasterGlyph*)(&start->data[glyph_size]); | |
45 | } | |
46 | spice_assert(start <= end); | |
47 | - spice_assert(glyphs == qxl->length); | |
48 | + spice_assert(glyphs == qxl_length); | |
49 | ||
50 | red = spice_malloc(red_size); | |
51 | - red->length = qxl->length; | |
52 | - red->flags = qxl->flags; | |
53 | + red->length = qxl_length; | |
54 | + red->flags = qxl_flags; | |
55 | ||
56 | start = (QXLRasterGlyph*)data; | |
57 | end = (QXLRasterGlyph*)(data + chunk_size); |