Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d642d48 authored by Jeremy Compostella's avatar Jeremy Compostella Committed by Mark Salyzyn
Browse files

libcutils: handle root directory empty path



Usually, the canned paths lack the leading '/' which means that the
root directory is an empty path.  This patch makes
load_canned_fs_config() handle this empty path as the root directory.
It also make it flexible enough to handle an optional leading '/'.

Original-Author: Jeremy Compostella <jeremy.compostella@intel.com>
Signed-off-by: default avatarJeremy Compostella <jeremy.compostella@intel.com>
Signed-off-by: default avatarGaelle Nassiet <gaellex.nassiet@intel.com>
Change-Id: Ice759ef37d1df23a54df1158ec0d3ad7f577a069
parent 8678872a
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
#include <errno.h>
#include <errno.h>
#include <inttypes.h>
#include <inttypes.h>
#include <limits.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
@@ -41,7 +42,7 @@ static int path_compare(const void* a, const void* b) {
}
}


int load_canned_fs_config(const char* fn) {
int load_canned_fs_config(const char* fn) {
    char line[PATH_MAX + 200];
    char buf[PATH_MAX + 200];
    FILE* f;
    FILE* f;


    f = fopen(fn, "r");
    f = fopen(fn, "r");
@@ -50,17 +51,21 @@ int load_canned_fs_config(const char* fn) {
        return -1;
        return -1;
    }
    }


    while (fgets(line, sizeof(line), f)) {
    while (fgets(buf, sizeof(buf), f)) {
        Path* p;
        Path* p;
        char* token;
        char* token;
        char* line = buf;
        bool rootdir;


        while (canned_used >= canned_alloc) {
        while (canned_used >= canned_alloc) {
            canned_alloc = (canned_alloc+1) * 2;
            canned_alloc = (canned_alloc+1) * 2;
            canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path));
            canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path));
        }
        }
        p = canned_data + canned_used;
        p = canned_data + canned_used;
        p->path = strdup(strtok(line, " "));
        if (line[0] == '/') line++;
        p->uid = atoi(strtok(NULL, " "));
        rootdir = line[0] == ' ';
        p->path = strdup(rootdir ? "" : strtok(line, " "));
        p->uid = atoi(strtok(rootdir ? line : NULL, " "));
        p->gid = atoi(strtok(NULL, " "));
        p->gid = atoi(strtok(NULL, " "));
        p->mode = strtol(strtok(NULL, " "), NULL, 8);   // mode is in octal
        p->mode = strtol(strtok(NULL, " "), NULL, 8);   // mode is in octal
        p->capabilities = 0;
        p->capabilities = 0;