Revision 01fc99d6 block/vmdk.c

b/block/vmdk.c
103 103
        return 0;
104 104
    magic = be32_to_cpu(*(uint32_t *)buf);
105 105
    if (magic == VMDK3_MAGIC ||
106
        magic == VMDK4_MAGIC)
106
        magic == VMDK4_MAGIC) {
107 107
        return 100;
108
    else
108
    } else {
109
        const char *p = (const char *)buf;
110
        const char *end = p + buf_size;
111
        while (p < end) {
112
            if (*p == '#') {
113
                /* skip comment line */
114
                while (p < end && *p != '\n') {
115
                    p++;
116
                }
117
                p++;
118
                continue;
119
            }
120
            if (*p == ' ') {
121
                while (p < end && *p == ' ') {
122
                    p++;
123
                }
124
                /* skip '\r' if windows line endings used. */
125
                if (p < end && *p == '\r') {
126
                    p++;
127
                }
128
                /* only accept blank lines before 'version=' line */
129
                if (p == end || *p != '\n') {
130
                    return 0;
131
                }
132
                p++;
133
                continue;
134
            }
135
            if (end - p >= strlen("version=X\n")) {
136
                if (strncmp("version=1\n", p, strlen("version=1\n")) == 0 ||
137
                    strncmp("version=2\n", p, strlen("version=2\n")) == 0) {
138
                    return 100;
139
                }
140
            }
141
            if (end - p >= strlen("version=X\r\n")) {
142
                if (strncmp("version=1\r\n", p, strlen("version=1\r\n")) == 0 ||
143
                    strncmp("version=2\r\n", p, strlen("version=2\r\n")) == 0) {
144
                    return 100;
145
                }
146
            }
147
            return 0;
148
        }
109 149
        return 0;
150
    }
110 151
}
111 152

  
112 153
#define CHECK_CID 1

Also available in: Unified diff