[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] poke: Handle the absence of current IOS in map command
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH] poke: Handle the absence of current IOS in map command |
Date: |
Sat, 27 Feb 2021 03:43:50 +0330 |
2021-02-27 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
* poke/pk-cmd-map.c (CUR_IOS_ID): Add new macro to find the current
IOS id.
(pk_cmd_map_create): Use `CUR_IOS_ID` macro.
(pk_cmd_map_remove): Likewise.
(pk_cmd_map_show): Likewise.
(pk_cmd_map_entry_add): Likewise.
(pk_cmd_map_entry_remove): Likewise.
(pk_cmd_map_load): Likewise.
(pk_cmd_info_maps): Likewise.
---
Hi, Jose.
Fix segmentation faults of `.map` commands when there's no IOS.
Reported by `Foxboron` on `#poke` channel.
I think this also should be committed on maint/poke-1.
(And sorry for not including the tests).
Regards,
Mohammad-Reza
ChangeLog | 12 ++++++++++++
poke/pk-cmd-map.c | 39 ++++++++++++++++++++++-----------------
2 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6ef48bea..e2ab6c43 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-02-27 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
+
+ * poke/pk-cmd-map.c (CUR_IOS_ID): Add new macro to find the current
+ IOS id.
+ (pk_cmd_map_create): Use `CUR_IOS_ID` macro.
+ (pk_cmd_map_remove): Likewise.
+ (pk_cmd_map_show): Likewise.
+ (pk_cmd_map_entry_add): Likewise.
+ (pk_cmd_map_entry_remove): Likewise.
+ (pk_cmd_map_load): Likewise.
+ (pk_cmd_info_maps): Likewise.
+
2021-02-26 Egeyar Bagcioglu <egeyar@gmail.com>
* libpoke/ios-dev-file.c (ios_dev_file_handler_normalize): Take error
diff --git a/poke/pk-cmd-map.c b/poke/pk-cmd-map.c
index 9675ae0f..eb2aa53e 100644
--- a/poke/pk-cmd-map.c
+++ b/poke/pk-cmd-map.c
@@ -27,6 +27,21 @@
#include "pk-map.h"
#include "pk-table.h"
+#define CUR_IOS_ID(ios_id) \
+ do \
+ { \
+ pk_ios cur_ios = pk_ios_cur (poke_compiler); \
+ \
+ if (!cur_ios) \
+ { \
+ pk_printf (_ ("No current IOS\n")); \
+ return 0; \
+ } \
+ \
+ ios_id = pk_ios_get_id (cur_ios); \
+ } \
+ while (0)
+
static int
pk_cmd_map_create (int argc, struct pk_cmd_arg argv[], uint64_t uflags)
{
@@ -47,17 +62,7 @@ pk_cmd_map_create (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
}
if (PK_CMD_ARG_TYPE (argv[1]) == PK_CMD_ARG_NULL)
- {
- pk_ios cur_ios = pk_ios_cur (poke_compiler);
-
- if (!cur_ios)
- {
- pk_printf (_("No current IOS\n"));
- return 0;
- }
-
- ios_id = pk_ios_get_id (cur_ios);
- }
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[1]);
@@ -98,7 +103,7 @@ pk_cmd_map_remove (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
}
if (PK_CMD_ARG_TYPE (argv[1]) == PK_CMD_ARG_NULL)
- ios_id = pk_ios_get_id (pk_ios_cur (poke_compiler));
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[1]);
@@ -134,7 +139,7 @@ pk_cmd_map_show (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
assert (PK_CMD_ARG_TYPE (argv[0]) == PK_CMD_ARG_STR);
if (PK_CMD_ARG_TYPE (argv[1]) == PK_CMD_ARG_NULL)
- ios_id = pk_ios_get_id (pk_ios_cur (poke_compiler));
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[1]);
@@ -207,7 +212,7 @@ pk_cmd_map_entry_add (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
varname = PK_CMD_ARG_STR (argv[1]);
if (PK_CMD_ARG_TYPE (argv[2]) == PK_CMD_ARG_NULL)
- ios_id = pk_ios_get_id (pk_ios_cur (poke_compiler));
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[2]);
@@ -276,7 +281,7 @@ pk_cmd_map_entry_remove (int argc, struct pk_cmd_arg
argv[], uint64_t uflags)
entryname = PK_CMD_ARG_STR (argv[1]);
if (PK_CMD_ARG_TYPE (argv[2]) == PK_CMD_ARG_NULL)
- ios_id = pk_ios_get_id (pk_ios_cur (poke_compiler));
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[2]);
@@ -319,7 +324,7 @@ pk_cmd_map_load (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
mapname = PK_CMD_ARG_STR (argv[0]);
if (PK_CMD_ARG_TYPE (argv[1]) == PK_CMD_ARG_NULL)
- ios_id = pk_ios_get_id (pk_ios_cur (poke_compiler));
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[1]);
@@ -371,7 +376,7 @@ pk_cmd_info_maps (int argc, struct pk_cmd_arg argv[],
uint64_t uflags)
assert (argc == 1);
if (PK_CMD_ARG_TYPE (argv[0]) == PK_CMD_ARG_NULL)
- ios_id = pk_ios_get_id (pk_ios_cur (poke_compiler));
+ CUR_IOS_ID (ios_id);
else
{
ios_id = PK_CMD_ARG_TAG (argv[0]);
--
2.30.1
- [PATCH] poke: Handle the absence of current IOS in map command,
Mohammad-Reza Nabipoor <=