@@ -90,6 +90,7 @@ int main(int argc, char *argv[])
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{"list-bits", no_argument, NULL, 'b'},
+ {NULL, 0, NULL, 0}
};
int c, oidx = 0;
@@ -21,7 +21,6 @@ static void print_usage(int code)
printf("\n");
printf(" NB: --list-bits shows which PPC bits are set\n");
exit(code);
- exit(code);
}
extern const char version[];
@@ -39,6 +38,8 @@ int main(int argc, char *argv[])
{"chip", required_argument, NULL, 'c'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
+ {"list-bits", no_argument, NULL, 'b'},
+ {NULL, 0, NULL, 0}
};
int c, oidx = 0;
@@ -20,6 +20,7 @@
#include <dirent.h>
#include <assert.h>
#include <ctype.h>
+#include <limits.h>
#include "xscom.h"
@@ -42,7 +43,7 @@ void xscom_for_each_chip(void (*cb)(uint32_t chip_id))
static uint32_t xscom_add_chip(const char *base_path, const char *dname)
{
- char nbuf[strlen(base_path) + strlen(dname) + 16];
+ char nbuf[PATH_MAX];
struct xscom_chip *chip;
int fd;
This patch resolves a memory safety bug and applies several hardening fixes and code cleanups to the xscom-utils binaries: - Add {NULL, 0, NULL, 0} to the long_opts arrays in getscom.c and putscom.c. getopt_long() relies on this zeroed struct to terminate its search. Without it, supplying an unrecognized long argument causes an out-of-bounds read into adjacent stack memory. - Replace Variable-Length Array in xscom_add_chip() with a PATH_MAX buffer. Add <limits.h> header to provide PATH_MAX. - Wire up missing {"list-bits", ...} entry in putscom.c's long_opts array. Previously, the tool advertised --list-bits in its help text and parsed the short '-b' flag, but failed to parse the long option. - Remove a duplicate exit(code); call in putscom.c's print_usage() function. Signed-off-by: Nikhil Kumar Singh <nikhilks@linux.ibm.com> --- external/xscom-utils/getscom.c | 1 + external/xscom-utils/putscom.c | 3 ++- external/xscom-utils/xscom.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-)