Back to home page

OSCL-LXR

 
 

    


0001 #!/usr/bin/awk -f
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Copyright © 2020, Microsoft Corporation. All rights reserved.
0005 #
0006 # Author: Mickaël Salaün <mic@linux.microsoft.com>
0007 #
0008 # Check that a CONFIG_SYSTEM_BLACKLIST_HASH_LIST file contains a valid array of
0009 # hash strings.  Such string must start with a prefix ("tbs" or "bin"), then a
0010 # colon (":"), and finally an even number of hexadecimal lowercase characters
0011 # (up to 128).
0012 
0013 BEGIN {
0014   RS = ","
0015 }
0016 {
0017   if (!match($0, "^[ \t\n\r]*\"([^\"]*)\"[ \t\n\r]*$", part1)) {
0018     print "Not a string (item " NR "):", $0;
0019     exit 1;
0020   }
0021   if (!match(part1[1], "^(tbs|bin):(.*)$", part2)) {
0022     print "Unknown prefix (item " NR "):", part1[1];
0023     exit 1;
0024   }
0025   if (!match(part2[2], "^([0-9a-f]+)$", part3)) {
0026     print "Not a lowercase hexadecimal string (item " NR "):", part2[2];
0027     exit 1;
0028   }
0029   if (length(part3[1]) > 128) {
0030     print "Hash string too long (item " NR "):", part3[1];
0031     exit 1;
0032   }
0033   if (length(part3[1]) % 2 == 1) {
0034     print "Not an even number of hexadecimal characters (item " NR "):", part3[1];
0035     exit 1;
0036   }
0037 }