From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23629 invoked from network); 3 Oct 2023 00:27:55 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Oct 2023 00:27:55 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1696292875; b=VRLrvgkQ01Y/pNBrk9zee2Cuo1ZG050FoV3aSWY+qsfMmjlL0/WWWzuE61oqgD/lqvS357kqnm jBetnBA4nOnNzXUwbIr8anC7C4RkVV2/oXN5DXNPWtJMKOA7wW29A9KxL+q5RVN2+Vyk2viv9V aHIUQyKbjnZ1SaQE0LWU1kxjfc8WmG5oshn0w25vdWi/LsVLVfWB0Wfp024oL5GwRY/skvYeMo TA963YLxGgNwnXl5ES1zJq1dyYc2RtNgJvHoJwVxWTTQWhviluAXmPHj4TXrJoEtchGWuMALTD p5KnGMX7KGy31cfaFeeh9zWrlo0yiiLzv5iS5Up67H1sgg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f53.google.com) smtp.remote-ip=209.85.218.53; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1696292875; bh=GYmhjOb4UwH8V4JpNkKN1Puq7jZB03qdIpybNYWJ2qs=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=GrTF186e8ffY+RfQbaKvMvRZt+gVUYaBT8P/4ijLap6tivJJ9HFnAWLO9L3MOnS0U+wAAqypRA GhxDmBE3rGd2qhmc9pC56U17rTHeFEc5SoTsFfwbnSSoLTn8gIe4tSMJpUG0YnpPz3N5If7XIN 9zkMPkjKy/jPSBTZfuY4vm27LVoebGB++NK3TOCsoU4/mBq67UiLoekYUxygHtXQ3twQi8zKJm mQ8+l18KyHw7T2rq1bEuAZDnE5K4Y9kLQhMK1I6lQbVhQUbFClSUD5SoSLX6oSGg/yinX+9nZz m7IJ94Y695PaLjVZfL8A7flml+m4JxgOvTs+4F0knVPuQg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=EtlQDxyitSPVS8ZG4/rfMN2ATXOvQMLfJfUWhJzzpbs=; b=mSpI5x/erIJmppCXYsFQJK+wcg bdHS6Baus77SYVvsE2cDrI0LlhATstVWAWLHLvDHoMXsfcNq8LV0sqibWEVIuTprM8Pv8DsXyNBPU iLsBZov8EADKoJs8XD9QLuJzB/93HLpEqyjMiAwGjSobasZuIZTSKxMQmUikogkguuVhtaNwEItty comNRGXi+dzvEERtbvVeoqh/fDOmoIa5j6J77S90zYM5ptLXdpHEVk5EB84RiXn/YccDepALeO7T8 8PZTWcAMauvy5k/v4HDh0oU1ep64LFsxiuZi43gxC2KrCIWrambxtSeiFZkC/x2LhqUbQRGbUGMFH aCq+TlbA==; Received: by zero.zsh.org with local id 1qnTGS-000DD6-LD; Tue, 03 Oct 2023 00:27:52 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f53.google.com) smtp.remote-ip=209.85.218.53; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f53.google.com ([209.85.218.53]:60656) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1qnTFs-000Cu9-No; Tue, 03 Oct 2023 00:27:17 +0000 Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-9ad8a822508so52696566b.0 for ; Mon, 02 Oct 2023 17:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1696292835; x=1696897635; darn=zsh.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=EtlQDxyitSPVS8ZG4/rfMN2ATXOvQMLfJfUWhJzzpbs=; b=kWfcIZVfZsNYIFf4g8QhM1r1UrlSjerrbrThk5P98M3OXXm3pwRPQW916jMhf1n4A0 0ToYerTZ/Oq6Ep/8IW5MD6ZcskNZNXzbG51AJFnypTruySRxs2E5QuSr3cE1fCe3Ew33 b21fZQTUX3cyl7bUXO2bYBmMHjbycPUanJIMXzw/oydsNj1Y4VmFcQe3AK42nZglq5zh bA1k/3Ni1a5/DI17GXQJFPHoPrDYWq1AQJ2LgDEk1BI4GqjYgHbDx2/VlWeLXTyIJg0+ k09yzXc34TvwgQlYyfx/Mh4kn/IMHBi+5je4kjJEr28JKyzHmQ7rH+Xgbs1wCo0hbaKR Gi3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696292835; x=1696897635; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EtlQDxyitSPVS8ZG4/rfMN2ATXOvQMLfJfUWhJzzpbs=; b=HHYISkV4+M0lK9FgnIfsZsS3D5luDv93Xa8qdVKi+j88fTcIb7nxGi0EOkkkOmLmlf /f2Rj81Mx61FMN+sA5qzjjK6Ufgh+iFSmHJRTl2kaKg4barzNDvxAIgs5PFvAC3jpVD/ Bsf3ZCgNcizVydM2gT3A2WAtux/3RDwaH4F6wDPkGHqRHLnuURGjggWMkDcWsGMyp0I2 374O3ZQQly6YaiAG6Ff59/xR7X5Hjy7AIy0QAmBWnm5O9PuNdrxzQPW0GUScy2A4f1SQ 4IaSjqqA7YBuZpG/MQ20xKhk3Y+8UPvt++UlLlbdWIM359k/dzz9ta2MussAQHznRQ7B WJrw== X-Gm-Message-State: AOJu0Yx2DTEs8drKF+0zmdX+JcCIMaHTccqEObyquasGZ2CWM3gz6CiO PA//Ovh2BuKJXGPNWblPh2lCnJut1qcG2FMshZuCjhJ9t23tqXU3ybo= X-Google-Smtp-Source: AGHT+IHAJJHhmYNCqcYNJb85kbsaYyFxQQR5LjWmqNmEv4ePNVKaS82MGi/FAe2AjekibNAOs1o7lrIg0bY9w8XVmv0= X-Received: by 2002:a17:906:5185:b0:9ae:6da8:1819 with SMTP id y5-20020a170906518500b009ae6da81819mr12708017ejk.48.1696292835520; Mon, 02 Oct 2023 17:27:15 -0700 (PDT) MIME-Version: 1.0 From: Bart Schaefer Date: Mon, 2 Oct 2023 17:27:04 -0700 Message-ID: Subject: Partial reads in ${ ... } capture To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 52198 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: I inadvertently removed a zfree() when moving the guts of stuff() into zstuff(), so patch below is for the resulting potential (though unlikely) memory leak on a failed or partial read. However, I did want to raise a question: Should this instead return a partly-filled buffer on a short read? In which case a different patch must be applied. That would require using zshcalloc() when allocating the buffer so that it would be properly NUL-terminated no matter how many bytes (up to "len") were placed in it. The ${ ... } substitution would ignore the return of -1 and instead check whether anything had been placed in the buffer. I would not want to change the result of stuff() because I presume having "fc" execute the content of a short read is not desirable, but I'm less certain about command substitution. Thoughts? diff --git a/Src/input.c b/Src/input.c index 8d7f44d7c..dd8f2edc7 100644 --- a/Src/input.c +++ b/Src/input.c @@ -632,6 +632,7 @@ zstuff(char **out, const char *fn) if (len && !(fread(buf, len, 1, in))) { zerr("read error on %s", fn); fclose(in); + zfree(buf, len + 1); unqueue_signals(); return -1; }