From patchwork Fri Jul 3 14:52:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 138442 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E31774BA23C5 for ; Fri, 3 Jul 2026 15:00:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E31774BA23C5 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dbDhOdQj X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 3112F4BA2E1D for ; Fri, 3 Jul 2026 14:52:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3112F4BA2E1D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3112F4BA2E1D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783090376; cv=none; b=HWj25Q1c4RL8BvYENOMqy/vkPsmYn0tdiUj8X1+eA4WEczUxTdkU6MK5OfA5mpekLcVApovL5ODDKvcbvrrgmEVBCDlaQ3ZXNWVHsUerYBrpu5Ot1b3nWL/C6vTwVR0tyL4tDPsC2k6HbnzRitF76SZ1gq4iv0iQbtZEMMpa2rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783090376; c=relaxed/simple; bh=S4xd/tktL+IVUsPBTHnhWGhiRQWAz5Bwot68v4fx3mM=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=GTmTv5k7/gbbyyAHpLtOtezc8/SMAx35rTG6taUNdpBCFS5ubJb85fCRl4Iu+s6XVkMroB9A29JZCxh93toJXvlWmJHMDpXhqVsOH272igN4spI5SplAtmki2EWxqc67CoddyTKUYl2lgFbtTmqqht13EGVZWLrSCqzfjqFBnAM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dbDhOdQj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3112F4BA2E1D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783090375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=juNkapGOnbAseFjrYJbD1ixQEyUGXpCVgfIrgxp08d4=; b=dbDhOdQj/F/5FHyp6bu/k4G4ZR1SMA7N2ifxe9j4gKsIwTUBcKabgk7EzhzlF7+9K2Iwu9 +P2WlqWNe2wDsEwp9NaiT9Kr+srLKFKFqSsT/DNaSj320fNBgPL6GrMn37FcQCzjtHQ2wR ge/kQZS9NfC62FoxeOY1FSagiPAbAZQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-izoLEuGjPiqQMRd71XkJaQ-1; Fri, 03 Jul 2026 10:52:54 -0400 X-MC-Unique: izoLEuGjPiqQMRd71XkJaQ-1 X-Mimecast-MFC-AGG-ID: izoLEuGjPiqQMRd71XkJaQ_1783090373 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6E8E918CC48E for ; Fri, 3 Jul 2026 14:52:53 +0000 (UTC) Received: from oldenburg3.str.redhat.com (unknown [10.44.50.50]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BB2F236F04 for ; Fri, 3 Jul 2026 14:52:52 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 1/4] support: Add resolv_response_set_buffer In-Reply-To: Message-ID: References: X-From-Line: da99017797e4be1e2d6516e2430e97d55558e5f5 Mon Sep 17 00:00:00 2001 Date: Fri, 03 Jul 2026 16:52:50 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VLZhTQUc7Z_IZAfHnGOnFQRpEZHj0wL5Cob7S8C9otA_1783090373 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org This can be used to mangle the response data to exercise the DNS client with corrupted packets. Also change resolv_response_buffer not to allocate. Instead, just return a pointer to the internal buffer. The function is currently unused. Reviewed-by: Adhemerval Zanella --- support/resolv_test.c | 17 +++++++++++++---- support/resolv_test.h | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/support/resolv_test.c b/support/resolv_test.c index ec406b281a..4bb642f439 100644 --- a/support/resolv_test.c +++ b/support/resolv_test.c @@ -429,11 +429,20 @@ resolv_response_length (const struct resolv_response_builder *b) } unsigned char * -resolv_response_buffer (const struct resolv_response_builder *b) +resolv_response_buffer (struct resolv_response_builder *b) { - unsigned char *result = xmalloc (b->offset); - memcpy (result, b->buffer, b->offset); - return result; + return b->buffer; +} + +void +resolv_response_set_buffer (struct resolv_response_builder *b, + const unsigned char *data, size_t length) +{ + if (length > max_response_length) + FAIL_EXIT1 ("resolv_response_set_buffer: length %zu exceeds maximum %d", + length, max_response_length); + memmove (b->buffer, data, length); + b->offset = length; } struct resolv_response_builder * diff --git a/support/resolv_test.h b/support/resolv_test.h index 7a81c1c513..c10c523eb4 100644 --- a/support/resolv_test.h +++ b/support/resolv_test.h @@ -206,6 +206,21 @@ void resolv_response_close (struct resolv_response_builder *); /* The size of the response packet built so far. */ size_t resolv_response_length (const struct resolv_response_builder *); +/* Return a pointer to the internal response buffer. The pointer is + only valid until the next call that modifies the builder. The + length of the byte array can be obtained using + resolv_response_length. */ +unsigned char *resolv_response_buffer (struct resolv_response_builder *) + __attribute_nonnull__ ((1)); + +/* Replace the contents of the response buffer contents with a copy of + LENGTH bytes starting at DATA. Passing the pointer returned by + resolv_response_buffer is valid. If LENGTH is larger than the + maximum support packet size, fail the process. */ +void resolv_response_set_buffer (struct resolv_response_builder *, + const unsigned char *data, size_t length) + __attribute_nonnull__ ((1, 2)); + /* Allocates a response builder tied to a specific query packet, starting at QUERY_BUFFER, containing QUERY_LENGTH bytes. */ struct resolv_response_builder *