--- scanforssp.awk 2003-12-28 18:37:41.000000000 -0500 +++ scanforssp-2.awk 2003-12-29 05:42:53.000000000 -0500 @@ -1,65 +1,54 @@ # Copyright 1999-2003 Gentoo Technologies, Inc. # Distributed under the terms of the GNU General Public License v2 # Author: Martin Schlemmer +# Contributor: Ned Ludd # $Header: /home/httpd/cvsroot/gentoo-x86/sys-devel/gcc/files/awk/scanforssp.awk,v 1.1 2003/12/28 21:46:24 azarah Exp $ + +# does not seem to be used in this script. function printn(string) { - system("echo -n \"" string "\"") + printf("%s", string) } function einfo(string) { - system("echo -e \" \\e[32;01m*\\e[0m " string "\"") + printf(" %s %s%s", "\033[32;01m*\033[0m", string, "\n") } +# does not seem to be used in this script. function einfon(string) { - system("echo -ne \" \\e[32;01m*\\e[0m " string "\"") + printf(" %s %s" , "\033[32;01m*\033[0m", string) } function ewarn(string) { - system("echo -e \" \\e[33;01m*\\e[0m " string "\"") + printf(" %s %s%s" , "\033[33;01m*\033[0m", string, "\n") } +# does not seem to be used in this script. function ewarnn(string) { - system("echo -ne \" \\e[33;01m*\\e[0m " string "\"") + printf("%s %s" , "\032[33;01m*\033[0m", string) } - + +# does not seem to be used in this script. function eerror(string) { - system("echo -e \" \\e[31;01m*\\e[0m " string "\"") + printf(" %s %s%s" , "\033[31;01m*\033[0m", string, "\n") } -# assert --- assert that a condition is true. Otherwise exit. -# This is from the gawk info manual. -function assert(condition, string) -{ - if (! condition) { - printf("%s:%d: assertion failed: %s\n", - FILENAME, FNR, string) > "/dev/stderr" - _assert_exit = 1 - exit 1 - } +function iself(scan_files) { + # can we open() a file and read() 4 bytes? + scan_file_pipe = ("head -c 4 " scan_files " 2>/dev/null | tail -c 3") + scan_file_pipe | getline scan_data + close("head -c 4 " scan_files " 2>/dev/null | tail -c 3") + return ((scan_data == "ELF") ? 0 : 1) } -# system() wrapper that normalize return codes ... -function dosystem(command, ret) -{ - ret = 0 - - ret = system(command) - if (ret == 0) - return 1 - else - return 0 -} - - BEGIN { - + auto_etcat = 0 DIRCOUNT = 0 # Add the two default library paths DIRLIST[1] = "/lib" @@ -108,7 +97,10 @@ } } - close(pipe) + exit_val = close(pipe) + if (exit_val != 0) + print(exit_val " - " ERRNO) + # We have no guarantee that ld.so.conf have more library paths than # the default, and its better scan files only in /lib and /usr/lib @@ -134,11 +126,12 @@ if (ADDED) continue - - DIRLIST[++DIRCOUNT] = PATHLIST[x] + + if (((PATHLIST[x] != "") && (PATHLIST[x] != "/") && (PATHLIST[x] != "."))) + DIRLIST[++DIRCOUNT] = PATHLIST[x] + } - FOUND_SSP = 0 GCCLIBPREFIX = "/usr/lib/gcc-lib/" for (x = 1;x <= DIRCOUNT;x++) { @@ -146,40 +139,42 @@ # Do nothing if the target dir is gcc's internal library path if (DIRLIST[x] ~ GCCLIBPREFIX) continue - einfo(" Scanning " DIRLIST[x] "...") - - FOUND = 0 - - pipe = "find " DIRLIST[x] "/ -type f -perm -1 -maxdepth 90 2>/dev/null" - while ((((pipe) | getline scan_files) > 0) && (!FOUND)) { + einfo("Scanning " ((x <= 9) ? "0"x : x)" of " DIRCOUNT " " DIRLIST[x] "...") + pipe = ("find " DIRLIST[x] "/ -type f -perm -1 -maxdepth 90 2>/dev/null") + while ( (pipe | getline scan_files) > 0) { # Do nothing if the file is located in gcc's internal lib path if (scan_files ~ GCCLIBPREFIX) continue + if (scan_files ~ "/lib/libgcc-3" ) continue + if (iself(scan_files)) continue - scan_file_pipe = "readelf -s " scan_files " 2>/dev/null" -# while ((((scan_file_pipe) | getline scan_data) > 0) && (!FOUND)) { - while (((getline scan_data < (scan_files)) > 0) && (!FOUND)) { - - if (scan_data ~ /__guard@GCC/) { - - ewarn(" Found files containing '__guard@GCC'!") - FOUND = 1 - FOUND_SSP = 1 - break + scan_file_pipe = ("readelf -s " scan_files " 2>/dev/null") + while ((scan_file_pipe | getline scan_data) > 0) { + if (scan_data ~ /__guard@GCC/ || scan_data ~ /__guard@@GCC/) { + + # 194: 00000000 32 OBJECT GLOBAL DEFAULT UND __guard@GCC_3.0 (3) + # 59: 00008ee0 32 OBJECT GLOBAL DEFAULT 22 __guard@@GCC_3.0 + # how can we get the 8th index? + ewarn("Found " scan_data " in " scan_files) + + if (auto_etcat) { + # use etcat that comes with gentoolkit if auto_etcat is true. + etcat_pipe = ("etcat belongs " scan_files) + etcat_pipe | getline etcat_belongs + + while((etcat_pipe | getline etcat_belongs) > 0) + eerror(etcat_belongs != "" ? "Please emerge '>=" etcat_belongs "'": "") + close("etcat belongs " scan_files) + } + exit(1) } } - -# close(scan_file_pipe) - close(scan_files) + close("readelf -s " scan_files " 2>/dev/null") } - - close(pipe) + close("find " DIRLIST[x] "/ -type f -perm -1 -maxdepth 90 2>/dev/null") } - if (FOUND_SSP) - exit(1) - else - exit(0) + exit(0) }