From patchwork Thu Feb 13 14:56:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 'Darko Komljenovic' via swupdate X-Patchwork-Id: 1237525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::33d; helo=mail-wm1-x33d.google.com; envelope-from=swupdate+bncbdmkfl6vyijrbdohsxzakgqeazjek4y@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=googlegroups.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=L9L92hQI; dkim-atps=neutral Received: from mail-wm1-x33d.google.com (mail-wm1-x33d.google.com [IPv6:2a00:1450:4864:20::33d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48JKMj6GLfz9sNg for ; Fri, 14 Feb 2020 01:56:17 +1100 (AEDT) Received: by mail-wm1-x33d.google.com with SMTP id b8sf1301872wmj.0 for ; Thu, 13 Feb 2020 06:56:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1581605773; cv=pass; d=google.com; s=arc-20160816; b=KtaQhoVNA6nvglgx/x+UwZOAG4xwg3C1S3ZO7tkhiMmmYDj206IXai390qA6f7Qn2H WPAbEDqDBqIAIUfkxhFQ2/N/4CZXRxLXA1J6pxrB8asI7usvxgzAo61fIZShOlgP80LH zI8VUOyKZl2dLGBr71+JF9TQhMCbruwnw7yPiqET2XqGqEO3GkGYgQKW1+f/THkhiuBK yby8JNnzUwHowYtUg+YRfNvNtKmp5MxFc/H7QzcBK/S6T9HMJX/Qj6/Z/l99Oum2bAhK NchoDlDf+TZX6e356DHLWaTHzN8XGdnVcEX+0s/uVlQGW2SDTFyAUFxYkVxaL7ZEb2o6 3mdw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date :from:mime-version:dkim-signature; bh=GlSPpmdfIVOQHAHieSLvu7JP0pAgR/33gwD9i2pKC1U=; b=uFgsqvF8x5hsum+lZsj662v4imdjn1LXGDOC6ePJqIOQgbBlhzhOa69//J/gMUY+4y fIElyEL8kBgTQewAingXhgl2OmzBk61paS4tUQSDQNSpJS1xCfEmybkTp2RFb9bqzqPt 5obwz21yejPI+9k1zkESgqssVqJBcBfttOJJDAgFeOe/pNOdyoqEs691qeFertMLn9Kk B6lkrTO42KQJx07C41wEJslHwFIk+seaQ5BHOFB5J+vVf5AAnQ84a6VI4yr1INPNR5Cn WdIablZJkTjfwCYKxZSzpIp8JoV5S5hZapdegObC0E8YGdFGFr7798npix1KAPBKZSq1 j+Cw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=PGeA29Ru; spf=pass (google.com: domain of chmielewskiandreas@googlemail.com designates 2a00:1450:4864:20::229 as permitted sender) smtp.mailfrom=chmielewskiandreas@googlemail.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=mime-version:from:date:message-id:subject:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=GlSPpmdfIVOQHAHieSLvu7JP0pAgR/33gwD9i2pKC1U=; b=L9L92hQIPmNrjFur2nN8KHb8BgODJQrH1dkKIiGU1dIWocy/XPYx2qbtdaQ1iQ2qBy TN29sMx4XAigZ8VI/THT+9kbK2ZUNHSQM8fY6041C6SoxxfE+DJJjp+pmAhFQvW9OOS1 fKuljYiqCGPPCA9E8cPvkl80e3FeXXMJgKWJey/SBUF4ptuXsnfc340OAlhsZqqbbFgl jgGsUNw6vQFJHOtu/nMbhG+7MUCff9Xi5zJ5bEyLvqZrf6umE0y7knhpzoQ+BQL0HEGH pGpaTn2DFOn7ew6hVPshmb/iZWtDX24EpapPYTD+ChzbgPSRZmacrNsk1jphC3Wf+N+a SCTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=GlSPpmdfIVOQHAHieSLvu7JP0pAgR/33gwD9i2pKC1U=; b=gIZqcofb6zWl7sPldWbrwzh3jRQCHiSXzOz034dGc5HOIcPMU5UJ8EZyKpPA4yGksh mP9uBCPZrYTZ9cXnW1NVHq/LRa6RYp7fyFrt0SspnY6v4zzbdx9rTTlicYWyACWigqI9 Ma11tNSTQjwW6E4EvjLCKrkVNb8WLLEBRigF/983FXPi6/L68Z1UjCvHzpQeNbwN+Aka X262CtJJQj/EdKhgbCxU7NoSBMm7C9DMGahRCZXLzVQNP3EqC2n09a+MbPie049OyLs0 xiOTg9IF5AgVrYhpzzJUObFDPZFB+1kWIVpbKU/tDghUnE7A2OH720DFGHmsXuoSBAYk NaCQ== X-Gm-Message-State: APjAAAXV6f58ai2gnDTE8X7bAZZ5I6aMd9ypUqyrA18kd7msufBN5SCs Y5EvcnhZTbyN0BHRDh6sepY= X-Google-Smtp-Source: APXvYqwaiIbqVxeRPjkzx1sJzwLKsODQQAXaS8Qymrh1eqYpDMqfNm5D+2zjKwER+eCx2v+QBYY9rQ== X-Received: by 2002:a5d:6b82:: with SMTP id n2mr23838386wrx.153.1581605773377; Thu, 13 Feb 2020 06:56:13 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a7b:cf15:: with SMTP id l21ls3164175wmg.0.canary-gmail; Thu, 13 Feb 2020 06:56:12 -0800 (PST) X-Received: by 2002:a1c:dfd6:: with SMTP id w205mr6396601wmg.151.1581605772588; Thu, 13 Feb 2020 06:56:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581605772; cv=none; d=google.com; s=arc-20160816; b=Os1hRlKqMp9Ck9X+gsoMUy6TicL9s5NPO+LTm1IAqRC0Q5VzibGV8D7p/qdR0EhKW2 MKHT/s+EpASxkgD2WzRgI/CePeG+ToxVwmg7Z3TH1NNEIoEB1f6LGsqipe2R9AhjveUK 45KBn7dgjcRGskynOblymLIx2Dx4hv7K5f2DsH0OXqHuV0NkMTW9Txw1QloZa0mAT92k 7tmK4IsdVdkhxQONUSqRWeLeucP49YMFUqqSliq+baB2bhDSIiwrObftlNn9G5U6az5h NOdnRnBoXYAGMPoU/RIFhIdpvBuERBxGjHFZqxYOBMTpLJ8EbzfpwDETVpiolGkk6n6p mpnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=sQ4vd3p5+AgsXulM0JdWr2nNNA8BXmGwvfPS4xgyynM=; b=VuKmX48c4qHhAu8A458DeWDYp3oQhiXKIkxBtgFohxPTQVtxOC3E0yIqy/B29ogXlF mSC4lxryHoPWIc8A7Z/7lNVlU660tLbqjxDIAuUN1rEcTwjjWCS8fbsa5uO0UGQGBD/N kzX+LAaHGlMIwPcsIemxBWGgw56oH3k7DjWQEBz9WT+qar4hMIZSKaj6bSb/FMlFqk41 n4XImU+9gZQtQjDvDbKUOtvzJFFQV61ODfNvRhnalQ8wpN9Q/xxHBMSSmNShx85gJTve y3zKEEOxVP9q7Bp6msqJDvfc59ZJCAeGLhU06xGzll5GI+yxzIjqu8IafV1vu4DeUXZl nh5w== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=PGeA29Ru; spf=pass (google.com: domain of chmielewskiandreas@googlemail.com designates 2a00:1450:4864:20::229 as permitted sender) smtp.mailfrom=chmielewskiandreas@googlemail.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com. [2a00:1450:4864:20::229]) by gmr-mx.google.com with ESMTPS id d191si400484wmd.2.2020.02.13.06.56.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Feb 2020 06:56:12 -0800 (PST) Received-SPF: pass (google.com: domain of chmielewskiandreas@googlemail.com designates 2a00:1450:4864:20::229 as permitted sender) client-ip=2a00:1450:4864:20::229; Received: by mail-lj1-x229.google.com with SMTP id y6so6949613lji.0 for ; Thu, 13 Feb 2020 06:56:12 -0800 (PST) X-Received: by 2002:a2e:9744:: with SMTP id f4mr11865550ljj.267.1581605771988; Thu, 13 Feb 2020 06:56:11 -0800 (PST) MIME-Version: 1.0 X-Patchwork-Original-From: "'Chmielewski Andreas' via swupdate" From: 'Darko Komljenovic' via swupdate Date: Thu, 13 Feb 2020 15:56:01 +0100 Message-ID: Subject: [swupdate] segfault within libubootenv when closing and opening environment To: swupdate@googlegroups.com X-Original-Sender: chmielewskiandreas@googlemail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@googlemail.com header.s=20161025 header.b=PGeA29Ru; spf=pass (google.com: domain of chmielewskiandreas@googlemail.com designates 2a00:1450:4864:20::229 as permitted sender) smtp.mailfrom=chmielewskiandreas@googlemail.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com X-Original-From: Chmielewski Andreas Reply-To: Chmielewski Andreas Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Hi, i am writing to you regarding libubootenv library where i see a segfault when opening and closing environment to uboot. My goal in my application is to initialize libuboot only once and open and close uboot environment whenever necessary so that uboot env does not stay open (and in blocking mode) To show the bug easily i have modified fw_printenv.c so that you can easily retry this. You will get a segfault the fist time you access libuboot_get_env method. value = libuboot_get_env(ctx, argv[i]); if (noheader) fprintf(stdout, "%s\n", value ? value : ""); So what i am basically doing here is closing the connection (as it was opened previously in the file), opening it again and then getting some environment variable what segfaults immediately. I am refering to the documentation of libuboot_close where you see that this should work. " * Release allocated recource for the environment, but * maintain the context. This allows to call * libuboot_open() again. " I am doing something wrong? Thanks for your help. Andreas diff --git a/src/fw_printenv.c b/src/fw_printenv.c index 18887f9..18196c6 100644 --- a/src/fw_printenv.c +++ b/src/fw_printenv.c @@ -143,6 +143,16 @@ int main (int argc, char **argv) { } } else { for (i = 0; i < argc; i++) { + libuboot_close(ctx); + + if ((ret = libuboot_open(ctx)) < 0) { + fprintf(stderr, "Cannot read environment, using default\n"); + if ((ret = libuboot_load_file(ctx, defenvfile)) < 0) { + fprintf(stderr, "Cannot read default environment from file\n"); + exit (ret); + } + } +