mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 12:28:07 +00:00
Set autocrlf by default, update affected files (#2261)
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
using System;
|
||||
namespace Problems {
|
||||
public static class Problems {
|
||||
public static void Func(ReadOnlySpan<byte> data) {
|
||||
var count = 0;
|
||||
if (data.Length < 4) {
|
||||
return;
|
||||
}
|
||||
if (data[0] == 0) { count++; }
|
||||
if (data[1] == 1) { count++; }
|
||||
if (data[2] == 2) { count++; }
|
||||
if (count >= 3) { throw new Exception("this is bad"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
namespace Problems {
|
||||
public static class Problems {
|
||||
public static void Func(ReadOnlySpan<byte> data) {
|
||||
var count = 0;
|
||||
if (data.Length < 4) {
|
||||
return;
|
||||
}
|
||||
if (data[0] == 0) { count++; }
|
||||
if (data[1] == 1) { count++; }
|
||||
if (data[2] == 2) { count++; }
|
||||
if (count >= 3) { throw new Exception("this is bad"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,8 +1,8 @@
|
||||
using SharpFuzz;
|
||||
namespace Wrapper {
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
Fuzzer.LibFuzzer.Run(stream => { Problems.Problems.Func(stream); });
|
||||
}
|
||||
}
|
||||
}
|
||||
using SharpFuzz;
|
||||
namespace Wrapper {
|
||||
public class Program {
|
||||
public static void Main(string[] args) {
|
||||
Fuzzer.LibFuzzer.Run(stream => { Problems.Problems.Func(stream); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\problems\problems.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SharpFuzz" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\problems\problems.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SharpFuzz" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,85 +1,85 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <io.h>
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#define STDIN_FILENO _fileno(stdin)
|
||||
#define read _read
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define SIZE 8192
|
||||
#define BUF_SIZE 32
|
||||
|
||||
int check(const char *data, size_t len)
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
strncpy(buf, data, len); // BUG - This incorrectly uses length of src, not dst
|
||||
|
||||
// do something to ensure this isn't optimized away
|
||||
int buflen = strlen(buf);
|
||||
for (int i = 0; i <= ((buflen % 2 == 1) ? buflen - 1 : buflen) / 2; i++)
|
||||
{
|
||||
if (buf[i] != buf[buflen - 1 - i])
|
||||
{
|
||||
printf("not palindrome: ");
|
||||
printf(buf);
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int from_stdin()
|
||||
{
|
||||
char input[SIZE] = {0};
|
||||
int size = read(STDIN_FILENO, input, SIZE);
|
||||
return check(input, size);
|
||||
}
|
||||
|
||||
int from_file(char *filename)
|
||||
{
|
||||
FILE *infile;
|
||||
char *buffer;
|
||||
long length;
|
||||
int result;
|
||||
|
||||
infile = fopen(filename, "r");
|
||||
|
||||
if (infile == NULL)
|
||||
return 1;
|
||||
|
||||
fseek(infile, 0L, SEEK_END);
|
||||
length = ftell(infile);
|
||||
|
||||
fseek(infile, 0L, SEEK_SET);
|
||||
buffer = calloc(length, sizeof(char));
|
||||
if (buffer == NULL)
|
||||
return 1;
|
||||
|
||||
length = fread(buffer, sizeof(char), length, infile);
|
||||
fclose(infile);
|
||||
|
||||
result = check(buffer, length);
|
||||
free(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
return from_stdin();
|
||||
}
|
||||
else if (argc > 1)
|
||||
{
|
||||
return from_file(argv[1]);
|
||||
}
|
||||
}
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN64
|
||||
#include <io.h>
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#define STDIN_FILENO _fileno(stdin)
|
||||
#define read _read
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define SIZE 8192
|
||||
#define BUF_SIZE 32
|
||||
|
||||
int check(const char *data, size_t len)
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
memset(buf, 0, BUF_SIZE);
|
||||
strncpy(buf, data, len); // BUG - This incorrectly uses length of src, not dst
|
||||
|
||||
// do something to ensure this isn't optimized away
|
||||
int buflen = strlen(buf);
|
||||
for (int i = 0; i <= ((buflen % 2 == 1) ? buflen - 1 : buflen) / 2; i++)
|
||||
{
|
||||
if (buf[i] != buf[buflen - 1 - i])
|
||||
{
|
||||
printf("not palindrome: ");
|
||||
printf(buf);
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int from_stdin()
|
||||
{
|
||||
char input[SIZE] = {0};
|
||||
int size = read(STDIN_FILENO, input, SIZE);
|
||||
return check(input, size);
|
||||
}
|
||||
|
||||
int from_file(char *filename)
|
||||
{
|
||||
FILE *infile;
|
||||
char *buffer;
|
||||
long length;
|
||||
int result;
|
||||
|
||||
infile = fopen(filename, "r");
|
||||
|
||||
if (infile == NULL)
|
||||
return 1;
|
||||
|
||||
fseek(infile, 0L, SEEK_END);
|
||||
length = ftell(infile);
|
||||
|
||||
fseek(infile, 0L, SEEK_SET);
|
||||
buffer = calloc(length, sizeof(char));
|
||||
if (buffer == NULL)
|
||||
return 1;
|
||||
|
||||
length = fread(buffer, sizeof(char), length, infile);
|
||||
fclose(infile);
|
||||
|
||||
result = check(buffer, length);
|
||||
free(buffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
return from_stdin();
|
||||
}
|
||||
else if (argc > 1)
|
||||
{
|
||||
return from_file(argv[1]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user