chiark / gitweb /
privcache; uncached_load_file: Introduce error_out
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Dec 2019 14:43:54 +0000 (14:43 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:54 +0000 (21:56 +0000)
The error handling here is a bit fragile: we rely on not having set
`ok' inappropriately.  Indeed actually we *do* set `ok'
inappropriately if we lack defhash, but in that case we set sigpriv to
0 so do return 0 as needed.  So we are fixing a latent bug.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
privcache.c

index 298626f2e19c4e416e3b8b7c6949684875f571dc..c01af9dbc412cbc218256ac01e3919fb8066a1a5 100644 (file)
@@ -89,7 +89,7 @@ static struct sigprivkey_if *uncached_load_file(
            slilog(log,M_ERR,"failed to open private key file %s",
                   path);
        }
-       goto out;
+       goto error_out;
     }
 
     setbuf(f,0);
@@ -98,12 +98,12 @@ static struct sigprivkey_if *uncached_load_file(
     if (ferror(f)) {
        slilog(log,M_ERR,"failed to read private-key file %s",
               path);
-       goto out;
+       goto error_out;
     }
     if (!feof(f)) {
        slilog(log,M_ERR,"private key file %s longer than max %d",
               path, (int)databuf->alloclen);
-       goto out;
+       goto error_out;
     }
     fclose(f); f=0;
 
@@ -111,7 +111,7 @@ static struct sigprivkey_if *uncached_load_file(
     databuf->size=got;
     struct cloc loc = { .file=path, .line=0 };
     ok=scheme->loadpriv(scheme, databuf, &sigpriv, log, loc);
-    if (!ok) goto out; /* loadpriv will have logged */
+    if (!ok) goto error_out; /* loadpriv will have logged */
 
     if (sigpriv->sethash) {
        if (!defhash) {
@@ -120,7 +120,7 @@ static struct sigprivkey_if *uncached_load_file(
                   path);
            sigpriv->dispose(sigpriv->st);
            sigpriv=0;
-           goto out;
+           goto error_out;
        }
        sigpriv->sethash(sigpriv->st,defhash);
     }
@@ -128,6 +128,10 @@ static struct sigprivkey_if *uncached_load_file(
   out:
     if (f) fclose(f);
     return ok ? sigpriv : 0;
+
+ error_out:
+    ok=False;
+    goto out;
 }
 
 static struct sigprivkey_if *privcache_lookup(void *sst,