|
|
3476ae |
From e44a22e2226a059bb46b06aae47a0f6d1c1284e9 Mon Sep 17 00:00:00 2001
|
|
|
3476ae |
From: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
|
|
|
3476ae |
Date: Tue, 7 May 2019 16:13:00 +0200
|
|
|
3476ae |
Subject: [PATCH] fix segfault when a value is missing from ibpi_str[]
|
|
|
3476ae |
|
|
|
3476ae |
Replace all usages of ibpi_str[] with ibpi2str(), which always returns a
|
|
|
3476ae |
valid string.
|
|
|
3476ae |
|
|
|
3476ae |
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
|
|
|
3476ae |
---
|
|
|
3476ae |
src/ibpi.h | 3 ++-
|
|
|
3476ae |
src/ledctl.c | 4 ++--
|
|
|
3476ae |
src/ledmon.c | 10 +++++-----
|
|
|
3476ae |
src/scsi.c | 2 +-
|
|
|
3476ae |
src/smp.c | 8 ++++----
|
|
|
3476ae |
src/sysfs.c | 2 +-
|
|
|
3476ae |
src/utils.c | 18 ++++++++++++++++++
|
|
|
3476ae |
src/utils.h | 4 ++++
|
|
|
3476ae |
9 files changed, 38 insertions(+), 15 deletions(-)
|
|
|
3476ae |
|
|
|
3476ae |
diff --git a/src/ibpi.h b/src/ibpi.h
|
|
|
3476ae |
index 776fba3..109f112 100644
|
|
|
3476ae |
--- a/src/ibpi.h
|
|
|
3476ae |
+++ b/src/ibpi.h
|
|
|
3476ae |
@@ -93,8 +93,9 @@ enum ibpi_pattern {
|
|
|
3476ae |
SES_REQ_DEV_OFF,
|
|
|
3476ae |
SES_REQ_FAULT,
|
|
|
3476ae |
SES_REQ_PRDFAIL,
|
|
|
3476ae |
+ ibpi_pattern_count,
|
|
|
3476ae |
};
|
|
|
3476ae |
|
|
|
3476ae |
-extern const char *ibpi_str[];
|
|
|
3476ae |
+extern const char *ibpi_str[ibpi_pattern_count];
|
|
|
3476ae |
|
|
|
3476ae |
#endif /* _IBPI_H_INCLUDED_ */
|
|
|
3476ae |
diff --git a/src/ledctl.c b/src/ledctl.c
|
|
|
3476ae |
index 2aa1abc..4dada8e 100644
|
|
|
3476ae |
--- a/src/ledctl.c
|
|
|
3476ae |
+++ b/src/ledctl.c
|
|
|
3476ae |
@@ -267,7 +267,7 @@ static void _determine(struct ibpi_state *state)
|
|
|
3476ae |
} else {
|
|
|
3476ae |
log_warning
|
|
|
3476ae |
("IBPI %s: missing block device(s)... pattern ignored.",
|
|
|
3476ae |
- ibpi_str[state->ibpi]);
|
|
|
3476ae |
+ ibpi2str(state->ibpi));
|
|
|
3476ae |
}
|
|
|
3476ae |
}
|
|
|
3476ae |
|
|
|
3476ae |
@@ -458,7 +458,7 @@ static status_t _ibpi_state_add_block(struct ibpi_state *state, char *name)
|
|
|
3476ae |
list_append(&state->block_list, blk1);
|
|
|
3476ae |
else
|
|
|
3476ae |
log_info("%s: %s: device already on the list.",
|
|
|
3476ae |
- ibpi_str[state->ibpi], path);
|
|
|
3476ae |
+ ibpi2str(state->ibpi), path);
|
|
|
3476ae |
return STATUS_SUCCESS;
|
|
|
3476ae |
}
|
|
|
3476ae |
|
|
|
3476ae |
diff --git a/src/ledmon.c b/src/ledmon.c
|
|
|
3476ae |
index 0ea2583..b775e6f 100644
|
|
|
3476ae |
--- a/src/ledmon.c
|
|
|
3476ae |
+++ b/src/ledmon.c
|
|
|
3476ae |
@@ -667,8 +667,8 @@ static void _add_block(struct block_device *block)
|
|
|
3476ae |
|
|
|
3476ae |
if (ibpi != temp->ibpi && ibpi <= IBPI_PATTERN_REMOVED) {
|
|
|
3476ae |
log_info("CHANGE %s: from '%s' to '%s'.",
|
|
|
3476ae |
- temp->sysfs_path, ibpi_str[ibpi],
|
|
|
3476ae |
- ibpi_str[temp->ibpi]);
|
|
|
3476ae |
+ temp->sysfs_path, ibpi2str(ibpi),
|
|
|
3476ae |
+ ibpi2str(temp->ibpi));
|
|
|
3476ae |
}
|
|
|
3476ae |
/* Check if name of the device changed.*/
|
|
|
3476ae |
if (strcmp(temp->sysfs_path, block->sysfs_path)) {
|
|
|
3476ae |
@@ -682,7 +682,7 @@ static void _add_block(struct block_device *block)
|
|
|
3476ae |
temp = block_device_duplicate(block);
|
|
|
3476ae |
if (temp != NULL) {
|
|
|
3476ae |
log_info("NEW %s: state '%s'.", temp->sysfs_path,
|
|
|
3476ae |
- ibpi_str[temp->ibpi]);
|
|
|
3476ae |
+ ibpi2str(temp->ibpi));
|
|
|
3476ae |
list_append(&ledmon_block_list, temp);
|
|
|
3476ae |
}
|
|
|
3476ae |
}
|
|
|
3476ae |
@@ -714,8 +714,8 @@ static void _send_msg(struct block_device *block)
|
|
|
3476ae |
block->ibpi == IBPI_PATTERN_REMOVED) {
|
|
|
3476ae |
if (block->ibpi != IBPI_PATTERN_FAILED_DRIVE) {
|
|
|
3476ae |
log_info("CHANGE %s: from '%s' to '%s'.",
|
|
|
3476ae |
- block->sysfs_path, ibpi_str[block->ibpi],
|
|
|
3476ae |
- ibpi_str[IBPI_PATTERN_FAILED_DRIVE]);
|
|
|
3476ae |
+ block->sysfs_path, ibpi2str(block->ibpi),
|
|
|
3476ae |
+ ibpi2str(IBPI_PATTERN_FAILED_DRIVE));
|
|
|
3476ae |
block->ibpi = IBPI_PATTERN_FAILED_DRIVE;
|
|
|
3476ae |
} else {
|
|
|
3476ae |
char *host = strstr(block->sysfs_path, "host");
|
|
|
3476ae |
diff --git a/src/scsi.c b/src/scsi.c
|
|
|
3476ae |
index 3267076..03b43dd 100644
|
|
|
3476ae |
--- a/src/scsi.c
|
|
|
3476ae |
+++ b/src/scsi.c
|
|
|
3476ae |
@@ -673,7 +673,7 @@ int scsi_ses_write(struct block_device *device, enum ibpi_pattern ibpi)
|
|
|
3476ae |
if (ret) {
|
|
|
3476ae |
log_warning
|
|
|
3476ae |
("Unable to send %s message to %s. Device is missing?",
|
|
|
3476ae |
- ibpi_str[ibpi], strstr(device->sysfs_path, "host"));
|
|
|
3476ae |
+ ibpi2str(ibpi), strstr(device->sysfs_path, "host"));
|
|
|
3476ae |
return ret;
|
|
|
3476ae |
}
|
|
|
3476ae |
|
|
|
3476ae |
diff --git a/src/smp.c b/src/smp.c
|
|
|
3476ae |
index 038fe02..6023b0a 100644
|
|
|
3476ae |
--- a/src/smp.c
|
|
|
3476ae |
+++ b/src/smp.c
|
|
|
3476ae |
@@ -468,16 +468,16 @@ int scsi_smp_fill_buffer(struct block_device *device, enum ibpi_pattern ibpi)
|
|
|
3476ae |
if (c++) {
|
|
|
3476ae |
log_debug
|
|
|
3476ae |
("pattern %s not supported for device (/dev/%s)",
|
|
|
3476ae |
- ibpi_str[ibpi], c);
|
|
|
3476ae |
+ ibpi2str(ibpi), c);
|
|
|
3476ae |
fprintf(stderr,
|
|
|
3476ae |
"%s(): pattern %s not supported for device (/dev/%s)\n",
|
|
|
3476ae |
- __func__, ibpi_str[ibpi], c);
|
|
|
3476ae |
+ __func__, ibpi2str(ibpi), c);
|
|
|
3476ae |
} else {
|
|
|
3476ae |
log_debug("pattern %s not supported for device %s",
|
|
|
3476ae |
- ibpi_str[ibpi], device->sysfs_path);
|
|
|
3476ae |
+ ibpi2str(ibpi), device->sysfs_path);
|
|
|
3476ae |
fprintf(stderr,
|
|
|
3476ae |
"%s(): pattern %s not supported for device\n\t(%s)\n",
|
|
|
3476ae |
- __func__, ibpi_str[ibpi], device->sysfs_path);
|
|
|
3476ae |
+ __func__, ibpi2str(ibpi), device->sysfs_path);
|
|
|
3476ae |
}
|
|
|
3476ae |
__set_errno_and_return(ENOTSUP);
|
|
|
3476ae |
}
|
|
|
3476ae |
diff --git a/src/sysfs.c b/src/sysfs.c
|
|
|
3476ae |
index 694878a..d4622dc 100644
|
|
|
3476ae |
--- a/src/sysfs.c
|
|
|
3476ae |
+++ b/src/sysfs.c
|
|
|
3476ae |
@@ -487,7 +487,7 @@ static void _set_block_state(struct block_device *block, enum ibpi_pattern ibpi)
|
|
|
3476ae |
char *debug_dev = strrchr(block->sysfs_path, '/');
|
|
|
3476ae |
debug_dev = debug_dev ? debug_dev + 1 : block->sysfs_path;
|
|
|
3476ae |
log_debug("(%s): device: %s, state: %s", __func__, debug_dev,
|
|
|
3476ae |
- ibpi_str[ibpi]);
|
|
|
3476ae |
+ ibpi2str(ibpi));
|
|
|
3476ae |
if (block->ibpi < ibpi)
|
|
|
3476ae |
block->ibpi = ibpi;
|
|
|
3476ae |
}
|
|
|
3476ae |
diff --git a/src/utils.c b/src/utils.c
|
|
|
3476ae |
index eb189b1..2920fba 100644
|
|
|
3476ae |
--- a/src/utils.c
|
|
|
3476ae |
+++ b/src/utils.c
|
|
|
3476ae |
@@ -616,3 +616,21 @@ status_t set_verbose_level(int log_level)
|
|
|
3476ae |
}
|
|
|
3476ae |
return STATUS_CMDLINE_ERROR;
|
|
|
3476ae |
}
|
|
|
3476ae |
+
|
|
|
3476ae |
+const char *ibpi2str(enum ibpi_pattern ibpi)
|
|
|
3476ae |
+{
|
|
|
3476ae |
+ static char buf[20];
|
|
|
3476ae |
+ const char *ret;
|
|
|
3476ae |
+
|
|
|
3476ae |
+ if (ibpi >= 0 && ibpi < ibpi_pattern_count)
|
|
|
3476ae |
+ ret = ibpi_str[ibpi];
|
|
|
3476ae |
+ else
|
|
|
3476ae |
+ ret = NULL;
|
|
|
3476ae |
+
|
|
|
3476ae |
+ if (!ret) {
|
|
|
3476ae |
+ snprintf(buf, sizeof(buf), "(unknown: %d)", ibpi);
|
|
|
3476ae |
+ ret = buf;
|
|
|
3476ae |
+ }
|
|
|
3476ae |
+
|
|
|
3476ae |
+ return ret;
|
|
|
3476ae |
+}
|
|
|
3476ae |
diff --git a/src/utils.h b/src/utils.h
|
|
|
3476ae |
index 720447a..67a211c 100644
|
|
|
3476ae |
--- a/src/utils.h
|
|
|
3476ae |
+++ b/src/utils.h
|
|
|
3476ae |
@@ -27,6 +27,7 @@
|
|
|
3476ae |
#include "list.h"
|
|
|
3476ae |
#include "status.h"
|
|
|
3476ae |
#include "syslog.h"
|
|
|
3476ae |
+#include "ibpi.h"
|
|
|
3476ae |
|
|
|
3476ae |
/**
|
|
|
3476ae |
* Maximum number of bytes in temporary buffer. It is used for local variables.
|
|
|
3476ae |
@@ -354,4 +355,7 @@ void setup_options(struct option **longopt, char **shortopt, int *options,
|
|
|
3476ae |
int options_nr);
|
|
|
3476ae |
int get_option_id(const char *optarg);
|
|
|
3476ae |
status_t set_verbose_level(int log_level);
|
|
|
3476ae |
+
|
|
|
3476ae |
+const char *ibpi2str(enum ibpi_pattern ibpi);
|
|
|
3476ae |
+
|
|
|
3476ae |
#endif /* _UTILS_H_INCLUDED_ */
|
|
|
3476ae |
--
|
|
|
3476ae |
2.20.1
|
|
|
3476ae |
|