From d44406c4deb1789994c3b2c60ee0007dbfd6a438 Mon Sep 17 00:00:00 2001 From: Cyberjun Date: Sat, 31 May 2008 17:03:02 -0400 Subject: rpmoffset: cleanup and remove size limit on cpio offset Signed-off-by: Mike Frysinger --- rpmoffset.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/rpmoffset.c b/rpmoffset.c index 524e310..32ccba2 100644 --- a/rpmoffset.c +++ b/rpmoffset.c @@ -4,29 +4,38 @@ /* Wouldn't it be a lot more sane if we could just untar these things? */ +#include #include +#include -/* These offsets keep getting bigger, so we're going to just bite a 2MB */ -/* chunk of RAM right away so that we have enough. Yeah, horrible */ -/* quick and dirty implementation, but hey -- it gets the job done. */ +int main(int argc, char *argv[]) +{ + size_t i; + char p[3]; -#define RPMBUFSIZ 2097152 + if (argc != 1) { + puts("Usage: rpmoffset < rpmfile"); + return 1; + } -main() -{ - char *buff = malloc(RPMBUFSIZ),*eb,*p; - for (p = buff, eb = buff + read(0,buff,RPMBUFSIZ); p < eb; p++) - { - if (*p == '\037' && p[1] == '\213' && p[2] == '\010') - { - printf("%d\n",p - buff); - exit(0); - } - else if (*p == 'B' && p[1] == 'Z' && p[2] == 'h') - { - printf("%d\n",p - buff); - exit(0); - } - } - exit(1); + if (read(0,p,3) != 3) + return 2; + + for (i = 0; p[2] != 0 || p[2] != -1; ++i) { + if (p[0] == '\037' && p[1] == '\213' && p[2] == '\010') { + printf("%zu\n", i); + return 0; + + } else if (p[0] == 'B' && p[1] == 'Z' && p[2] == 'h') { + printf("%zu\n", i); + return 0; + } + + p[0] = p[1]; + p[1] = p[2]; + if (read(0, p+2, 1) != 1) + return 2; + } + + return 1; } -- cgit v1.2.3-65-gdbad