| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | const char *QElfParser::parseSectionHeader(const char *data, ElfSectionHeader *sh) | - |
| 11 | { | - |
| 12 | sh->name = read<qelfword_t>(data); | - |
| 13 | data += sizeof(qelfword_t); | - |
| 14 | sh->type = read<qelfword_t>(data); | - |
| 15 | data += sizeof(qelfword_t) | - |
| 16 | + sizeof(qelfaddr_t) | - |
| 17 | + sizeof(qelfaddr_t); | - |
| 18 | sh->offset = read<qelfoff_t>(data); | - |
| 19 | data += sizeof(qelfoff_t); | - |
| 20 | sh->size = read<qelfoff_t>(data); | - |
| 21 | data += sizeof(qelfoff_t); | - |
| 22 | return data; executed: return data;Execution Count:3948 | 3948 |
| 23 | } | - |
| 24 | | - |
| 25 | int QElfParser::parse(const char *dataStart, ulong fdlen, const QString &library, QLibraryPrivate *lib, long *pos, ulong *sectionlen) | - |
| 26 | { | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | if (fdlen < 64){ evaluated: fdlen < 64| yes Evaluation Count:2 | yes Evaluation Count:484 |
| 2-484 |
| 32 | if (lib) partially evaluated: lib| yes Evaluation Count:2 | no Evaluation Count:0 |
| 0-2 |
| 33 | lib->errorString = QLibrary::tr("'%1' is not an ELF object (%2)").arg(library).arg(QLatin1String("file too small")); executed: lib->errorString = QLibrary::tr("'%1' is not an ELF object (%2)").arg(library).arg(QLatin1String("file too small"));Execution Count:2 | 2 |
| 34 | return NotElf; executed: return NotElf;Execution Count:2 | 2 |
| 35 | } | - |
| 36 | const char *data = dataStart; | - |
| 37 | if (qstrncmp(data, "\177ELF", 4) != 0) { evaluated: qstrncmp(data, "\177ELF", 4) != 0| yes Evaluation Count:253 | yes Evaluation Count:231 |
| 231-253 |
| 38 | if (lib) partially evaluated: lib| yes Evaluation Count:253 | no Evaluation Count:0 |
| 0-253 |
| 39 | lib->errorString = QLibrary::tr("'%1' is not an ELF object").arg(library); executed: lib->errorString = QLibrary::tr("'%1' is not an ELF object").arg(library);Execution Count:253 | 253 |
| 40 | return NotElf; executed: return NotElf;Execution Count:253 | 253 |
| 41 | } | - |
| 42 | | - |
| 43 | if (data[4] != 1 && data[4] != 2) { partially evaluated: data[4] != 1| yes Evaluation Count:231 | no Evaluation Count:0 |
partially evaluated: data[4] != 2| no Evaluation Count:0 | yes Evaluation Count:231 |
| 0-231 |
| 44 | if (lib) | 0 |
| 45 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd cpu architecture")); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd cpu architecture")); | 0 |
| 46 | return Corrupt; never executed: return Corrupt; | 0 |
| 47 | } | - |
| 48 | m_bits = (data[4] << 5); | - |
| 49 | | - |
| 50 | | - |
| 51 | | - |
| 52 | | - |
| 53 | if ((sizeof(void*) == 4 && m_bits != 32) || (sizeof(void*) == 8 && m_bits != 64)) { partially evaluated: sizeof(void*) == 4| no Evaluation Count:0 | yes Evaluation Count:231 |
never evaluated: m_bits != 32 partially evaluated: sizeof(void*) == 8| yes Evaluation Count:231 | no Evaluation Count:0 |
partially evaluated: m_bits != 64| no Evaluation Count:0 | yes Evaluation Count:231 |
| 0-231 |
| 54 | if (lib) | 0 |
| 55 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("wrong cpu architecture")); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("wrong cpu architecture")); | 0 |
| 56 | return Corrupt; never executed: return Corrupt; | 0 |
| 57 | } | - |
| 58 | | - |
| 59 | if (data[5] == 0) { partially evaluated: data[5] == 0| no Evaluation Count:0 | yes Evaluation Count:231 |
| 0-231 |
| 60 | if (lib) | 0 |
| 61 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd endianess")); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd endianess")); | 0 |
| 62 | return Corrupt; never executed: return Corrupt; | 0 |
| 63 | } | - |
| 64 | m_endian = (data[5] == 1 ? ElfLittleEndian : ElfBigEndian); partially evaluated: data[5] == 1| yes Evaluation Count:231 | no Evaluation Count:0 |
| 0-231 |
| 65 | | - |
| 66 | data += 16 | - |
| 67 | + sizeof(qelfhalf_t) | - |
| 68 | + sizeof(qelfhalf_t) | - |
| 69 | + sizeof(qelfword_t) | - |
| 70 | + sizeof(qelfaddr_t) | - |
| 71 | + sizeof(qelfoff_t); | - |
| 72 | | - |
| 73 | qelfoff_t e_shoff = read<qelfoff_t> (data); | - |
| 74 | data += sizeof(qelfoff_t) | - |
| 75 | + sizeof(qelfword_t); | - |
| 76 | | - |
| 77 | qelfhalf_t e_shsize = read<qelfhalf_t> (data); | - |
| 78 | | - |
| 79 | if (e_shsize > fdlen) { partially evaluated: e_shsize > fdlen| no Evaluation Count:0 | yes Evaluation Count:231 |
| 0-231 |
| 80 | if (lib) | 0 |
| 81 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("unexpected e_shsize")); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("unexpected e_shsize")); | 0 |
| 82 | return Corrupt; never executed: return Corrupt; | 0 |
| 83 | } | - |
| 84 | | - |
| 85 | data += sizeof(qelfhalf_t) | - |
| 86 | + sizeof(qelfhalf_t) | - |
| 87 | + sizeof(qelfhalf_t); | - |
| 88 | | - |
| 89 | qelfhalf_t e_shentsize = read<qelfhalf_t> (data); | - |
| 90 | | - |
| 91 | if (e_shentsize % 4){ partially evaluated: e_shentsize % 4| no Evaluation Count:0 | yes Evaluation Count:231 |
| 0-231 |
| 92 | if (lib) | 0 |
| 93 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("unexpected e_shentsize")); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("unexpected e_shentsize")); | 0 |
| 94 | return Corrupt; never executed: return Corrupt; | 0 |
| 95 | } | - |
| 96 | data += sizeof(qelfhalf_t); | - |
| 97 | qelfhalf_t e_shnum = read<qelfhalf_t> (data); | - |
| 98 | data += sizeof(qelfhalf_t); | - |
| 99 | qelfhalf_t e_shtrndx = read<qelfhalf_t> (data); | - |
| 100 | data += sizeof(qelfhalf_t); | - |
| 101 | | - |
| 102 | if ((quint32)(e_shnum * e_shentsize) > fdlen) { partially evaluated: (quint32)(e_shnum * e_shentsize) > fdlen| no Evaluation Count:0 | yes Evaluation Count:231 |
| 0-231 |
| 103 | if (lib) | 0 |
| 104 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) | 0 |
| 105 | .arg(QLatin1String("announced %2 sections, each %3 bytes, exceed file size")) | 0 |
| 106 | .arg(e_shnum).arg(e_shentsize); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) .arg(QLatin1String("announced %2 sections, each %3 bytes, exceed file size")) .arg(e_shnum).arg(e_shentsize); | 0 |
| 107 | return Corrupt; never executed: return Corrupt; | 0 |
| 108 | } | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | ElfSectionHeader strtab; | - |
| 115 | qulonglong soff = e_shoff + e_shentsize * (e_shtrndx); | - |
| 116 | | - |
| 117 | if ((soff + e_shentsize) > fdlen || soff % 4 || soff == 0) { partially evaluated: (soff + e_shentsize) > fdlen| no Evaluation Count:0 | yes Evaluation Count:231 |
evaluated: soff % 4| yes Evaluation Count:1 | yes Evaluation Count:230 |
partially evaluated: soff == 0| no Evaluation Count:0 | yes Evaluation Count:230 |
| 0-231 |
| 118 | if (lib) partially evaluated: lib| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 119 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) | 1 |
| 120 | .arg(QLatin1String("shstrtab section header seems to be at %1")) | 1 |
| 121 | .arg(QString::number(soff, 16)); executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) .arg(QLatin1String("shstrtab section header seems to be at %1")) .arg(QString::number(soff, 16));Execution Count:1 | 1 |
| 122 | return Corrupt; executed: return Corrupt;Execution Count:1 | 1 |
| 123 | } | - |
| 124 | | - |
| 125 | parseSectionHeader(dataStart + soff, &strtab); | - |
| 126 | m_stringTableFileOffset = strtab.offset; | - |
| 127 | | - |
| 128 | if ((quint32)(m_stringTableFileOffset + e_shentsize) >= fdlen || m_stringTableFileOffset == 0) { partially evaluated: (quint32)(m_stringTableFileOffset + e_shentsize) >= fdlen| no Evaluation Count:0 | yes Evaluation Count:230 |
partially evaluated: m_stringTableFileOffset == 0| no Evaluation Count:0 | yes Evaluation Count:230 |
| 0-230 |
| 129 | if (lib) | 0 |
| 130 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) | 0 |
| 131 | .arg(QLatin1String("string table seems to be at %1")) | 0 |
| 132 | .arg(QString::number(soff, 16)); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) .arg(QLatin1String("string table seems to be at %1")) .arg(QString::number(soff, 16)); | 0 |
| 133 | return Corrupt; never executed: return Corrupt; | 0 |
| 134 | } | - |
| 135 | | - |
| 136 | | - |
| 137 | | - |
| 138 | | - |
| 139 | | - |
| 140 | const char *s = dataStart + e_shoff; | - |
| 141 | for (int i = 0; i < e_shnum; ++i) { evaluated: i < e_shnum| yes Evaluation Count:3718 | yes Evaluation Count:1 |
| 1-3718 |
| 142 | ElfSectionHeader sh; | - |
| 143 | parseSectionHeader(s, &sh); | - |
| 144 | if (sh.name == 0) { evaluated: sh.name == 0| yes Evaluation Count:232 | yes Evaluation Count:3486 |
| 232-3486 |
| 145 | s += e_shentsize; | - |
| 146 | continue; executed: continue;Execution Count:232 | 232 |
| 147 | } | - |
| 148 | const char *shnam = dataStart + m_stringTableFileOffset + sh.name; | - |
| 149 | | - |
| 150 | if (m_stringTableFileOffset + sh.name > fdlen) { evaluated: m_stringTableFileOffset + sh.name > fdlen| yes Evaluation Count:1 | yes Evaluation Count:3485 |
| 1-3485 |
| 151 | if (lib) partially evaluated: lib| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 152 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) | 1 |
| 153 | .arg(QLatin1String("section name %2 of %3 behind end of file")) | 1 |
| 154 | .arg(i).arg(e_shnum); executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) .arg(QLatin1String("section name %2 of %3 behind end of file")) .arg(i).arg(e_shnum);Execution Count:1 | 1 |
| 155 | return Corrupt; executed: return Corrupt;Execution Count:1 | 1 |
| 156 | } | - |
| 157 | | - |
| 158 | | - |
| 159 | | - |
| 160 | | - |
| 161 | | - |
| 162 | if (qstrcmp(shnam, ".qtmetadata") == 0 || qstrcmp(shnam, ".rodata") == 0) { evaluated: qstrcmp(shnam, ".qtmetadata") == 0| yes Evaluation Count:227 | yes Evaluation Count:3258 |
evaluated: qstrcmp(shnam, ".rodata") == 0| yes Evaluation Count:230 | yes Evaluation Count:3028 |
| 227-3258 |
| 163 | if (!(sh.type & 0x1)) { evaluated: !(sh.type & 0x1)| yes Evaluation Count:1 | yes Evaluation Count:456 |
| 1-456 |
| 164 | if (shnam[1] == 'r') { partially evaluated: shnam[1] == 'r'| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 165 | if (lib) partially evaluated: lib| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 166 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) | 1 |
| 167 | .arg(QLatin1String("empty .rodata. not a library.")); executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) .arg(QLatin1String("empty .rodata. not a library."));Execution Count:1 | 1 |
| 168 | return Corrupt; executed: return Corrupt;Execution Count:1 | 1 |
| 169 | } | - |
| 170 | | - |
| 171 | | - |
| 172 | | - |
| 173 | s += e_shentsize; | - |
| 174 | continue; never executed: continue; | 0 |
| 175 | } | - |
| 176 | | - |
| 177 | if (sh.offset == 0 || (sh.offset + sh.size) > fdlen || sh.size < 1) { partially evaluated: sh.offset == 0| no Evaluation Count:0 | yes Evaluation Count:456 |
partially evaluated: (sh.offset + sh.size) > fdlen| no Evaluation Count:0 | yes Evaluation Count:456 |
partially evaluated: sh.size < 1| no Evaluation Count:0 | yes Evaluation Count:456 |
| 0-456 |
| 178 | if (lib) | 0 |
| 179 | lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) | 0 |
| 180 | .arg(QLatin1String("missing section data. This is not a library.")); never executed: lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library) .arg(QLatin1String("missing section data. This is not a library.")); | 0 |
| 181 | return Corrupt; never executed: return Corrupt; | 0 |
| 182 | } | - |
| 183 | *pos = sh.offset; | - |
| 184 | *sectionlen = sh.size - 1; | - |
| 185 | if (shnam[1] == 'q') evaluated: shnam[1] == 'q'| yes Evaluation Count:227 | yes Evaluation Count:229 |
| 227-229 |
| 186 | return QtMetaDataSection; executed: return QtMetaDataSection;Execution Count:227 | 227 |
| 187 | } executed: }Execution Count:229 | 229 |
| 188 | s += e_shentsize; | - |
| 189 | } executed: }Execution Count:3257 | 3257 |
| 190 | return NoQtSection; executed: return NoQtSection;Execution Count:1 | 1 |
| 191 | } | - |
| 192 | | - |
| 193 | | - |
| 194 | | - |
| | |