2 Commits

Author SHA1 Message Date
Jack Garrard
70b0af699d Handle invalid packet size more gracefully 2025-04-20 13:16:32 -07:00
Jack Garrard
dabc9231ac Add flake files 2025-04-20 13:16:19 -07:00
4 changed files with 107 additions and 1 deletions

61
flake.lock generated Normal file
View File

@@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1738136902,
"narHash": "sha256-pUvLijVGARw4u793APze3j6mU1Zwdtz7hGkGGkD87qw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9a5db3142ce450045840cc8d832b13b8a2018e0c",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

40
flake.nix Normal file
View File

@@ -0,0 +1,40 @@
# This is an example flake.nix for a Switch project based on devkitA64.
# It will work on any devkitPro example with a Makefile out of the box.
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};
in {
devShells.default = pkgs.mkShell {
name = "smov2-server-dev";
buildInputs = with pkgs; [
curlftpfs
rustPlatform.bindgenHook
rustc
cargo
rustfmt
gcc
rust-analyzer
cmake
clippy
];
# Each package provides a shell hook that sets all necessary
# environmental variables. This part is necessary, otherwise your build
# system won't know where to find devkitPro. By setting these
# variables we allow devkitPro's example Makefiles to work out of the box.
};
});
}

View File

@@ -302,7 +302,9 @@ where
},
};
let excess_padding = p_size as usize - data.get_size();
let excess_padding = (p_size as usize).checked_sub(data.get_size());
let excess_padding = excess_padding.ok_or(EncodingError::InvalidSize)?;
if excess_padding > 0 {
buf.advance(excess_padding);
}

View File

@@ -74,6 +74,8 @@ pub enum ChannelError {
#[derive(Error, Debug)]
pub enum EncodingError {
#[error("Invalid Packet Size")]
InvalidSize,
#[error("Not enough data")]
NotEnoughData,
#[error("Invalid string data")]
@@ -109,6 +111,7 @@ impl SMOError {
match self {
Self::Encoding(EncodingError::ConnectionClose)
| Self::Encoding(EncodingError::ConnectionReset)
| Self::Encoding(EncodingError::InvalidSize)
| Self::Channel(_) => ErrorSeverity::ClientFatal,
_ => ErrorSeverity::NonCritical,
}