[{"id":3675327,"web_url":"http://patchwork.ozlabs.org/comment/3675327/","msgid":"<aderIKSVgzrb_hFR@yuki.lan>","list_archive_url":null,"date":"2026-04-09T13:35:28","subject":"Re: [LTP] [PATCH 1/2] lib: safe_file_ops: Add SAFE_FILE_READ_STR()","submitter":{"id":8530,"url":"http://patchwork.ozlabs.org/api/people/8530/","name":"Cyril Hrubis","email":"chrubis@suse.cz"},"content":"Hi!\n> diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c\n> index 8314c4b1b..2d163c0af 100644\n> --- a/lib/safe_file_ops.c\n> +++ b/lib/safe_file_ops.c\n> @@ -160,6 +160,30 @@ void safe_file_scanf(const char *file, const int lineno,\n>  \t}\n>  }\n>  \n> +void safe_file_read_str(const char *file, const int lineno,\n> +                        const char *path, char *buf, size_t buf_size)\n> +{\n> +\tFILE *f;\n> +\n> +\tf = fopen(path, \"r\");\n> +\tif (!f) {\n> +\t\ttst_brkm_(file, lineno, TBROK | TERRNO, NULL,\n> +\t\t          \"Failed to open FILE '%s' for reading\", path);\n\nWe need a return; here in an unlikely case that someone would call this\nfrom a test cleanup() callback.\n\n> +\t}\n> +\n> +\tif (!fgets(buf, buf_size, f))\n> +\t\tbuf[0] = 0;\n> +\n> +\tsize_t len = strlen(buf);\n> +\n> +\tif (len && buf[len-1] == '\\n')\n> +\t\tbuf[len-1] = 0;\n> +\n> +\tif (fclose(f)) {\n> +\t\ttst_brkm_(file, lineno, TBROK | TERRNO, NULL,\n> +\t\t\t\"Failed to close FILE '%s'\", path);\n> +\t}\n> +}\n>  \n>  /*\n>   * Try to parse each line from file specified by 'path' according\n> -- \n> 2.52.0\n> \n> \n> -- \n> Mailing list info: https://lists.linux.it/listinfo/ltp","headers":{"Return-Path":"<ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>","X-Original-To":["incoming@patchwork.ozlabs.org","ltp@lists.linux.it"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","ltp@picard.linux.it"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256\n header.s=susede2_rsa header.b=vPQC11eN;\n\tdkim=fail reason=\"signature verification failed\" header.d=suse.cz\n header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519\n header.b=F4UWmlFp;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key)\n header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa\n header.b=T8W2rZc+;\n\tdkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256\n header.s=susede2_ed25519 header.b=AShJiQrx;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it\n (client-ip=2001:1418:10:5::2; helo=picard.linux.it;\n envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it;\n receiver=patchwork.ozlabs.org)","smtp-out1.suse.de;\n dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=T8W2rZc+;\n dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=AShJiQrx"],"Received":["from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fs1CJ3lbVz1xy1\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 23:35:24 +1000 (AEST)","from picard.linux.it (localhost [IPv6:::1])\n\tby picard.linux.it (Postfix) with ESMTP id 233233E4D1A\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  9 Apr 2026 15:35:22 +0200 (CEST)","from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature ECDSA (secp384r1))\n (No client certificate requested)\n by picard.linux.it (Postfix) with ESMTPS id 211EC3E4CFE\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 15:35:18 +0200 (CEST)","from smtp-out1.suse.de (smtp-out1.suse.de\n [IPv6:2a07:de40:b251:101:10:150:64:1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 6C789602F50\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 15:35:18 +0200 (CEST)","from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org\n [IPv6:2a07:de40:b281:104:10:150:64:97])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by smtp-out1.suse.de (Postfix) with ESMTPS id EB0F66A7C2\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 13:35:16 +0000 (UTC)","from imap1.dmz-prg2.suse.org (localhost [127.0.0.1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n (No client certificate requested)\n by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DBD494A0B3\n for <ltp@lists.linux.it>; Thu,  9 Apr 2026 13:35:16 +0000 (UTC)","from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167])\n by imap1.dmz-prg2.suse.org with ESMTPSA id BZHBNBSr12m8RwAAD6G6ig\n (envelope-from <chrubis@suse.cz>)\n for <ltp@lists.linux.it>; Thu, 09 Apr 2026 13:35:16 +0000"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_rsa;\n t=1775741717; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=oVh3t0ToxB9X+HaMr7pxy7FjIsMjaARVJzDjQFF1UsE=;\n b=vPQC11eNSrwaNNNE5fM6MvFIWi6YPd6IuCQcwQNbaBOl6KxkVBum3NE8IRASHSaQTWLRrQ\n WkGLAwXp+WR6BfEprmNkKSIncINWK9OFHJ+cQjIX/2tRXdLvsZQLE37ETJB3GaIpLsoCSZ\n bTPpxp0wZQ01ZNujuTiAypwMi/51q2w=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_ed25519; t=1775741717;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=oVh3t0ToxB9X+HaMr7pxy7FjIsMjaARVJzDjQFF1UsE=;\n b=F4UWmlFptj/40W1xRQoh3ncxOGELY/x1PpejN//ZgMRtgo5ValjLWkOTC7ap91wTybruCo\n 12MMzQ98qJlHTZCA==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_rsa;\n t=1775741716; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=oVh3t0ToxB9X+HaMr7pxy7FjIsMjaARVJzDjQFF1UsE=;\n b=T8W2rZc+BSA1wa20W+sXKKLNEKW5avG6afA7yoP6xzLW2tuXRRmcHPzT3idMwYmDtYDN+P\n bro03Eazc/DXV9YSPIPOuFdcP9SWut0VcsKnUNS7SMWwA0fo82F0mFhAUYmrCiCOv7Trnm\n KFeFKOdCq2sLS/t1la+V26O5b86z7WU=","v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz;\n s=susede2_ed25519; t=1775741716;\n h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:\n mime-version:mime-version:content-type:content-type:\n in-reply-to:in-reply-to:references:references;\n bh=oVh3t0ToxB9X+HaMr7pxy7FjIsMjaARVJzDjQFF1UsE=;\n b=AShJiQrx/R0jEgzQaqow3KXqyEWubjDGcVMOsv46Ls45bNoYNOG2CMkpR+IaPoyR6KvFfP\n VVzeTPynJRudb7DA=="],"Date":"Thu, 9 Apr 2026 15:35:28 +0200","From":"Cyril Hrubis <chrubis@suse.cz>","To":"ltp@lists.linux.it","Message-ID":"<aderIKSVgzrb_hFR@yuki.lan>","References":"<20260409103041.8253-1-chrubis@suse.cz>\n <20260409103041.8253-2-chrubis@suse.cz>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20260409103041.8253-2-chrubis@suse.cz>","X-Rspamd-Action":"no action","X-Rspamd-Server":"rspamd2.dmz-prg2.suse.org","X-Spamd-Result":"default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%];\n NEURAL_HAM_LONG(-1.00)[-1.000];\n R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519];\n NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain];\n MX_GOOD(-0.01)[];\n DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519];\n FUZZY_RATELIMITED(0.00)[rspamd.com];\n RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[];\n ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FROM_HAS_DN(0.00)[];\n RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.cz:+];\n TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2];\n FROM_EQ_ENVFROM(0.00)[];\n SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from];\n RCVD_VIA_SMTP_AUTH(0.00)[];\n PREVIOUSLY_DELIVERED(0.00)[ltp@lists.linux.it];\n MISSING_XM_UA(0.00)[];\n DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:dkim, suse.cz:email,\n imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:rdns]","X-Rspamd-Queue-Id":"EB0F66A7C2","X-Spam-Score":"-4.51","X-Spam-Level":"","X-Spam-Status":"No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID,\n DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_NONE,SPF_PASS\n shortcircuit=no autolearn=disabled version=4.0.1","X-Spam-Checker-Version":"SpamAssassin 4.0.1 (2024-03-25) on in-2.smtp.seeweb.it","X-Virus-Scanned":"clamav-milter 1.0.9 at in-2.smtp.seeweb.it","X-Virus-Status":"Clean","Subject":"Re: [LTP] [PATCH 1/2] lib: safe_file_ops: Add SAFE_FILE_READ_STR()","X-BeenThere":"ltp@lists.linux.it","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"Linux Test Project <ltp.lists.linux.it>","List-Unsubscribe":"<https://lists.linux.it/options/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=unsubscribe>","List-Archive":"<http://lists.linux.it/pipermail/ltp/>","List-Post":"<mailto:ltp@lists.linux.it>","List-Help":"<mailto:ltp-request@lists.linux.it?subject=help>","List-Subscribe":"<https://lists.linux.it/listinfo/ltp>,\n <mailto:ltp-request@lists.linux.it?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it","Sender":"\"ltp\" <ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it>"}}]