Просмотр исходного кода

libdpkg: Do not segfault on varbufdupc after extending the buffer

Store the old used size instead of the precomputed address, as
varbufextend might change the buffer from under us.
Guillem Jover лет назад: 18
Родитель
Сommit
b3e03cf33b
2 измененных файлов с 9 добавлено и 2 удалено
  1. 6 0
      ChangeLog
  2. 3 2
      lib/varbuf.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2008-06-19  Guillem Jover  <guillem@debian.org>
+
+	* lib/varbuf.c (varbufdupc): Store the old used size instead of the
+	precomputed address, as varbufextend might change the buffer from
+	under us.
+
 2008-06-17  Guillem Jover  <guillem@debian.org>
 
 	* scripts/dpkg-divert.pl: Do not silently force --rename on --remove.

+ 3 - 2
lib/varbuf.c

@@ -35,11 +35,12 @@ varbufaddc(struct varbuf *v, int c)
 }
 
 void varbufdupc(struct varbuf *v, int c, ssize_t n) {
-  char *b = v->buf + v->used;
+  size_t old_used = v->used;
+
   v->used += n;
   if (v->used >= v->size) varbufextend(v);
 
-  memset(b, c, n);
+  memset(v->buf + old_used, c, n);
 }
 
 int varbufprintf(struct varbuf *v, const char *fmt, ...) {