Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whi30-000NTy-3C for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 06:15:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1whi2z-00BHVP-0k for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Jul 2026 06:15:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1whi2y-00BHVD-33 for pgsql-hackers@lists.postgresql.org; Thu, 09 Jul 2026 06:15:45 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1whi2x-00000000H1t-2m8x for pgsql-hackers@postgresql.org; Thu, 09 Jul 2026 06:15:44 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2cce6a0c9c3so5791495ad.1 for ; Wed, 08 Jul 2026 23:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783577743; x=1784182543; darn=postgresql.org; h=content-transfer-encoding:content-type:mime-version:user-agent :references:in-reply-to:from:subject:cc:to:message-id:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=37KeOvbwCcRjcmjFcHPb9viBqRFsFu7rP5dwvjSFHLo=; b=oLnEVZO3z9MkOn6IDAgJVgwbFZuRgReHmK+0GPspRMbgze7WVrEc1j9SC22WWNG/7n xENt07GEufhofJarwwZk0E/4w0rvA7knrH7lwzOmw2kgp5F/Yybt5UVoTSLGJdMUBb1k Z55s6AkKgCVJJ2XXHn96Q8uiitiNSqbJjsNSj//4cP7Nmw/s6AoLejobuOLU6xLWttub MGf7Z7Fj68qlkuSmetDVB7zMxSjRwBH/HzWbt0UAIpvtR7tJsam+iys1PCXX7HmL2dBP FIiNdnM5WoBF/T6wF5PSTrVekNvR4n0SyyO3gjtQOwDTxB8bTGvEIthD/PvmZ9peWJQE vZ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783577743; x=1784182543; h=content-transfer-encoding:content-type:mime-version:user-agent :references:in-reply-to:from:subject:cc:to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=37KeOvbwCcRjcmjFcHPb9viBqRFsFu7rP5dwvjSFHLo=; b=iY/dzYjDLqNIoQuAJdfOm3VajNE0LJkQHXJnZ4AgXWAzJhuqDeF6Iz5sgb6QWg2x5o zQ3VamncILbrjQiBHYDEZvSLpqVLn0gX72tVJD/zAGm9u3kkw1PykSn8o0sOdaSR71IC 82tAikm9XHhAYgI7+rKWzi+u9nSlooyDyQSY/yMO6CV8dG0Fw1t+6/M/UqKgm4vURj3c W2HT7gxkGiGpRXjRu7FsaB8CXtdaSuNyq/BBSk4lklfljW8NsOHPSWU2TeiGoN7z8o71 5Ey7NHuz+HDZoIMhI/NrYAEXJcwLdP98kVabsLJUQ2/clBZc9ckuRbho3bNYwOFuVV/Z TbZQ== X-Forwarded-Encrypted: i=1; AHgh+RpcRgtzyD9sxtfQCa23nIaqvIbUrTpLPS+7z0oSWu7BemnEw7igwejNlgS3yMoqFdFli33m/9f4n4lMo7ex@postgresql.org X-Gm-Message-State: AOJu0Yxel52dhH/Hvnw77KaaSMHktJa/6/Zj+tGcQBAlPiOhrD8JHpkS mz5X7g6gtncx56YkUJWyo5oWdvbN7feKoa5G8mA7uxzKZEcpIKSoOloAHPH8fw== X-Gm-Gg: AfdE7cllDWfRBBX6lswBv55BpUbltfbM2isVzxphSP3sIjjEsYyc/fiYyj62O2J4jv6 Tu3p6wDt8DYCvTLXP2D/2+E+7Y7BiGoO4U5npTp72j3eFxz0G67l7RX3OTSvmJvV9UlqgQkYjjx ez+YFWTQfq3P4NUKbxevPzaP9ypjjrBKCA/x1LfMfELXDdTYaJGW0gteJp4mZS3CySP60+6rm2P g7hN8XF7H+W179UDcqSEJbN1Njo8CnjpWjSW00q/uWTEm0IDUriW/Tx+hKqoxwQDH/A0RJotXTX GKA2NQoe1aNOBxU+YW2yPcVuUciTN0AeqCcH1c2Et4JVS7WlOSS+0nJXTxho1vCIu9lQJVaoKHF Np3VRZF5WsALtulAZiPv5e08QmOBI6wEftG3pkxoW9Yw+zzURXLFDvWyrbpa0T8SPIHGJ56sOV6 BlwTbZE9su28hwFH0+Yuc/Yhklv0JDIhG5Zj2WXJLxGoFHTJRAFVMHEVDVWSGb X-Received: by 2002:a17:902:d548:b0:2ca:de3:15e1 with SMTP id d9443c01a7336-2ccea45f224mr55090275ad.31.1783577742940; Wed, 08 Jul 2026 23:15:42 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc99cc5aasm38556905ad.0.2026.07.08.23.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jul 2026 23:15:42 -0700 (PDT) Date: Thu, 09 Jul 2026 15:15:40 +0900 (JST) Message-Id: <20260709.151540.712205027352253675.horikyota.ntt@gmail.com> To: gonzalemario@gmail.com Cc: daniel@yesql.se, pgsql-hackers@postgresql.org Subject: Re: Possible replace of strncpy on xactdesc.c From: Kyotaro Horiguchi In-Reply-To: References: <2F655280-ACEB-47C8-9F0A-35709B96373F@yesql.se> User-Agent: Mew version 6.8 on Emacs 29.4 Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, At Mon, 6 Jul 2026 18:31:44 -0400, Mario Gonz=E1lez Troncoso wrote in = > On Mon, 6 Jul 2026 at 18:26, Mario Gonz=E1lez Troncoso > wrote: > > > > On Mon, 6 Jul 2026 at 10:38, Daniel Gustafsson wr= ote: > > > > > > > > > As a general rule it's a good idea to replace strncpy with strlcp= y. > > > > > > > The other functions that are inside the file already use strlcp= y() so > > > > maybe the use of current strncpy() on xactdesc.c is just code t= hat > > > > comes from the refactor itself. > > > > > > It was introduced in 1eb6d6527aae in twophase.c and then moved to= xaxtdesc.c in > > > the above mentioned commit. > > > > > > > I'll send a proper patch once some feedback is received but at = least > > > > it's compiling and passing local tests. > > > > > > Sounds good, please send a patch. > > > > > > > Great. Sending it now after rebasing from master and passing local > > tests (long live cirrus CI). > > > > I added this to the commitfest as well > > https://commitfest.postgresql.org/patch/6989/ I agree that replacing strncpy() with strlcpy() is often a good general= direction, but I'm not sure this case fits that pattern. Here, xlrec->gidlen is the length of the GID including the terminating NUL byte, and the following pointer advance is based on the same length= .= So this looks more like copying a known-length field from the WAL recor= d than copying an arbitrary C string. Wouldn't memcpy(parsed->twophase_gid, bufptr, xlrec->gidlen) express th= e intent more directly? Regards, -- = Kyotaro Horiguchi NTT Open Source Software Center