]> git.meshlink.io Git - meshlink/commitdiff
Fix a memory leak when an invitation file contains an invalid submesh name.
authorGuus Sliepen <guus@meshlink.io>
Tue, 11 Feb 2020 20:39:36 +0000 (21:39 +0100)
committerGuus Sliepen <guus@meshlink.io>
Tue, 11 Feb 2020 20:39:36 +0000 (21:39 +0100)
Found by Clang's static analyzer.

src/protocol_auth.c

index 3676e9cb6f47ac88ab36f3c90e9849db4aeaa4ba..6517d9ceef8765bcb5493d03b75daecd98c9865a 100644 (file)
@@ -230,17 +230,20 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat
        char *submesh_name = packmsg_get_str_dup(&in);
 
        if(!strcmp(submesh_name, CORE_MESH)) {
+               free(submesh_name);
                c->submesh = NULL;
        } else {
                if(!check_id(submesh_name)) {
                        logger(mesh, MESHLINK_ERROR, "Invalid invitation file %s\n", cookie);
-                       abort();
+                       free(submesh_name);
                        return false;
                }
 
                c->submesh = lookup_or_create_submesh(mesh, submesh_name);
+               free(submesh_name);
 
                if(!c->submesh) {
+                       logger(mesh, MESHLINK_ERROR, "Unknown submesh in invitation file %s\n", cookie);
                        return false;
                }
        }
@@ -249,7 +252,6 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat
        sptps_send_record(&c->sptps, 0, config.buf, config.len);
 
        config_free(&config);
-       free(submesh_name);
 
        c->status.invitation_used = true;