summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorse <se@FreeBSD.org>1999-08-02 17:50:07 +0000
committerse <se@FreeBSD.org>1999-08-02 17:50:07 +0000
commit5efdb8aee5bbe722a6bdb059f6a616f86509b0c6 (patch)
tree69df2b11fca8bfdb5e58974d5d3081e97cad67e2 /usr.sbin
parentd3b550b2243a7c136fd4be3e4949f6837e4715e4 (diff)
downloadFreeBSD-src-5efdb8aee5bbe722a6bdb059f6a616f86509b0c6.zip
FreeBSD-src-5efdb8aee5bbe722a6bdb059f6a616f86509b0c6.tar.gz
Remove accidental 8bit character in error message.
Add checks for malloc failure and add error exit in case of malloc failure. Add rcsid. Submitted by: charnier
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/elf2exe/elf2exe.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/usr.sbin/elf2exe/elf2exe.c b/usr.sbin/elf2exe/elf2exe.c
index 92919ed..c778299 100644
--- a/usr.sbin/elf2exe/elf2exe.c
+++ b/usr.sbin/elf2exe/elf2exe.c
@@ -22,16 +22,19 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $Id$
*/
/*
* Make an ARC firmware executable from an ELF file.
*/
-#include <sys/types.h>
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+#include <sys/types.h>
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -154,6 +157,8 @@ find_shstrtable(int fileno, int sections, Elf64_Shdr *shdr)
shstrtabindex = i;
shstrtab = malloc(shdr[shstrtabindex].sh_size);
+ if (shstrtab == NULL)
+ errx(1, "malloc failed");
lseek(fileno, shdr[shstrtabindex].sh_offset, SEEK_SET);
read(fileno, shstrtab, shdr[shstrtabindex].sh_size);
@@ -243,6 +248,13 @@ section_fpos(Elf64_Shdr *shdr, int sections, char *name)
return shdr[i].sh_offset;
}
+void
+usage(void)
+{
+ fprintf(stderr, "usage: elf2exe infile outfile\n");
+ exit(1);
+}
+
int
main(int argc, char** argv)
{
@@ -262,13 +274,13 @@ main(int argc, char** argv)
int sections;
if (argc != 3)
- errx(1, "usage: elf2exe <infile> <outfile>");
+ usage();
infd = open_elffile(argv[1]);
ehdr = load_ehdr(infd);
if (ehdr == NULL)
- errx(1, "canīt read Elf Header\n");
+ errx(1, "cannot read Elf Header\n");
sections = ehdr->e_shnum;
progentry = ehdr->e_entry;
@@ -361,6 +373,8 @@ main(int argc, char** argv)
lseek(outfd, textscn.s_scnptr, SEEK_SET);
p = malloc(ROUNDUP(textsize, 512));
+ if (p == NULL)
+ errx(1, "malloc failed");
memset(p, 0, ROUNDUP(textsize, 512));
lseek(infd, textfpos, SEEK_SET);
read(infd, p, textsize);
@@ -369,6 +383,8 @@ main(int argc, char** argv)
lseek(outfd, datascn.s_scnptr, SEEK_SET);
p = malloc(ROUNDUP(datasize, 512));
+ if (p == NULL)
+ errx(1, "malloc failed");
memset(p, 0, ROUNDUP(datasize, 512));
lseek(infd, datafpos, SEEK_SET);
read(infd, p, datasize);
OpenPOWER on IntegriCloud