Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions system.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *msg)
{
void *c;
char line[256];
char line[512];
char *key, *val, *next;
const char *rootfs_type = system_rootfs_type();
struct utsname utsname;
Expand All @@ -145,19 +145,27 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
key = strtok(line, "\t:");
val = strtok(NULL, "\t\n");

if (!key || !val)
if (!key || !val || strlen(val) < 3)
continue;

val += 2;

#ifdef __aarch64__
if (!strcasecmp(key, "CPU revision")) {
snprintf(line, sizeof(line), "ARMv8 Processor rev %lu", strtoul(val + 2, NULL, 16));
snprintf(line, sizeof(line), "ARMv8 Processor rev %lu", strtoul(val, NULL, 16));
blobmsg_add_string(&b, "system", line);
break;
}
#elif __riscv
if (!strcasecmp(key, "isa")) {
snprintf(line, sizeof(line), "RISC-V (%s)", val + 2);
blobmsg_add_string(&b, "system", line);
char *tmp = val;
while (*tmp++)
if (*tmp == '_')
*tmp = ' ';

char buf[512];
snprintf(buf, sizeof(buf), "RISC-V (%s)", val);
blobmsg_add_string(&b, "system", buf);
break;
}
#else
Expand All @@ -166,11 +174,11 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
!strcasecmp(key, "cpu") ||
!strcasecmp(key, "model name"))
{
strtoul(val + 2, &key, 0);
strtoul(val, &key, 0);

if (key == (val + 2) || *key != 0)
if (key == (val) || *key != 0)
{
blobmsg_add_string(&b, "system", val + 2);
blobmsg_add_string(&b, "system", val);
break;
}
}
Expand Down Expand Up @@ -200,13 +208,15 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
key = strtok(line, "\t:");
val = strtok(NULL, "\t\n");

if (!key || !val)
if (!key || !val || strlen(val) < 3)
continue;

val += 2;

if (!strcasecmp(key, "machine") ||
!strcasecmp(key, "hardware"))
{
blobmsg_add_string(&b, "model", val + 2);
blobmsg_add_string(&b, "model", val);
break;
}
}
Expand Down
Loading