diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2006-12-04 10:32:48 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2006-12-04 10:32:48 +0000 |
commit | 7629179cc5c88d8207a43282134d3d767121ce39 (patch) | |
tree | d70dfa22b734632ffcdb5fdc796b72264b1e9676 | |
parent | 82e8182e3e9aa64ea7f3ef8cc2cd652927f8fb7c (diff) | |
download | perl-URPM-7629179cc5c88d8207a43282134d3d767121ce39.tar perl-URPM-7629179cc5c88d8207a43282134d3d767121ce39.tar.gz perl-URPM-7629179cc5c88d8207a43282134d3d767121ce39.tar.bz2 perl-URPM-7629179cc5c88d8207a43282134d3d767121ce39.tar.xz perl-URPM-7629179cc5c88d8207a43282134d3d767121ce39.zip |
- much stricter synthesis parsing. fail on first error
- add test using a buggy synthesis that occured on kenobi
-rw-r--r-- | URPM.xs | 19 | ||||
-rw-r--r-- | t/buggy_synthesis.cz | bin | 0 -> 40711 bytes | |||
-rw-r--r-- | t/empty_synthesis.cz | bin | 0 -> 20 bytes | |||
-rw-r--r-- | t/synthesis.t | 27 |
4 files changed, 31 insertions, 15 deletions
@@ -979,14 +979,16 @@ call_package_callback(SV *urpm, SV *sv_pkg, SV *callback) { return sv_pkg != NULL; } -static void +static int parse_line(AV *depslist, HV *provides, URPM__Package pkg, char *buff, SV *urpm, SV *callback) { SV *sv_pkg; URPM__Package _pkg; char *tag, *data; int data_len; - if ((tag = strchr(buff, '@')) != NULL && (data = strchr(tag+1, '@')) != NULL) { + if (buff[0] == 0) { + return 1; + } else if ((tag = buff)[0] == '@' && (data = strchr(tag+1, '@')) != NULL) { *tag++ = *data++ = 0; data_len = 1+strlen(data); if (!strcmp(tag, "info")) { @@ -1011,6 +1013,10 @@ parse_line(AV *depslist, HV *provides, URPM__Package pkg, char *buff, SV *urpm, } else if (!strcmp(tag, "summary")) { free(pkg->summary); pkg->summary = memcpy(malloc(data_len), data, data_len); } + return 1; + } else { + fprintf(stderr, "bad line <%s>\n", buff); + return 0; } } @@ -3031,6 +3037,7 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) memset(&pkg, 0, sizeof(struct s_Package)); buff[sizeof(buff)-1] = 0; p = buff; + int ok = 1; while ((buff_len = gzread(f, p, sizeof(buff)-1-(p-buff))) >= 0 && (buff_len += p-buff)) { buff[buff_len] = 0; @@ -3038,15 +3045,17 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) if ((eol = strchr(p, '\n')) != NULL) { do { *eol++ = 0; - parse_line(depslist, provides, &pkg, p, urpm, callback); + if (!parse_line(depslist, provides, &pkg, p, urpm, callback)) { ok = 0; break; } p = eol; } while ((eol = strchr(p, '\n')) != NULL); } else { /* a line larger than sizeof(buff) has been encountered, bad file problably */ + fprintf(stderr, "invalid line <%s>\n", p); + ok = 0; break; } if (gzeof(f)) { - parse_line(depslist, provides, &pkg, p, urpm, callback); + if (!parse_line(depslist, provides, &pkg, p, urpm, callback)) ok = 0; break; } else { /* move the remaining non-complete-line at beginning */ @@ -3055,7 +3064,7 @@ Urpm_parse_synthesis__XS(urpm, filename, ...) p = &buff[buff_len-(p-buff)]; } } - int ok = gzclose(f) == 0; + if (gzclose(f) != 0) ok = 0; SPAGAIN; if (ok) { XPUSHs(sv_2mortal(newSViv(start_id))); diff --git a/t/buggy_synthesis.cz b/t/buggy_synthesis.cz Binary files differnew file mode 100644 index 0000000..fa1f68d --- /dev/null +++ b/t/buggy_synthesis.cz diff --git a/t/empty_synthesis.cz b/t/empty_synthesis.cz Binary files differnew file mode 100644 index 0000000..8aee682 --- /dev/null +++ b/t/empty_synthesis.cz diff --git a/t/synthesis.t b/t/synthesis.t index 4050493..f44e769 100644 --- a/t/synthesis.t +++ b/t/synthesis.t @@ -2,19 +2,19 @@ use strict ; use warnings ; -use Test::More tests => 86; +use Test::More tests => 88; use URPM; my $file1 = 'synthesis.sample.cz'; open my $f, "| gzip -9 >$file1"; -print $f q{ -glibc-devel@provides@glibc-devel == 6:2.2.4-25mdk -glibc-devel@requires@/sbin/install-info@glibc == 2.2.4@kernel-headers@kernel-headers >= 2.2.1@/bin/sh@/bin/sh@/bin/sh@rpmlib(PayloadFilesHavePrefix) <= 4.0-1@rpmlib(CompressedFileNames) <= 3.0.4-1 -glibc-devel@conflicts@texinfo < 3.11@gcc < 2.96-0.50mdk -glibc-devel@obsoletes@libc-debug@libc-headers@libc-devel@linuxthreads-devel@glibc-debug -glibc-devel@info@glibc-devel-2.2.4-25mdk.i586@6@45692097@Development/C -}; +print $f <<'EOF'; +@provides@glibc-devel == 6:2.2.4-25mdk +@requires@/sbin/install-info@glibc == 2.2.4@kernel-headers@kernel-headers >= 2.2.1@/bin/sh@/bin/sh@/bin/sh@rpmlib(PayloadFilesHavePrefix) <= 4.0-1@rpmlib(CompressedFileNames) <= 3.0.4-1 +@conflicts@texinfo < 3.11@gcc < 2.96-0.50mdk +@obsoletes@libc-debug@libc-headers@libc-devel@linuxthreads-devel@glibc-debug +@info@glibc-devel-2.2.4-25mdk.i586@6@45692097@Development/C +EOF close $f; END { unlink $file1 } @@ -22,9 +22,16 @@ END { unlink $file1 } my $a = new URPM; ok($a); -my ($first, $end) = $a->parse_synthesis($file1); +my ($first, $end); + +($first, $end) = URPM->new->parse_synthesis('t/empty_synthesis.cz'); +is("$first $end", "0 -1", 'parse empty synthesis'); + +is(URPM->new->parse_synthesis('t/buggy_synthesis.cz'), undef, 'parse buggy synthesis'); + +($first, $end) = $a->parse_synthesis($file1); ok($first == 0 && $end == 0); -ok(@{$a->{depslist}} == 1); +is(int @{$a->{depslist}}, 1); ok(keys(%{$a->{provides}}) == 3); ok(defined $a->{provides}{'glibc-devel'}); ok(exists $a->{provides}{'/bin/sh'}); |