]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/radius/config.c
CI: Updated the 'checkout' actions that were using Node.js 16 to Node.js 20. (#489)
[ppp.git] / pppd / plugins / radius / config.c
index 6e36d898a27a58bdae7e29f8e616797ff1eb0ab2..e1a4814873488945c0f60febb660996005f37464 100644 (file)
@@ -212,6 +212,7 @@ int rc_read_config(char *filename)
 
                if ((pos = strcspn(p, "\t ")) == 0) {
                        error("%s: line %d: bogus format: %s", filename, line, p);
+                       fclose(configfd);
                        return (-1);
                }
 
@@ -224,6 +225,7 @@ int rc_read_config(char *filename)
 
                if (option->status != ST_UNDEF) {
                        error("%s: line %d: duplicate option line: %s", filename, line, p);
+                       fclose(configfd);
                        return (-1);
                }
 
@@ -233,20 +235,28 @@ int rc_read_config(char *filename)
 
                switch (option->type) {
                        case OT_STR:
-                                if (set_option_str(filename, line, option, p) < 0)
+                               if (set_option_str(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        case OT_INT:
-                                if (set_option_int(filename, line, option, p) < 0)
+                               if (set_option_int(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        case OT_SRV:
-                                if (set_option_srv(filename, line, option, p) < 0)
+                               if (set_option_srv(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        case OT_AUO:
-                                if (set_option_auo(filename, line, option, p) < 0)
+                               if (set_option_auo(filename, line, option, p) < 0) {
+                                       fclose(configfd);
                                        return (-1);
+                               }
                                break;
                        default:
                                fatal("rc_read_config: impossible case branch!");
@@ -273,7 +283,7 @@ char *rc_conf_str(char *optname)
        option = find_option(optname, OT_STR);
 
        if (option == NULL)
-               fatal("rc_conf_str: unkown config option requested: %s", optname);
+               fatal("rc_conf_str: unknown config option requested: %s", optname);
        return (char *)option->val;
 }
 
@@ -284,7 +294,7 @@ int rc_conf_int(char *optname)
        option = find_option(optname, OT_INT|OT_AUO);
 
        if (option == NULL)
-               fatal("rc_conf_int: unkown config option requested: %s", optname);
+               fatal("rc_conf_int: unknown config option requested: %s", optname);
        return *((int *)option->val);
 }
 
@@ -295,7 +305,7 @@ SERVER *rc_conf_srv(char *optname)
        option = find_option(optname, OT_SRV);
 
        if (option == NULL)
-               fatal("rc_conf_srv: unkown config option requested: %s", optname);
+               fatal("rc_conf_srv: unknown config option requested: %s", optname);
        return (SERVER *)option->val;
 }
 
@@ -482,26 +492,14 @@ int rc_find_server (char *server_name, UINT4 *ip_addr, char *secret)
                if ((h = strtok (buffer, " \t\n")) == NULL) /* first hostname */
                        continue;
 
-               memset (hostnm, '\0', AUTH_ID_LEN);
-               len = strlen (h);
-               if (len > AUTH_ID_LEN)
-               {
-                       len = AUTH_ID_LEN;
-               }
-               strncpy (hostnm, h, (size_t) len);
-               hostnm[AUTH_ID_LEN] = '\0';
+               memset (hostnm, '\0', AUTH_ID_LEN + 1);
+               strlcpy (hostnm, h, AUTH_ID_LEN + 1);
 
                if ((s = strtok (NULL, " \t\n")) == NULL) /* and secret field */
                        continue;
 
-               memset (secret, '\0', MAX_SECRET_LENGTH);
-               len = strlen (s);
-               if (len > MAX_SECRET_LENGTH)
-               {
-                       len = MAX_SECRET_LENGTH;
-               }
-               strncpy (secret, s, (size_t) len);
-               secret[MAX_SECRET_LENGTH] = '\0';
+               memset (secret, '\0', MAX_SECRET_LENGTH + 1);
+               strlcpy (secret, s, MAX_SECRET_LENGTH + 1);
 
                if (!strchr (hostnm, '/')) /* If single name form */
                {
@@ -537,7 +535,6 @@ int rc_find_server (char *server_name, UINT4 *ip_addr, char *secret)
        if (result == 0)
        {
                memset (buffer, '\0', sizeof (buffer));
-               memset (secret, '\0', sizeof (secret));
                error("rc_find_server: couldn't find RADIUS server %s in %s",
                      server_name, rc_conf_str("servers"));
                return (-1);