From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Thu, 1 Sep 2011 13:47:00 -0400 Subject: [U-Boot] [PATCHv5] new tool mkenvimage: generates an env image from an arbitrary config file In-Reply-To: <1314892629-2002-1-git-send-email-david.wagner@free-electrons.com> References: <1312555798-29542-1-git-send-email-david.wagner@free-electrons.com> <1314892629-2002-1-git-send-email-david.wagner@free-electrons.com> Message-ID: <201109011347.01447.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thursday, September 01, 2011 11:57:09 David Wagner wrote: > + txt_filename = argv[optind]; > + if (strcmp(txt_filename, "-") == 0) { > + txt_fd = STDIN_FILENO; > + } else { > + txt_fd = open(txt_filename, O_RDONLY); > + if (txt_fd == -1) { > + fprintf(stderr, "Can't open \"%s\": %s\n", > + txt_filename, strerror(errno)); > + return EXIT_FAILURE; > + } > + } > + /* ... and check it */ > + ret = fstat(txt_fd, &txt_file_stat); > + if (ret == -1) { > + fprintf(stderr, "Can't stat() on \"%s\": " > + "%s\n", txt_filename, strerror(errno)); > + return EXIT_FAILURE; > + } > + /* > + * The right test to do is "=>" (not ">") because of the additionnal > + * ending \0. See below. > + */ > + if (txt_file_stat.st_size >= envsize) { > + fprintf(stderr, "The input file is larger than the " > + "envrionnment partition size\n"); > + return EXIT_FAILURE; > + } > + > + /* Read the raw input file and transform it */ > + filebuf = malloc(sizeof(*envptr) * txt_file_stat.st_size); > + ret = read(txt_fd, filebuf, sizeof(*envptr) * txt_file_stat.st_size); > + if (ret != txt_file_stat.st_size) { > + fprintf(stderr, "Can't read the whole input file\n"); > + return EXIT_FAILURE; > + } i think the stdin logic here is broken. when you fstat() stdin, you get back st_size == 0, and so you end up doing a read() on stdin of 0 bytes, and it writes out an empty image. simple test: echo foo=var | ./mkenvimage -s 0x1000 -o foo - hexdump -C foo running it through strace shows the bum read(0, "", 0) ... -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. Url : http://lists.denx.de/pipermail/u-boot/attachments/20110901/5e00bdeb/attachment.pgp