]> git.ipfire.org Git - people/stevee/pakfire.git/blobdiff - src/libpakfire/file.c
build: Move strip check into file check
[people/stevee/pakfire.git] / src / libpakfire / file.c
index b4b599a7bd19d98a842d4f65c87142b666702846..24a76553e6b3339b70aa42cba56d7f4802ddda3e 100644 (file)
@@ -623,6 +623,12 @@ char* pakfire_file_dump(struct pakfire_file* file, int flags) {
                                goto ERROR;
                }
 
+               if (file->issues & PAKFIRE_FILE_MISSING_DEBUGINFO) {
+                       r = asprintf(&buffer, "%s [MISSING-DEBUGINFO]", buffer);
+                       if (r < 0)
+                               goto ERROR;
+               }
+
                if (pakfire_file_matches_class(file, PAKFIRE_FILE_ELF)) {
                        // Stack-smashing Protection
                        if (file->issues & PAKFIRE_FILE_NO_SSP) {
@@ -1692,7 +1698,7 @@ static int pakfire_file_get_elf_type(struct pakfire_file* file) {
        return type;
 }
 
-static int __pakfire_file_is_stripped(struct pakfire_file* file, Elf* elf, void* data) {
+static int __pakfire_file_check_debuginfo(struct pakfire_file* file, Elf* elf, void* data) {
        Elf_Scn* section = NULL;
        GElf_Shdr shdr;
 
@@ -1715,20 +1721,13 @@ static int __pakfire_file_is_stripped(struct pakfire_file* file, Elf* elf, void*
        // Not found
        DEBUG(file->pakfire, "%s has no debug sections\n", file->path);
 
-       return 1;
-}
+       // Store the result
+       file->issues |= PAKFIRE_FILE_MISSING_DEBUGINFO;
 
-int pakfire_file_is_stripped(struct pakfire_file* file) {
-       // Don't run this for non-ELF files
-       if (!pakfire_file_matches_class(file, PAKFIRE_FILE_ELF)) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       // Do not perform this check on firmware
-       if (pakfire_file_matches_class(file, PAKFIRE_FILE_FIRMWARE))
-               return 0;
+       return 0;
+}
 
+static int pakfire_file_check_debuginfo(struct pakfire_file* file) {
        switch (pakfire_file_get_elf_type(file)) {
                // Do not check Relocatable Objects
                case ET_REL:
@@ -1739,7 +1738,7 @@ int pakfire_file_is_stripped(struct pakfire_file* file) {
                        break;
        }
 
-       return pakfire_file_open_elf(file, __pakfire_file_is_stripped, NULL);
+       return pakfire_file_open_elf(file, __pakfire_file_check_debuginfo, NULL);
 }
 
 static int __pakfire_file_check_ssp(
@@ -1811,6 +1810,10 @@ static int pakfire_file_check_ssp(struct pakfire_file* file) {
        if (pakfire_file_matches_class(file, PAKFIRE_FILE_RUNTIME_LINKER))
                return 0;
 
+       // We cannot perform this check if we don't have debuginfo
+       if (file->issues & PAKFIRE_FILE_MISSING_DEBUGINFO)
+               return 0;
+
        return pakfire_file_open_elf(file, __pakfire_file_check_ssp, NULL);
 }
 
@@ -1948,6 +1951,11 @@ int pakfire_file_check(struct pakfire_file* file, int* issues) {
                                        break;
                        }
 
+                       // Check if the file has debug info
+                       r = pakfire_file_check_debuginfo(file);
+                       if (r)
+                               return r;
+
                        // Check for SSP
                        r = pakfire_file_check_ssp(file);
                        if (r)