Description: Upstream fix for two CVEs
 r-cran-haven (1.1.1-2) unstable; urgency=medium
 .
   * Rebuilding for R 3.5.0 transition
 .
   * debian/control: Set Build-Depends: to current R version
   * debian/control: Set Build-Depends: to 'debhelper (>= 10)'
   * debian/control: Set Standards-Version: to current version
   * debian/control: Add Vcs-Browser: and Vcs-Git:
 .
   * src/readstat/sas/readstat_sas7bcat_read.c: Upstream ReadStat patch
   * src/readstat/spss/readstat_sav.c: Idem
   * src/readstat/spss/readstat_sav_read.c: Idem
Author: Dirk Eddelbuettel <edd@debian.org>

---
Origin: upstream, https://github.com/WizardMac/ReadStat/commit/8c09e2882739193780e4bd54ae530a0c8920eb70 and https://github.com/WizardMac/ReadStat/commit/a178d1f9c16a26a0a681972c13b6d596a36b0362
Bug-Debian: https://bugs.debian.org/899355
Forwarded: not-needed
Reviewed-By: Dirk Eddelbuettel
Last-Update: 2018-06-07

--- r-cran-haven-1.1.1.orig/src/readstat/sas/readstat_sas7bcat_read.c
+++ r-cran-haven-1.1.1/src/readstat/sas/readstat_sas7bcat_read.c
@@ -279,13 +279,14 @@ static readstat_error_t sas7bcat_read_bl
     readstat_io_t *io = ctx->io;
     int next_page = start_page;
     int next_page_pos = start_page_pos;
+    int link_count = 0;
 
     int chain_link_len = 0;
     int buffer_offset = 0;
 
     char chain_link[16];
 
-    while (next_page > 0 && next_page_pos > 0) {
+    while (next_page > 0 && next_page_pos > 0 && next_page <= ctx->page_count && link_count++ < ctx->page_count) {        
         if (io->seek(ctx->header_size+(next_page-1)*ctx->page_size+next_page_pos, READSTAT_SEEK_SET, io->io_ctx) == -1) {
             retval = READSTAT_ERROR_SEEK;
             goto cleanup;
--- r-cran-haven-1.1.1.orig/src/readstat/spss/readstat_sav.c
+++ r-cran-haven-1.1.1/src/readstat/spss/readstat_sav.c
@@ -77,9 +77,8 @@ void sav_ctx_free(sav_ctx_t *ctx) {
         free(ctx->raw_string);
     if (ctx->utf8_string)
         free(ctx->utf8_string);
-    if (ctx->converter) {
+    if (ctx->converter)
         iconv_close(ctx->converter);
-    }
     if (ctx->variable_display_values) {
         free(ctx->variable_display_values);
     }
--- r-cran-haven-1.1.1.orig/src/readstat/spss/readstat_sav_read.c
+++ r-cran-haven-1.1.1/src/readstat/spss/readstat_sav_read.c
@@ -861,6 +861,9 @@ static readstat_error_t sav_parse_machin
         if (converter == (iconv_t)-1) {
             return READSTAT_ERROR_UNSUPPORTED_CHARSET;
         }
+        if (ctx->converter) {
+            iconv_close(ctx->converter);
+        }
         ctx->converter = converter;
     }
     return READSTAT_OK;
