This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=2bc3077fbe930b06f0c3d4a9a5a5069a57392b4f

commit 2bc3077fbe930b06f0c3d4a9a5a5069a57392b4f
Author: Guillem Jover <[email protected]>
AuthorDate: Wed Jul 12 05:33:41 2023 +0200

    dpkg-split: Use varbuf instead of ad-hoc allocation in read_info
    
    Changelog: internal
---
 src/split/info.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/split/info.c b/src/split/info.c
index 73fbd69d4..eaf610cf3 100644
--- a/src/split/info.c
+++ b/src/split/info.c
@@ -85,8 +85,7 @@ static char *nextline(char **ripp, const char *fn, const char 
*what) {
 struct partinfo *
 read_info(struct dpkg_ar *ar, struct partinfo *ir)
 {
-  static char *readinfobuf= NULL;
-  static size_t readinfobuflen= 0;
+  static struct varbuf format_member = VARBUF_INIT;
 
   size_t thisilen;
   intmax_t templong;
@@ -117,27 +116,27 @@ read_info(struct dpkg_ar *ar, struct partinfo *ir)
     ohshit(_("file '%.250s' is corrupt - bad magic at end of first header"),
            ar->name);
   thisilen = dpkg_ar_member_get_size(ar, &arh);
-  if (thisilen >= readinfobuflen) {
-    readinfobuflen = thisilen + 2;
-    readinfobuf= m_realloc(readinfobuf,readinfobuflen);
-  }
-  rc = fd_read(ar->fd, readinfobuf, thisilen + (thisilen & 1));
+
+  varbuf_reset(&format_member);
+  varbuf_grow(&format_member, thisilen + 2);
+
+  rc = fd_read(ar->fd, format_member.buf, thisilen + (thisilen & 1));
   if (rc != (ssize_t)(thisilen + (thisilen & 1)))
     read_fail(rc, ar->name, "reading header member");
   if (thisilen & 1) {
-    int c = readinfobuf[thisilen];
+    int c = format_member.buf[thisilen];
 
     if (c != '\n')
       ohshit(_("file '%.250s' is corrupt - bad padding character (code %d)"),
              ar->name, c);
   }
-  readinfobuf[thisilen] = '\0';
-  if (memchr(readinfobuf,0,thisilen))
+  varbuf_trunc(&format_member, thisilen);
+  if (memchr(format_member.buf, 0, thisilen))
     ohshit(_("file '%.250s' is corrupt - nulls in info section"), ar->name);
 
   ir->filename = ar->name;
 
-  rip= readinfobuf;
+  rip = format_member.buf;
   err = deb_version_parse(&ir->fmtversion,
                           nextline(&rip, ar->name, _("format version 
number")));
   if (err)

-- 
Dpkg.Org's dpkg

Reply via email to