fix: better sanity checking for bad plugin manifests

This commit is contained in:
goaaats 2021-12-18 12:27:57 +01:00
parent 8e5db448b2
commit 678cd0f130
No known key found for this signature in database
GPG key ID: F18F057873895461
5 changed files with 28 additions and 7 deletions

View file

@ -1889,7 +1889,7 @@ namespace Dalamud.Interface.Internal.Windows
return hasSearchString && !( return hasSearchString && !(
manifest.Name.ToLowerInvariant().Contains(searchString) || manifest.Name.ToLowerInvariant().Contains(searchString) ||
manifest.Author.Equals(this.searchText, StringComparison.InvariantCultureIgnoreCase) || (!manifest.Author.IsNullOrEmpty() && manifest.Author.Equals(this.searchText, StringComparison.InvariantCultureIgnoreCase)) ||
(manifest.Tags != null && manifest.Tags.Contains(searchString, StringComparer.InvariantCultureIgnoreCase))); (manifest.Tags != null && manifest.Tags.Contains(searchString, StringComparer.InvariantCultureIgnoreCase)));
} }

View file

@ -247,9 +247,9 @@ namespace Dalamud.Plugin.Internal
{ {
// Not a plugin // Not a plugin
} }
catch (Exception) catch (Exception ex)
{ {
Log.Error("During boot plugin load, an unexpected error occurred"); Log.Error(ex, "During boot plugin load, an unexpected error occurred");
} }
} }
} }
@ -519,6 +519,9 @@ namespace Dalamud.Plugin.Internal
LocalPlugin plugin; LocalPlugin plugin;
if (!manifest.CheckSanity())
throw new InvalidOperationException("Plugin manifest is not sane.");
if (isDev) if (isDev)
{ {
Log.Information($"Loading dev plugin {name}"); Log.Information($"Loading dev plugin {name}");

View file

@ -1,5 +1,5 @@
using System.IO; using System.IO;
using Dalamud.Utility;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Dalamud.Plugin.Internal.Types namespace Dalamud.Plugin.Internal.Types
@ -10,6 +10,24 @@ namespace Dalamud.Plugin.Internal.Types
/// </summary> /// </summary>
internal record LocalPluginManifest : PluginManifest internal record LocalPluginManifest : PluginManifest
{ {
/// <summary>
/// Check if this manifest is valid.
/// </summary>
/// <returns>Whether or not this manifest is valid.</returns>
public bool CheckSanity()
{
if (this.InternalName.IsNullOrEmpty())
return false;
if (this.Name.IsNullOrEmpty())
return false;
if (this.DalamudApiLevel != 0)
return false;
return true;
}
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the plugin is disabled and should not be loaded. /// Gets or sets a value indicating whether the plugin is disabled and should not be loaded.
/// This value supercedes the ".disabled" file functionality and should not be included in the plugin master. /// This value supercedes the ".disabled" file functionality and should not be included in the plugin master.

View file

@ -15,7 +15,7 @@ namespace Dalamud.Plugin.Internal.Types
/// Gets the author/s of the plugin. /// Gets the author/s of the plugin.
/// </summary> /// </summary>
[JsonProperty] [JsonProperty]
public string Author { get; init; } public string? Author { get; init; }
/// <summary> /// <summary>
/// Gets or sets the public name of the plugin. /// Gets or sets the public name of the plugin.

View file

@ -18,13 +18,13 @@ namespace Dalamud.Utility
/// </summary> /// </summary>
/// <param name="value">The string to test.</param> /// <param name="value">The string to test.</param>
/// <returns>true if the value parameter is null or an empty string (""); otherwise, false.</returns> /// <returns>true if the value parameter is null or an empty string (""); otherwise, false.</returns>
public static bool IsNullOrEmpty(this string value) => string.IsNullOrEmpty(value); public static bool IsNullOrEmpty(this string? value) => string.IsNullOrEmpty(value);
/// <summary> /// <summary>
/// Indicates whether a specified string is null, empty, or consists only of white-space characters. /// Indicates whether a specified string is null, empty, or consists only of white-space characters.
/// </summary> /// </summary>
/// <param name="value">The string to test.</param> /// <param name="value">The string to test.</param>
/// <returns>true if the value parameter is null or an empty string (""), or if value consists exclusively of white-space characters.</returns> /// <returns>true if the value parameter is null or an empty string (""), or if value consists exclusively of white-space characters.</returns>
public static bool IsNullOrWhitespace(this string value) => string.IsNullOrWhiteSpace(value); public static bool IsNullOrWhitespace(this string? value) => string.IsNullOrWhiteSpace(value);
} }
} }