boot: Use strlen8/16
The casts in this and the next few commits are curently necessary because CHAR8 is defined as uint8_t in gnu-efi, while char is signed. Once we switch from gnu-efi typedefs to stdint types, the casts will be dropped.
This commit is contained in:
+3
-6
@@ -7,9 +7,7 @@
|
||||
# define TEST_STATIC
|
||||
#else
|
||||
/* Provide our own "EFI API" if we are running as a unit test. */
|
||||
# include <stddef.h>
|
||||
# include <stdint.h>
|
||||
# include <uchar.h>
|
||||
# include "efi-string.h"
|
||||
# include "string-util-fundamental.h"
|
||||
|
||||
# define CHAR8 char
|
||||
@@ -19,7 +17,6 @@
|
||||
# define UINT32 uint32_t
|
||||
# define UINT64 uint64_t
|
||||
# define UINTN size_t
|
||||
# define strlena(s) strlen(s)
|
||||
# define strncaseeqa(a, b, n) strncaseeq((a), (b), (n))
|
||||
# define TEST_STATIC static
|
||||
#endif
|
||||
@@ -168,7 +165,7 @@ static const Key *get_key(const UINT8 *bcd, UINT32 bcd_len, UINT32 offset, const
|
||||
return NULL;
|
||||
|
||||
if (*name) {
|
||||
if (strncaseeqa(name, key->key_name, key->key_name_len) && strlena(name) == key->key_name_len)
|
||||
if (strncaseeqa(name, key->key_name, key->key_name_len) && strlen8((const char *) name) == key->key_name_len)
|
||||
name += key->key_name_len;
|
||||
else
|
||||
return NULL;
|
||||
@@ -213,7 +210,7 @@ static const KeyValue *get_key_value(const UINT8 *bcd, UINT32 bcd_len, const Key
|
||||
if (BAD_OFFSET(kv->data_offset, kv->data_size, bcd_len))
|
||||
continue;
|
||||
|
||||
if (strncaseeqa(name, kv->name, kv->name_len) && strlena(name) == kv->name_len)
|
||||
if (strncaseeqa(name, kv->name, kv->name_len) && strlen8((const char *) name) == kv->name_len)
|
||||
return kv;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -149,7 +149,7 @@ static BOOLEAN line_edit(
|
||||
|
||||
assert(line_in);
|
||||
|
||||
len = strlen_ptr(*line_in);
|
||||
len = strlen16(*line_in);
|
||||
size = len + 1024;
|
||||
line = xnew(CHAR16, size);
|
||||
print = xnew(CHAR16, x_max + 1);
|
||||
@@ -662,7 +662,7 @@ static BOOLEAN menu_run(
|
||||
/* length of the longest entry */
|
||||
line_width = 0;
|
||||
for (UINTN i = 0; i < config->entry_count; i++)
|
||||
line_width = MAX(line_width, StrLen(config->entries[i]->title_show));
|
||||
line_width = MAX(line_width, strlen16(config->entries[i]->title_show));
|
||||
line_width = MIN(line_width + 2 * entry_padding, x_max);
|
||||
|
||||
/* offsets to center the entries on the screen */
|
||||
@@ -686,7 +686,7 @@ static BOOLEAN menu_run(
|
||||
UINTN j, padding;
|
||||
|
||||
lines[i] = xnew(CHAR16, line_width + 1);
|
||||
padding = (line_width - MIN(StrLen(config->entries[i]->title_show), line_width)) / 2;
|
||||
padding = (line_width - MIN(strlen16(config->entries[i]->title_show), line_width)) / 2;
|
||||
|
||||
for (j = 0; j < padding; j++)
|
||||
lines[i][j] = ' ';
|
||||
@@ -750,7 +750,7 @@ static BOOLEAN menu_run(
|
||||
* input. Therefore, draw one less character then we could for the status message.
|
||||
* Note that the same does not apply for the separator line as it will never be drawn
|
||||
* on the last line. */
|
||||
UINTN len = StrnLen(status, x_max - 1);
|
||||
UINTN len = strnlen16(status, x_max - 1);
|
||||
UINTN x = (x_max - len) / 2;
|
||||
status[len] = '\0';
|
||||
print_at(0, y_status, COLOR_NORMAL, clearline + x_max - x);
|
||||
@@ -1277,13 +1277,13 @@ static void config_entry_parse_tries(
|
||||
* foobar+4-0.efi → foobar+3-1.efi → foobar+2-2.efi → foobar+1-3.efi → foobar+0-4.efi → STOP!
|
||||
*/
|
||||
|
||||
i = StrLen(file);
|
||||
i = strlen16(file);
|
||||
|
||||
/* Chop off any suffix such as ".conf" or ".efi" */
|
||||
if (suffix) {
|
||||
UINTN suffix_length;
|
||||
|
||||
suffix_length = StrLen(suffix);
|
||||
suffix_length = strlen16(suffix);
|
||||
if (i < suffix_length)
|
||||
return;
|
||||
|
||||
@@ -1829,7 +1829,7 @@ static void config_title_generate(Config *config) {
|
||||
config->entries[i]->title_show = xpool_print(
|
||||
L"%s (%.*s)",
|
||||
t,
|
||||
StrnLen(config->entries[i]->machine_id, 8),
|
||||
strnlen16(config->entries[i]->machine_id, 8),
|
||||
config->entries[i]->machine_id);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -81,12 +81,12 @@ static EFI_STATUS pack_cpio_one(
|
||||
|
||||
l = 6 + 13*8 + 1 + 1; /* Fixed CPIO header size, slash separator, and NUL byte after the file name*/
|
||||
|
||||
target_dir_prefix_size = strlena(target_dir_prefix);
|
||||
target_dir_prefix_size = strlen8((const char *) target_dir_prefix);
|
||||
if (l > UINTN_MAX - target_dir_prefix_size)
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
l += target_dir_prefix_size;
|
||||
|
||||
fname_size = StrLen(fname);
|
||||
fname_size = strlen16(fname);
|
||||
if (l > UINTN_MAX - fname_size)
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
l += fname_size; /* append space for file name */
|
||||
@@ -182,7 +182,7 @@ static EFI_STATUS pack_cpio_dir(
|
||||
|
||||
l = 6 + 13*8 + 1; /* Fixed CPIO header size, and NUL byte after the file name*/
|
||||
|
||||
path_size = strlena(path);
|
||||
path_size = strlen8((const char *) path);
|
||||
if (l > UINTN_MAX - path_size)
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
l += path_size;
|
||||
@@ -388,7 +388,7 @@ EFI_STATUS pack_cpio(
|
||||
continue;
|
||||
if (!is_ascii(dirent->FileName))
|
||||
continue;
|
||||
if (StrLen(dirent->FileName) > 255) /* Max filename size on Linux */
|
||||
if (strlen16(dirent->FileName) > 255) /* Max filename size on Linux */
|
||||
continue;
|
||||
|
||||
d = xstrdup(dirent->FileName);
|
||||
|
||||
@@ -194,6 +194,7 @@ efi_cflags = cc.get_supported_arguments(
|
||||
'-isystem', efi_incdir,
|
||||
'-isystem', efi_incdir / efi_arch[1],
|
||||
'-I', fundamental_path,
|
||||
'-I', meson.current_source_dir(),
|
||||
'-DSD_BOOT',
|
||||
'-DGNU_EFI_USE_MS_ABI',
|
||||
'-include', efi_config_h,
|
||||
@@ -390,14 +391,14 @@ tests += [
|
||||
if efi_arch[1] in ['ia32', 'x86_64', 'arm', 'aarch64']
|
||||
systemd_boot_sources += files('bcd.c')
|
||||
tests += [
|
||||
[files('test-bcd.c'),
|
||||
[files('test-bcd.c', 'efi-string.c'),
|
||||
[],
|
||||
[libzstd],
|
||||
[],
|
||||
'HAVE_ZSTD'],
|
||||
]
|
||||
fuzzers += [
|
||||
[files('fuzz-bcd.c')],
|
||||
[files('fuzz-bcd.c', 'efi-string.c')],
|
||||
]
|
||||
endif
|
||||
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ static void locate_sections(
|
||||
const struct PeSectionHeader *sect = section_table + i;
|
||||
|
||||
for (UINTN j = 0; sections[j]; j++) {
|
||||
if (CompareMem(sect->Name, sections[j], strlena(sections[j])) != 0)
|
||||
if (CompareMem(sect->Name, sections[j], strlen8((const char *) sections[j])) != 0)
|
||||
continue;
|
||||
|
||||
if (addrs)
|
||||
|
||||
@@ -220,7 +220,7 @@ static void validate_sha256(void) {
|
||||
uint8_t result[HASH_VALUE_SIZE];
|
||||
|
||||
sha256_init_ctx(&hash);
|
||||
sha256_process_bytes(array[i].string, strlena((const CHAR8*) array[i].string), &hash);
|
||||
sha256_process_bytes(array[i].string, strlen8(array[i].string), &hash);
|
||||
sha256_finish_ctx(&hash, result);
|
||||
|
||||
assert(CompareMem(result, array[i].hash, HASH_VALUE_SIZE) == 0);
|
||||
|
||||
+3
-16
@@ -306,7 +306,7 @@ CHAR16 *xstra_to_str(const CHAR8 *stra) {
|
||||
|
||||
assert(stra);
|
||||
|
||||
len = strlena(stra);
|
||||
len = strlen8((const char *) stra);
|
||||
str = xnew(CHAR16, len + 1);
|
||||
|
||||
strlen = 0;
|
||||
@@ -336,7 +336,7 @@ CHAR16 *xstra_to_path(const CHAR8 *stra) {
|
||||
|
||||
assert(stra);
|
||||
|
||||
len = strlena(stra);
|
||||
len = strlen8((const char *) stra);
|
||||
str = xnew(CHAR16, len + 2);
|
||||
|
||||
str[0] = '\\';
|
||||
@@ -572,19 +572,6 @@ EFI_STATUS readdir_harder(
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
UINTN strnlena(const CHAR8 *p, UINTN maxlen) {
|
||||
UINTN c;
|
||||
|
||||
if (!p)
|
||||
return 0;
|
||||
|
||||
for (c = 0; c < maxlen; c++)
|
||||
if (p[c] == 0)
|
||||
break;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
INTN strncasecmpa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen) {
|
||||
if (!a || !b)
|
||||
return CMP(a, b);
|
||||
@@ -615,7 +602,7 @@ CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz) {
|
||||
|
||||
assert(p || sz == 0);
|
||||
|
||||
sz = strnlena(p, sz);
|
||||
sz = strnlen8((const char *) p, sz);
|
||||
|
||||
n = xallocate_pool(sz + 1);
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@ EFI_STATUS get_file_info_harder(EFI_FILE *handle, EFI_FILE_INFO **ret, UINTN *re
|
||||
|
||||
EFI_STATUS readdir_harder(EFI_FILE *handle, EFI_FILE_INFO **buffer, UINTN *buffer_size);
|
||||
|
||||
UINTN strnlena(const CHAR8 *p, UINTN maxlen);
|
||||
CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz);
|
||||
INTN strncasecmpa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen);
|
||||
static inline BOOLEAN strncaseeqa(const CHAR8 *a, const CHAR8 *b, UINTN maxlen) {
|
||||
|
||||
@@ -2,23 +2,24 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef SD_BOOT
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
# include <efi.h>
|
||||
# include <efilib.h>
|
||||
# include "efi-string.h"
|
||||
#else
|
||||
#include <string.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include "macro-fundamental.h"
|
||||
|
||||
#ifdef SD_BOOT
|
||||
#define strlen(a) StrLen((a))
|
||||
#define strcmp(a, b) StrCmp((a), (b))
|
||||
#define strncmp(a, b, n) StrnCmp((a), (b), (n))
|
||||
#define strcasecmp(a, b) StriCmp((a), (b))
|
||||
#define STR_C(str) (L ## str)
|
||||
#define memcmp(a, b, n) CompareMem(a, b, n)
|
||||
# define strlen(a) strlen16((a))
|
||||
# define strcmp(a, b) StrCmp((a), (b))
|
||||
# define strncmp(a, b, n) StrnCmp((a), (b), (n))
|
||||
# define strcasecmp(a, b) StriCmp((a), (b))
|
||||
# define STR_C(str) (L ## str)
|
||||
# define memcmp(a, b, n) CompareMem(a, b, n)
|
||||
#else
|
||||
#define STR_C(str) (str)
|
||||
# define STR_C(str) (str)
|
||||
#endif
|
||||
|
||||
#define streq(a,b) (strcmp((a),(b)) == 0)
|
||||
|
||||
Reference in New Issue
Block a user