summaryrefslogtreecommitdiffstats
path: root/usr.bin/brandelf/brandelf.c
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1997-02-09 20:35:54 +0000
committerjoerg <joerg@FreeBSD.org>1997-02-09 20:35:54 +0000
commitbd4abbf5cc3514deafffe6ed2a426721baf39557 (patch)
tree73ea711b2f13601b8c7bdce6f4fd70536bd81b0a /usr.bin/brandelf/brandelf.c
parentdf55a26f6588556d0f4d560fee27eaa42c78c122 (diff)
downloadFreeBSD-src-bd4abbf5cc3514deafffe6ed2a426721baf39557.zip
FreeBSD-src-bd4abbf5cc3514deafffe6ed2a426721baf39557.tar.gz
Add a manpage for brandelf(1). Minor stylistic fixes, and a buffer
overrun fix, too. Submitted by: John-Mark Gurney <jmg@nike.efn.org>
Diffstat (limited to 'usr.bin/brandelf/brandelf.c')
-rw-r--r--usr.bin/brandelf/brandelf.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/usr.bin/brandelf/brandelf.c b/usr.bin/brandelf/brandelf.c
index 6f04450..97da3e3 100644
--- a/usr.bin/brandelf/brandelf.c
+++ b/usr.bin/brandelf/brandelf.c
@@ -30,17 +30,19 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
#include <fcntl.h>
#include <sys/imgact_elf.h>
-int usage();
+int usage(void);
+int
main(int argc, char **argv)
{
- extern char *optarg;
- extern int optind;
- char type[10] = "FreeBSD";
+ const char *type = "FreeBSD";
+ int retval = 0;
int ch, change = 0, verbose = 0;
while ((ch = getopt(argc, argv, "t:v")) != EOF)
@@ -50,7 +52,7 @@ main(int argc, char **argv)
break;
case 't':
change = 1;
- strcpy(type, optarg);
+ type = optarg;
break;
default:
usage();
@@ -68,17 +70,20 @@ main(int argc, char **argv)
if ((fd = open(argv[0], O_RDWR, 0)) < 0) {
fprintf(stderr, "No such file %s.\n", argv[0]);
+ retval = 1;
goto fail;
}
if (read(fd, buffer, EI_NINDENT) < EI_NINDENT) {
fprintf(stderr, "File '%s' too short.\n", argv[0]);
+ retval = 1;
goto fail;
}
if (buffer[0] != ELFMAG0 || buffer[1] != ELFMAG1 ||
buffer[2] != ELFMAG2 || buffer[3] != ELFMAG3) {
fprintf(stderr, "File '%s' is not ELF format.\n",
argv[0]);
+ retval = 1;
goto fail;
}
if (!change) {
@@ -97,6 +102,7 @@ main(int argc, char **argv)
lseek(fd, 0, SEEK_SET);
if (write(fd, buffer, EI_NINDENT) != EI_NINDENT) {
fprintf(stderr, "Error writing %s\n", argv[0]);
+ retval = 1;
goto fail;
}
}
@@ -104,10 +110,13 @@ fail:
argc--;
argv++;
}
+
+ return retval;
}
int
-usage()
+usage(void)
{
fprintf(stderr, "Usage: brandelf [-t string] file ...\n");
+ exit(1);
}
OpenPOWER on IntegriCloud