|
|
e6b270b |
From 3afc4c0ed28d443bb71956b07fd45c8cfb07566f Mon Sep 17 00:00:00 2001
|
|
|
e6b270b |
From: Nathaniel McCallum <npmccallum@redhat.com>
|
|
|
e6b270b |
Date: Fri, 2 Mar 2018 14:59:32 -0500
|
|
|
e6b270b |
Subject: [PATCH 2/8] Change return type in getRootSpecifier()
|
|
|
e6b270b |
|
|
|
e6b270b |
Rather than returning a new allocation of the prefix, just return the
|
|
|
e6b270b |
length of the prefix. This change accomplishes a couple things. First,
|
|
|
e6b270b |
it reduces some memory leaks since the return value was often never
|
|
|
e6b270b |
freed. Second, it simplifies the caller who is usually only interested
|
|
|
e6b270b |
in the length of the prefix.
|
|
|
e6b270b |
---
|
|
|
e6b270b |
grubby.c | 54 +++++++++++++++++++++++++++---------------------------
|
|
|
e6b270b |
1 file changed, 27 insertions(+), 27 deletions(-)
|
|
|
e6b270b |
|
|
|
e6b270b |
diff --git a/grubby.c b/grubby.c
|
|
|
e6b270b |
index d4ebb86168d..a062ef8e567 100644
|
|
|
e6b270b |
--- a/grubby.c
|
|
|
e6b270b |
+++ b/grubby.c
|
|
|
e6b270b |
@@ -675,7 +675,7 @@ static int lineWrite(FILE * out, struct singleLine * line,
|
|
|
e6b270b |
struct configFileInfo * cfi);
|
|
|
e6b270b |
static int getNextLine(char ** bufPtr, struct singleLine * line,
|
|
|
e6b270b |
struct configFileInfo * cfi);
|
|
|
e6b270b |
-static char * getRootSpecifier(char * str);
|
|
|
e6b270b |
+static size_t getRootSpecifier(const char *str);
|
|
|
e6b270b |
static void requote(struct singleLine *line, struct configFileInfo * cfi);
|
|
|
e6b270b |
static void insertElement(struct singleLine * line,
|
|
|
e6b270b |
const char * item, int insertHere,
|
|
|
e6b270b |
@@ -1840,7 +1840,7 @@ int suitableImage(struct singleEntry * entry, const char * bootPrefix,
|
|
|
e6b270b |
char * fullName;
|
|
|
e6b270b |
int i;
|
|
|
e6b270b |
char * dev;
|
|
|
e6b270b |
- char * rootspec;
|
|
|
e6b270b |
+ size_t rs;
|
|
|
e6b270b |
char * rootdev;
|
|
|
e6b270b |
|
|
|
e6b270b |
if (skipRemoved && entry->skip) {
|
|
|
e6b270b |
@@ -1866,12 +1866,11 @@ int suitableImage(struct singleEntry * entry, const char * bootPrefix,
|
|
|
e6b270b |
|
|
|
e6b270b |
fullName = alloca(strlen(bootPrefix) +
|
|
|
e6b270b |
strlen(line->elements[1].item) + 1);
|
|
|
e6b270b |
- rootspec = getRootSpecifier(line->elements[1].item);
|
|
|
e6b270b |
- int rootspec_offset = rootspec ? strlen(rootspec) : 0;
|
|
|
e6b270b |
+ rs = getRootSpecifier(line->elements[1].item);
|
|
|
e6b270b |
int hasslash = endswith(bootPrefix, '/') ||
|
|
|
e6b270b |
- beginswith(line->elements[1].item + rootspec_offset, '/');
|
|
|
e6b270b |
+ beginswith(line->elements[1].item + rs, '/');
|
|
|
e6b270b |
sprintf(fullName, "%s%s%s", bootPrefix, hasslash ? "" : "/",
|
|
|
e6b270b |
- line->elements[1].item + rootspec_offset);
|
|
|
e6b270b |
+ line->elements[1].item + rs);
|
|
|
e6b270b |
if (access(fullName, R_OK)) {
|
|
|
e6b270b |
notSuitablePrintf(entry, 0, "access to %s failed\n", fullName);
|
|
|
e6b270b |
return 0;
|
|
|
e6b270b |
@@ -1952,7 +1951,6 @@ struct singleEntry * findEntryByPath(struct grubConfig * config,
|
|
|
e6b270b |
struct singleLine * line;
|
|
|
e6b270b |
int i;
|
|
|
e6b270b |
char * chptr;
|
|
|
e6b270b |
- char * rootspec = NULL;
|
|
|
e6b270b |
enum lineType_e checkType = LT_KERNEL;
|
|
|
e6b270b |
|
|
|
e6b270b |
if (isdigit(*kernel)) {
|
|
|
e6b270b |
@@ -2044,11 +2042,10 @@ struct singleEntry * findEntryByPath(struct grubConfig * config,
|
|
|
e6b270b |
|
|
|
e6b270b |
if (line && line->type != LT_MENUENTRY &&
|
|
|
e6b270b |
line->numElements >= 2) {
|
|
|
e6b270b |
- rootspec = getRootSpecifier(line->elements[1].item);
|
|
|
e6b270b |
- if (!strcmp(line->elements[1].item +
|
|
|
e6b270b |
- ((rootspec != NULL) ? strlen(rootspec) : 0),
|
|
|
e6b270b |
- kernel + strlen(prefix)))
|
|
|
e6b270b |
- break;
|
|
|
e6b270b |
+ if (!strcmp(line->elements[1].item +
|
|
|
e6b270b |
+ getRootSpecifier(line->elements[1].item),
|
|
|
e6b270b |
+ kernel + strlen(prefix)))
|
|
|
e6b270b |
+ break;
|
|
|
e6b270b |
}
|
|
|
e6b270b |
if(line->type == LT_MENUENTRY &&
|
|
|
e6b270b |
!strcmp(line->elements[1].item, kernel))
|
|
|
e6b270b |
@@ -2797,11 +2794,11 @@ struct singleLine * addLineTmpl(struct singleEntry * entry,
|
|
|
e6b270b |
|
|
|
e6b270b |
/* but try to keep the rootspec from the template... sigh */
|
|
|
e6b270b |
if (tmplLine->type & (LT_HYPER|LT_KERNEL|LT_MBMODULE|LT_INITRD|LT_KERNEL_EFI|LT_INITRD_EFI|LT_KERNEL_16|LT_INITRD_16)) {
|
|
|
e6b270b |
- char * rootspec = getRootSpecifier(tmplLine->elements[1].item);
|
|
|
e6b270b |
- if (rootspec != NULL) {
|
|
|
e6b270b |
- free(newLine->elements[1].item);
|
|
|
e6b270b |
- newLine->elements[1].item =
|
|
|
e6b270b |
- sdupprintf("%s%s", rootspec, val);
|
|
|
e6b270b |
+ size_t rs = getRootSpecifier(tmplLine->elements[1].item);
|
|
|
e6b270b |
+ if (rs > 0) {
|
|
|
e6b270b |
+ free(newLine->elements[1].item);
|
|
|
e6b270b |
+ newLine->elements[1].item = sdupprintf("%.*s%s", (int) rs,
|
|
|
e6b270b |
+ tmplLine->elements[1].item, val);
|
|
|
e6b270b |
}
|
|
|
e6b270b |
}
|
|
|
e6b270b |
}
|
|
|
e6b270b |
@@ -3729,15 +3726,19 @@ int checkForElilo(struct grubConfig * config) {
|
|
|
e6b270b |
return 1;
|
|
|
e6b270b |
}
|
|
|
e6b270b |
|
|
|
e6b270b |
-static char * getRootSpecifier(char * str) {
|
|
|
e6b270b |
- char * idx, * rootspec = NULL;
|
|
|
e6b270b |
+static size_t getRootSpecifier(const char *str)
|
|
|
e6b270b |
+{
|
|
|
e6b270b |
+ size_t rs = 0;
|
|
|
e6b270b |
|
|
|
e6b270b |
if (*str == '(') {
|
|
|
e6b270b |
- idx = rootspec = strdup(str);
|
|
|
e6b270b |
- while(*idx && (*idx != ')') && (!isspace(*idx))) idx++;
|
|
|
e6b270b |
- *(++idx) = '\0';
|
|
|
e6b270b |
+ for (; str[rs] != ')' && !isspace(str[rs]); rs++) {
|
|
|
e6b270b |
+ if (!str[rs])
|
|
|
e6b270b |
+ return rs;
|
|
|
e6b270b |
+ }
|
|
|
e6b270b |
+ rs++;
|
|
|
e6b270b |
}
|
|
|
e6b270b |
- return rootspec;
|
|
|
e6b270b |
+
|
|
|
e6b270b |
+ return rs;
|
|
|
e6b270b |
}
|
|
|
e6b270b |
|
|
|
e6b270b |
static char * getInitrdVal(struct grubConfig * config,
|
|
|
e6b270b |
@@ -4616,7 +4617,7 @@ int main(int argc, const char ** argv) {
|
|
|
e6b270b |
if (displayDefault) {
|
|
|
e6b270b |
struct singleLine * line;
|
|
|
e6b270b |
struct singleEntry * entry;
|
|
|
e6b270b |
- char * rootspec;
|
|
|
e6b270b |
+ size_t rs;
|
|
|
e6b270b |
|
|
|
e6b270b |
if (config->defaultImage == -1) return 0;
|
|
|
e6b270b |
if (config->defaultImage == DEFAULT_SAVED_GRUB2 &&
|
|
|
e6b270b |
@@ -4629,9 +4630,8 @@ int main(int argc, const char ** argv) {
|
|
|
e6b270b |
line = getLineByType(LT_KERNEL|LT_HYPER|LT_KERNEL_EFI|LT_KERNEL_16, entry->lines);
|
|
|
e6b270b |
if (!line) return 0;
|
|
|
e6b270b |
|
|
|
e6b270b |
- rootspec = getRootSpecifier(line->elements[1].item);
|
|
|
e6b270b |
- printf("%s%s\n", bootPrefix, line->elements[1].item +
|
|
|
e6b270b |
- ((rootspec != NULL) ? strlen(rootspec) : 0));
|
|
|
e6b270b |
+ rs = getRootSpecifier(line->elements[1].item);
|
|
|
e6b270b |
+ printf("%s%s\n", bootPrefix, line->elements[1].item + rs);
|
|
|
e6b270b |
|
|
|
e6b270b |
return 0;
|
|
|
e6b270b |
|
|
|
e6b270b |
--
|
|
|
e6b270b |
2.17.1
|
|
|
e6b270b |
|