From 4e08a1c97600e0372680e86a651f916c70e89342 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 22 Jan 2020 18:45:57 +0300 Subject: [PATCH] More errors checking --- VERSION | 2 +- doc/install.texi | 2 +- doc/news.ru.texi | 12 ++++++++++++ doc/news.texi | 12 ++++++++++++ ports/nncp/Makefile | 2 +- src/lockdir.go | 5 ++++- src/sp.go | 8 ++++++-- src/tmp.go | 4 +++- src/toss.go | 32 ++++++++++++++++++++++---------- src/tx.go | 31 ++++++++++++++++++++----------- 10 files changed, 82 insertions(+), 28 deletions(-) diff --git a/VERSION b/VERSION index 84197c8..74664af 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.3.2 +5.3.3 diff --git a/doc/install.texi b/doc/install.texi index 55d1499..89c15d5 100644 --- a/doc/install.texi +++ b/doc/install.texi @@ -1,7 +1,7 @@ @node Installation @unnumbered Installation -@set VERSION 5.3.2 +@set VERSION 5.3.3 Possibly NNCP package already exists for your distribution: diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 791f14e..5abadc4 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -1,6 +1,18 @@ @node Новости @section Новости +@node Релиз 5.3.3 +@subsection Релиз 5.3.3 +@itemize + +@item +Больше различных проверок в коде на ошибки. + +@item +Обновлены зависимые библиотеки. + +@end itemize + @node Релиз 5.3.2 @subsection Релиз 5.3.2 @itemize diff --git a/doc/news.texi b/doc/news.texi index 671f6e3..244331c 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -3,6 +3,18 @@ See also this page @ref{Новости, on russian}. +@node Release 5.3.3 +@section Release 5.3.3 +@itemize + +@item +More various error checks. + +@item +Updated dependencies. + +@end itemize + @node Release 5.3.2 @section Release 5.3.2 @itemize diff --git a/ports/nncp/Makefile b/ports/nncp/Makefile index 3efb3ea..527eb9e 100644 --- a/ports/nncp/Makefile +++ b/ports/nncp/Makefile @@ -1,7 +1,7 @@ # $FreeBSD: $ PORTNAME= nncp -DISTVERSION= 5.3.2 +DISTVERSION= 5.3.3 CATEGORIES= net MASTER_SITES= http://www.nncpgo.org/download/ diff --git a/src/lockdir.go b/src/lockdir.go index 38144ee..875a5bb 100644 --- a/src/lockdir.go +++ b/src/lockdir.go @@ -25,7 +25,10 @@ import ( ) func (ctx *Ctx) LockDir(nodeId *NodeId, lockCtx string) (*os.File, error) { - ctx.ensureRxDir(nodeId) + if err := ctx.ensureRxDir(nodeId); err != nil { + ctx.LogE("lockdir", SDS{}, err, "") + return nil, err + } lockPath := filepath.Join(ctx.Spool, nodeId.String(), lockCtx) + ".lock" dirLock, err := os.OpenFile( lockPath, diff --git a/src/sp.go b/src/sp.go index 21a4a2e..94b37ff 100644 --- a/src/sp.go +++ b/src/sp.go @@ -475,7 +475,7 @@ func (state *SPState) StartR(conn ConnDeadlined) error { state.maxOnlineTime = node.MaxOnlineTime sds := SDS{"node": node.Id, "nice": int(state.Nice)} - if state.Ctx.ensureRxDir(node.Id); err != nil { + if err = state.Ctx.ensureRxDir(node.Id); err != nil { return err } var rxLock *os.File @@ -999,7 +999,11 @@ func (state *SPState) ProcessSP(payload []byte) ([][]byte, error) { } state.wg.Add(1) defer state.wg.Done() - fd.Seek(0, io.SeekStart) + if _, err = fd.Seek(0, io.SeekStart); err != nil { + fd.Close() // #nosec G104 + state.Ctx.LogE("sp-file", sdsp, err, "") + return + } state.Ctx.LogD("sp-file", sdsp, "checking") gut, err := Check(fd, file.Hash[:], sdsp, state.Ctx.ShowPrgrs) fd.Close() // #nosec G104 diff --git a/src/tmp.go b/src/tmp.go index 91850d7..62ec5bb 100644 --- a/src/tmp.go +++ b/src/tmp.go @@ -105,7 +105,9 @@ func (tmp *TmpFileWHash) Commit(dir string) error { tmp.Fd.Close() // #nosec G104 return err } - tmp.Fd.Close() + if err = tmp.Fd.Close(); err != nil { + return err + } checksum := Base32Codec.EncodeToString(tmp.Hsh.Sum(nil)) tmp.ctx.LogD("tmp", SDS{"src": tmp.Fd.Name(), "dst": checksum}, "commit") if err = os.Rename(tmp.Fd.Name(), filepath.Join(dir, checksum)); err != nil { diff --git a/src/toss.go b/src/toss.go index a7cb457..c0aa7bf 100644 --- a/src/toss.go +++ b/src/toss.go @@ -89,8 +89,7 @@ func (ctx *Ctx) Toss( continue } pipeR, pipeW := io.Pipe() - errs := make(chan error, 1) - go func(job Job) { + go func(job Job) error { pipeWB := bufio.NewWriter(pipeW) _, _, err := PktEncRead( ctx.Self, @@ -98,13 +97,16 @@ func (ctx *Ctx) Toss( bufio.NewReader(job.Fd), pipeWB, ) - errs <- err - pipeWB.Flush() - pipeW.Close() - job.Fd.Close() + job.Fd.Close() // #nosec G104 if err != nil { ctx.LogE("rx", sds, err, "decryption") + return pipeW.CloseWithError(err) } + if err = pipeWB.Flush(); err != nil { + ctx.LogE("rx", sds, err, "decryption flush") + return pipeW.CloseWithError(err) + } + return pipeW.Close() }(job) var pkt Pkt var err error @@ -180,7 +182,9 @@ func (ctx *Ctx) Toss( cmd.Stdin = newNotification(notify, fmt.Sprintf( "Exec from %s: %s", sender.Name, argsStr, ), output) - cmd.Run() + if err = cmd.Run(); err != nil { + ctx.LogE("rx", sds, err, "notify") + } } } } @@ -250,7 +254,11 @@ func (ctx *Ctx) Toss( isBad = true goto Closing } - tmp.Close() + if err = tmp.Close(); err != nil { + ctx.LogE("rx", sds, err, "copy") + isBad = true + goto Closing + } dstPathOrig := filepath.Join(*incoming, dst) dstPath := dstPathOrig dstPathCtr := 0 @@ -298,7 +306,9 @@ func (ctx *Ctx) Toss( dst, humanize.IBytes(uint64(pktSize)), ), nil) - cmd.Run() + if err = cmd.Run(); err != nil { + ctx.LogE("rx", sds, err, "notify") + } } } case PktTypeFreq: @@ -362,7 +372,9 @@ func (ctx *Ctx) Toss( cmd.Stdin = newNotification(ctx.NotifyFreq, fmt.Sprintf( "Freq from %s: %s", sender.Name, src, ), nil) - cmd.Run() + if err = cmd.Run(); err != nil { + ctx.LogE("rx", sds, err, "notify") + } } } case PktTypeTrns: diff --git a/src/tx.go b/src/tx.go index 80357e7..4c31d92 100644 --- a/src/tx.go +++ b/src/tx.go @@ -159,9 +159,13 @@ func prepareTxFile(srcPath string) (reader io.Reader, closer io.Closer, fileSize } fileSize = int64(written) if err = tmpW.Flush(); err != nil { + rerr = err + return + } + if _, err = src.Seek(0, io.SeekStart); err != nil { + rerr = err return } - src.Seek(0, io.SeekStart) r, w := io.Pipe() go func() { if _, err := aeadProcess(aead, nonce, false, bufio.NewReader(src), w); err != nil { @@ -272,16 +276,19 @@ func prepareTxFile(srcPath string) (reader io.Reader, closer io.Closer, fileSize } fd, err := os.Open(e.path) if err != nil { - w.CloseWithError(err) + fd.Close() // #nosec G104 + return w.CloseWithError(err) } - _, err = io.Copy(tarWr, bufio.NewReader(fd)) - if err != nil { - w.CloseWithError(err) + if _, err = io.Copy(tarWr, bufio.NewReader(fd)); err != nil { + fd.Close() // #nosec G104 + return w.CloseWithError(err) } - fd.Close() + fd.Close() // #nosec G104 + } + if err = tarWr.Close(); err != nil { + return w.CloseWithError(err) } - tarWr.Close() - w.Close() + return w.Close() }() return } @@ -492,9 +499,11 @@ func (ctx *Ctx) TxExec( if err != nil { return err } - _, err = io.Copy(compressor, in) - compressor.Close() - if err != nil { + if _, err = io.Copy(compressor, in); err != nil { + compressor.Close() // #nosec G104 + return err + } + if err = compressor.Close(); err != nil { return err } size := int64(compressed.Len()) -- 2.44.0