为了开始这个,我很清楚参数化查询是最好的选择,但我想知道是什么让我在下面提出的策略容易受到攻击.人们坚持认为下面的解决方案不起作用,所以我找一个为什么它不会这样做的例子.
如果在发送到SQL Server之前使用以下转义在代码中构建动态SQL,那么什么样的注入可以打败这个?
string userInput= "N'" + userInput.Replace("'", "''") + "'"
Run Code Online (Sandbox Code Playgroud)
在SQL Server中无法使用"\"转义单引号.
我相信使用Unicode进行SQL走私(此处概述)会被生成的字符串被单引号前面的N标记为Unicode这一事实所阻碍.据我所知,SQL Server没有其他字符集会自动转换为单引号.没有未转义的单引号,我不相信注射是可能的.
我不相信String Truncation也是一个可行的载体.SQL Server肯定不会截断,因为根据microsoft,a的最大大小为nvarchar2GB .在大多数情况下,2 GB的字符串是不可行的,在我的情况下是不可能的.
二阶注入是可能的,但如果可能的话:
我并不是说这比使用参数化查询更好或者替代,但我想知道我概述的内容是如何易受攻击的.有任何想法吗?
我有以下代码:
Sub AddSources()
Dim pubPage As Page
Dim pubShape As Shape
Dim hprlink As Hyperlink
Dim origAddress() As String
Dim exportFileName As String
exportFileName = "TestResume"
Dim linkSource As String
linkSource = "TestSource2"
Dim hyperLinkText As TextRange
For Each pubPage In ActiveDocument.Pages
For Each pubShape In pubPage.Shapes
If pubShape.Type = pbTextFrame Then
For Each hprlink In pubShape.TextFrame.TextRange.Hyperlinks
If InStr(hprlink.Address, "http://bleaney.ca") > 0 Then
hyperLinkText = hprlink.Range
origAddress = Split(hprlink.Address, "?source=")
hprlink.Address = origAddress(0) + "?source=" + linkSource
hprlink.Range = hyperLinkText …Run Code Online (Sandbox Code Playgroud) 当除法产生无限重复的数字时,数字显然会被截断以适合小数的大小.所以像1/3这样的东西就像0.3333333333333333333.如果我们然后将该数字乘以3,我们得到类似于0.999999999999999999而不是1,如果保留了该分数的真实值,我们将获得.
这是来自MSDN上十进制文章的代码示例:
decimal dividend = Decimal.One;
decimal divisor = 3;
// The following displays 0.9999999999999999999999999999 to the console
Console.WriteLine(dividend/divisor * divisor);
Run Code Online (Sandbox Code Playgroud)
当值0.9999999999999999999与1进行比较时,这会导致问题.如果不失去精确度,它们就会相等,但当然在这种情况下,比较会导致错误.
人们通常如何处理这个问题?除了为每次比较定义一些误差之外,还有更优雅的解决方案吗?
我试图让Bloomberg的BDE库在Visual Studio 2015中编译.因为它们重新实现了编译器通常提供的标准库,所以有一些头文件的名称与标准库名称完全匹配,例如stddef.h.它们可选地允许您关闭标准库的覆盖,为此,它们重新实现的文件可选地只包括原始编译器提供的版本,例如stddef.h.他们这样做包括通过宏,如下所示:
# if defined(BSLS_COMPILERFEATURES_SUPPORT_INCLUDE_NEXT)
# include_next <stddef.h>
# else
# include BSL_NATIVE_C_LIB_HEADER(stddef.h)
# endif
Run Code Online (Sandbox Code Playgroud)
在哪里BSL_NATIVE_C_LIB_HEADER扩展到这样的东西:
#if defined(BSLS_PLATFORM_CMP_SUN) // Sun Compiler
# define BSL_NATIVE_C_LIB_HEADER(filename) <../include/filename>
#elif defined(BSLS_PLATFORM_CMP_CLANG) || defined(BSLS_PLATFORM_CMP_GNU)
// Clang and GCC use 'include_next'
#elif defined(BSLS_PLATFORM_CMP_HP) // HP Compiler
# define BSL_NATIVE_C_LIB_HEADER(filename) <../include_std/filename>
#else
// Most other compilers
# define BSL_NATIVE_C_LIB_HEADER(filename) <../include/filename>
#endif
Run Code Online (Sandbox Code Playgroud)
问题是Visual Studio 2015 引入了一些重构,将一些 C标准库头文件移动到这样的路径:C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt.这显然意味着 <../include/filename>将不再找到移动的文件.问题是所有文件都没有移动.例如,iso646.h …
我正在编写一个类型的测试驱动程序,这显然不应该是默认构造的.有没有办法在我的测试驱动程序中声明这是这种情况?我可以通过编译错误手动验证,但我想要一些可以防止未来可能错误地添加默认构造函数的更改.
编辑:我陷入了使用C++ 03的环境.记住这一点,还有其他选择is_default_constructable吗?
我创建一个 JFile Chooser,并使用 .setCurrentDirectory(); 通过传递 newFile("."); 将目录设置为我的 java 项目文件夹的根目录 有时这似乎工作正常,但有时会引发错误。这一切都是在程序加载时、在任何用户输入之前发生的,因此据我所知,无论发生与否,这都是完全随机的。这是我的代码中与文件选择器相关的部分:
public class PnlHighScores extends JPanel {
JFileChooser fcScores = new JFileChooser();
PnlHighScores() {
fcScores.addChoosableFileFilter(new TxtFilter());
//***********This seems to cause a strange error only somethimes, Right as the program is run!***********
fcScores.setCurrentDirectory(new File("."));//http://www.rgagnon.com/javadetails/java-0370.html
}
class ActFileChooser implements ActionListener {
public void actionPerformed(ActionEvent e) {//http://download.oracle.com/javase/tutorial/uiswing/examples/components/FileChooserDemoProject/src/components/FileChooserDemo.java
int returnVal = fcScores.showOpenDialog(PnlHighScores.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
filScores = fcScores.getSelectedFile();
sFileLocation = filScores.getAbsolutePath();//.getParent();//http://www.java-forums.org/awt-swing/29485-how-retrieve-path-filechooser.html
//System.out.println(filScores);
pnlScoreText.updateScoreFile(sFileLocation);
}
}
}
class TxtFilter extends javax.swing.filechooser.FileFilter {//http://www.exampledepot.com/egs/javax.swing.filechooser/Filter.html
public boolean …Run Code Online (Sandbox Code Playgroud) 我现在正在阅读C#在一个Nutshell中,书中提到Queue数据结构的底层实现使用了一个根据需要调整大小的数组.这个调整大小当然会有成本,所以我想知道使用它的背后的理由是说双链表是什么?鉴于我们只关心第一个和最后一个元素,并且双链表比数组更有效地调整大小,为什么要使用数组呢?数组会占用更少的内存,但这是唯一的理由吗?
编辑:对不起,刚刚意识到这几乎与此完全重复: 为什么Stack <T>和Queue <T>用数组实现? (他们的问题甚至来自同一本书).无论如何,谢谢你的所有答案!
我有一个这样的矢量设置,我想对它进行排序:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
const int a =10;
int b = 20;
pair<const int, int> constPair1(a,b);
b=30;
pair<const int, int> constPair2(a,b);
vector<pair<const int, int>> vec{constPair1,constPair2};
sort(vec.begin(),vec.end());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,由于const值的原因,上面的排序不会编译.有什么方法可以对这个载体进行排序吗?或者我是不是创建了一个新的向量并复制了值?
我正在制作一个java应用程序,我需要播放音频.我正在播放我的大炮射击的小声音文件(它是一个大炮射击游戏)和射弹爆炸,虽然我打算循环播放背景音乐.我找到了两种不同的方法来实现这一目标,但两种方法都无法实现我想要的效果.
第一种方法实际上是一种方法:
public void playSoundFile(File file) {//http://java.ittoolbox.com/groups/technical-functional/java-l/sound-in-an-application-90681
try {
//get an AudioInputStream
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
//get the AudioFormat for the AudioInputStream
AudioFormat audioformat = ais.getFormat();
System.out.println("Format: " + audioformat.toString());
System.out.println("Encoding: " + audioformat.getEncoding());
System.out.println("SampleRate:" + audioformat.getSampleRate());
System.out.println("SampleSizeInBits: " + audioformat.getSampleSizeInBits());
System.out.println("Channels: " + audioformat.getChannels());
System.out.println("FrameSize: " + audioformat.getFrameSize());
System.out.println("FrameRate: " + audioformat.getFrameRate());
System.out.println("BigEndian: " + audioformat.isBigEndian());
//ULAW format to PCM format conversion
if ((audioformat.getEncoding() == AudioFormat.Encoding.ULAW)
|| (audioformat.getEncoding() == AudioFormat.Encoding.ALAW)) {
AudioFormat newformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
audioformat.getSampleRate(),
audioformat.getSampleSizeInBits() * …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的程序添加一个功能,该功能将在芝加哥期货市场关闭后每天执行代码.这意味着我想在美国东部时间5点35分左右(市场所在的中部时间中午4点35分)运行代码.当然,当夏令时发生时,这将在EST(UTC -5)和EST(UTC -4)之间来回切换.
我知道有很多类似的问题,但是它们似乎都没有提供我可以使用的解决方案.主要的建议似乎是使用Task Scheduler或Quartz,但是,我无法在我的程序中实现这些.我认为,最有前途的解决办法是使用的组合TimeZoneInfo,DateTime以及TimeSpan每天都将触发在合适的时间安排的计时器.我目前的解决方案是:
DateTime now = DateTime.Now;
DateTime currentDateTime = now.DateTime.Date;
DateTime expiryDateTime = currentDateTime
.AddHours(17)
.AddMinutes(35)
.AddDays(
now.DateTime.Hour >= 18 + utcOffset
|| (now.DateTime.Hour == 17 && now.DateTime.Minute >= 35) ? 1 : 0);
Timer timer = new Timer(
...,
null,
expiryDateTime - DateTime.Now,
...);
Run Code Online (Sandbox Code Playgroud)
但是,如果我的代码在东部时间以外的时区运行,我认为这将会崩溃.我还担心,当时区从EST切换到EDT时,这种情况在23或25小时内表现不正常,反之亦然.
有没有比我目前正在做的更好的方式来处理调度?如何使这段代码更加健壮,以便在任何时区运行,但总是在东部时间同时执行?
编辑:如上所述,任务计划程序和Quartz不是选项.Quartz已经出局,因为我无法包含第三方库.任务计划程序已经出局,因为我需要访问程序中的许多内部值.启动另一个应用程序并将这些值暴露给该应用程序会增加比我认为的更复杂的复杂性.
我声明然后定义一个执行比较的函数:
template <class KEY, class VALUE>
bool compareFlatMapElements(
typename SortedPairsVector<KEY, VALUE>::ElementType& first,
typename SortedPairsVector<KEY, VALUE>::ElementType& second);
// Compares the specified 'first' and 'second' using
// 'bsl::less<KEY>' to compare the values stored in 'first()' of
// each pair held by the 'FlatMap_Element.
template <class KEY, class VALUE>
inline
bool compareFlatMapElements(
typename SortedPairsVector<KEY, VALUE>::ElementType& first,
typename SortedPairsVector<KEY, VALUE>::ElementType& second)
{
return first.data().first < second.data().first;
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试在排序中使用它
std::sort(d_data.begin(), d_data.end(), compareFlatMapElements);
Run Code Online (Sandbox Code Playgroud)
是什么导致以下错误,我该如何解决?
error: no matching function for call to 'sort(..., ..., <unresolved overloaded function …Run Code Online (Sandbox Code Playgroud)