]> git.ipfire.org Git - location/libloc.git/commitdiff
as: Fix dereferencing NULL pointer when setting AS name
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Oct 2020 20:44:43 +0000 (20:44 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Oct 2020 20:44:43 +0000 (20:44 +0000)
Reported-by: Gisle Vanem <gisle.vanem@gmail.com>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/as.c

index e1fbb013fcab7697c6524cb85ae600ff7ebad6c2..8421ac8a341a091513f272e60546ef36805b0067 100644 (file)
--- a/src/as.c
+++ b/src/as.c
@@ -90,7 +90,13 @@ LOC_EXPORT const char* loc_as_get_name(struct loc_as* as) {
 }
 
 LOC_EXPORT int loc_as_set_name(struct loc_as* as, const char* name) {
-       as->name = strdup(name);
+       if (as->name)
+               free(as->name);
+
+       if (name)
+               as->name = strdup(name);
+       else
+               as->name = NULL;
 
        return 0;
 }