X-Original-To: alpine-aports@lists.alpinelinux.org Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by lists.alpinelinux.org (Postfix) with ESMTP id 81CD85C4243 for ; Mon, 6 Feb 2017 11:11:08 +0000 (GMT) Received: by mail-lf0-f67.google.com with SMTP id x1so3610037lff.0 for ; Mon, 06 Feb 2017 03:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t4qeUotaS8ir5q/qQla1MRARwj4Fb3ut8uSfoyuV594=; b=IpVIOag2BEaI8onv5jhyyHjOcjKmzkkRDpYdN7XqGew1RmTntBu23OnmKfZPpD7rw/ R6S7lNb3D9htg0ZlVaTWG+0+XO/cx2OGYUJ+LvbQ0ULM/5EnX44vMyCEQEemnsGbB7YD 37xMWB69BkIVWUE953MtmE1PhiFBi5tvhF2kJ4ORS5OJZ6lBuA25mTf+H4+NJO02JIV5 1ROTbD+5SVSycZCxuIHx3eFJ677OL+VswqWo5rzYu10EM0NdcS6rPDNLkAeMHpygpd0t YYSr8ZrSy2nTtgHjq88J3FpO5i7or23M+HcEYS++k0YQJPzukQboM7W/ISdYFZJ/Q9q/ EJhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=t4qeUotaS8ir5q/qQla1MRARwj4Fb3ut8uSfoyuV594=; b=Aj/NR+grOQ50S+NDg+uOLJ9hA1mnaRO2sBz3AUBAKbRgOtLDXXULHiXe8ScE9XVrhW IpQfh43tpBOoBqPrBZMwqH+Gd3bXem9qOttAkxX9aCfyMXLSvuR2zdG2poYXJLxOUj9/ D725onIRI4DZTDmAmTpE5TMscscXLQfPTv4Ux01baSCcxloUJDa6VyMdYonHurP/WdeK BXc8e8DxzrH8fmq5Szh4/rjBVGayHdQ56hVJW6Wbv5gH4UQszG99MzKYmHXVb9kC5fGN q1AEGtvEGZGIvfI+YD+/hsFLQyUTs5MJ9GXbXWLaAMOtvCL0MrOE1NK6wQ6EPmGaXI+X lf9w== X-Gm-Message-State: AMke39l1EFhTO8ug0ZRNvqGhMpd4AUieJKtf9PVTnDt+NIXDRt6xc1NZLWzHncwUfDDUnA== X-Received: by 10.25.199.213 with SMTP id x204mr3405670lff.122.1486379467542; Mon, 06 Feb 2017 03:11:07 -0800 (PST) Received: from vostro.util.wtbts.net ([2001:1bc8:101:f402:e66f:13ff:fef3:8cd0]) by smtp.gmail.com with ESMTPSA id s28sm166369ljd.6.2017.02.06.03.11.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Feb 2017 03:11:07 -0800 (PST) Sender: =?UTF-8?Q?Timo_Ter=C3=A4s?= Date: Mon, 6 Feb 2017 13:11:05 +0200 From: Timo Teras To: Huszty =?UTF-8?B?R2VyZ8WR?= Cc: alpine-aports@lists.alpinelinux.org Subject: Re: [alpine-aports] [PATCH] community/minidlna: patch for potential segfaults Message-ID: <20170206131105.6965c132@vostro.util.wtbts.net> In-Reply-To: References: <20170204201354.26019-1-huszty.gergo@digitaltrip.hu> <20170206114306.4920c40c@vostro.util.wtbts.net> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.28; x86_64-alpine-linux-musl) X-Mailinglist: alpine-aports Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, 06 Feb 2017 11:52:13 +0100 Huszty Gerg=C5=91 wrote: > Aport list added to CC.=20 >=20 > 2017-02-06 11:26 id=C5=91pontban Huszty Gerg=C5=91 ezt =C3=ADrta: >=20 > > Please see my comments inline. So I didn't dig myself too much into > > the details, but stack is exhausted always at this point on my > > system and maybe other users suffer from the same issue. > > I didn't want to touch the code too much and also didn't want to > > increase the very typical 8192k stack ulimit size. I don't know how > > typical is to set exclusive stack size for an app. Do you think that > > would be a better solution? The 8M ulimit based stack size affects only the main thread. The program creates additional thread(s) in minidlna.c:1052. On those threads the musl default is 80k. You should use pthread_attr_setstacksize to change this. For example, see: http://git.alpinelinux.org/cgit/aports/tree/main/mpd/stacksize.patch > > 2017-02-06 10:43 id=C5=91pontban Timo Teras ezt =C3=ADrta: > >=20 > > On Sat, 4 Feb 2017 20:13:54 +0000 > > Gergo Huszty wrote: > >=20 > > From: libesz > >=20 > > Nfo parsing related fixes added in a patch. > > - uninitalized string (GetVideoMetadata() - nfo) -> memset to 0 > > - stack was kicked with 64k buffer unconditionally (parse_nfo() - > > buf) -> now it is on heap and malloc'd size depends on filesize --- > > community/minidlna/10-minidlna-nfo.patch | 42 > > ++++++++++++++++++++++++++++++++ > > community/minidlna/APKBUILD | 14 +++++++---- 2 files > > changed, 51 insertions(+), 5 deletions(-) create mode 100644 > > community/minidlna/10-minidlna-nfo.patch > >=20 > > diff --git a/community/minidlna/10-minidlna-nfo.patch > > b/community/minidlna/10-minidlna-nfo.patch new file mode 100644 > > index 0000000..8e3497c > > --- /dev/null > > +++ b/community/minidlna/10-minidlna-nfo.patch > > @@ -0,0 +1,42 @@ > > +--- a/metadata.c > > ++++ b/metadata.c > > +@@ -160,7 +160,7 @@ > > + parse_nfo(const char *path, metadata_t *m) > > + { > > + FILE *nfo; > > +- char buf[65536]; > > ++ char *buf; > > + struct NameValueParserData xml; > > + struct stat file; > > + size_t nread; > > +@@ -172,11 +172,13 @@ > > + DPRINTF(E_INFO, L_METADATA, "Not parsing very > > large .nfo file %s\n", path); > > + return; > > + } > > ++ buf =3D malloc(file.st_size+1);=20 > > The return value should be checked for out-of-memory. =20 > Yep, going to add it.=20 >=20 > > Additionally the code above checks for maximum of 65536, so using > > malloc does not help much here. Large files seem to be ignored > > intentionally. > >=20 > > Though, if this fixes issues it's probably due to reducing stack > > usage. It might be better to increase default stack size, as large > > stack buffers might be used elsewhere. =20 > Well that's interesting because the program fails every time exactly > here.=20 Probably the inotify thread crashing due to out of stack. > >> ++ memset(buf, '\0', file.st_size+1); > >> + DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", > >> path); > >> + nfo =3D fopen(path, "r"); > >> + if( !nfo ) > >> + return; > >> +- nread =3D fread(&buf, 1, sizeof(buf), nfo); > >> ++ nread =3D fread(buf, 1, file.st_size, nfo); > >> + > >> + ParseNameValue(buf, nread, &xml, 0); > >> + > >> +@@ -676,6 +679,7 @@ > >> + > >> + memset(&m, '\0', sizeof(m)); > >> + memset(&video, '\0', sizeof(video)); > >> ++ memset(nfo, '\0', sizeof(nfo)); > >> + > >> + //DEBUG DPRINTF(E_DEBUG, L_METADATA, "Parsing video > >> %s...\n", name); > >> + if ( stat(path, &file) !=3D 0 ) =20 > >=20 > > This probable does not fix anything. nfo is strcpy:ied to. =20 > Yes it is, but the string was not null terminated so it was passed > forward as a filepath with junk at the end. At least I saw it in the > debugger.=20 That is normal. Debugger shows the whole char array. When used the first zero byte terminates the string, and it'd handled right. --- Unsubscribe: alpine-aports+unsubscribe@lists.alpinelinux.org Help: alpine-aports+help@lists.alpinelinux.org ---