我在这里使用答案尝试POST通过数据上传发出请求,但我从服务器端有不寻常的要求.该服务器是一个PHP脚本,需要filename对Content-Disposition行,因为它是期待一个文件上传.
Content-Disposition: form-data; name="file"; filename="-"
Run Code Online (Sandbox Code Playgroud)
但是,在客户端,我想发布一个内存缓冲区(在这种情况下是一个String)而不是一个文件,但让服务器处理它就好像它是一个文件上传.
但是,使用StringBody我无法在行filename上添加必填字段Content-Disposition.因此,我试图使用FormBodyPart,但这只是filename在一个单独的行.
HttpPost httppost = new HttpPost(url);
MultipartEntity entity = new MultipartEntity();
ContentBody body = new StringBody(data,
org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM);
FormBodyPart fbp = new FormBodyPart("file", body);
fbp.addField("filename", "-");
entity.addPart(fbp);
httppost.setEntity(entity);
Run Code Online (Sandbox Code Playgroud)
如果没有先将我写入文件然后再将其读回来,我怎样才能filename进入该Content-Disposition行String?
假设我正在编写一个递归函数,希望将a传递list给缺少单个元素的函数,作为循环的一部分。这是一种可能的解决方案:
def Foo(input):
if len(input) == 0: return
for j in input:
t = input[:]
t.remove(j)
Foo(t)
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以滥用slice运算符来传递列表减去元素,j而无需显式复制列表并从中删除项目?
我试图rdmsr在用户模式下执行特权指令,我希望得到某种特权错误,但我得到一个段错误.我检查了asm,我装0x186成ecx,这被认为是PERFEVTSEL0,基于上手动,1171页.
segfault的原因是什么,如何修改下面的代码来修复它?
我想在破解内核模块之前解决这个问题,因为我不希望这个段错误炸毁我的内核.
更新:我正在运行Intel(R) Xeon(R) CPU X3470.
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sched.h>
#include <assert.h>
uint64_t
read_msr(int ecx)
{
unsigned int a, d;
__asm __volatile("rdmsr" : "=a"(a), "=d"(d) : "c"(ecx));
return ((uint64_t)a) | (((uint64_t)d) << 32);
}
int main(int ac, char **av)
{
uint64_t start, end;
cpu_set_t cpuset;
unsigned int c = 0x186;
int i = 0;
CPU_ZERO(&cpuset);
CPU_SET(i, &cpuset);
assert(sched_setaffinity(0, sizeof(cpuset), …Run Code Online (Sandbox Code Playgroud) 我有一个gdb以命令结尾的脚本quit.
当我像这样运行脚本时:
gdb -x foo.gdb target_program
Run Code Online (Sandbox Code Playgroud)
最终输出始终具有:
Quit anyway? (y or n) [answered Y; input not from terminal]
Run Code Online (Sandbox Code Playgroud)
有没有办法抑制整个消息,甚至只是内部的部分[]?
[answered Y; input not from terminal]
Run Code Online (Sandbox Code Playgroud) 在我的一个控制器中,我编写以下内容以保护CSRF中的某些页面.
protect_from_forgery :only => [:foo, :bar]
Run Code Online (Sandbox Code Playgroud)
当我加载URL的对应于foo和bar,和我查看HTML,我没有看到任何隐藏的输入域或包含任何安全令牌的meta标签,描述在这里.
但是,在测试期间,我确实发现这CSRF对这些页面无效,尽管它对同一应用程序中未受保护的其他页面有效.
那么在哪里Rails 4存储用于验证请求来自原始页面的安全令牌?
请注意,我已经通过阅读Ruby on Rails的安全指南,并从部分上protect_from_forgery,它说
这将自动包含所有表单中的安全令牌和Rails生成的Ajax请求.如果安全令牌与预期的不匹配,则会重置会话.
问题是,启用CSRF保护的页面上的表单中似乎缺少此安全令牌,即使CSRF确实对它们无效.
请注意,此代码来自一个类项目,其中一个目标是执行clickjacking攻击以绕过CSRF项目.我在这里提出的问题与作业的目的是正交的.
我只是好奇Rails如何做CSRF.
在rails server直接做之后,我找不到安全令牌的相关URL是http://localhost:3000/protected_transfer.
我已经阅读了有关子流程和os.fork()的大多数相关问题,包括有关双叉技巧的所有讨论。但是,这些解决方案似乎都不适合我的情况。
我想创建一个新进程,并允许父进程终止(正常情况下),而不会破坏孩子的stdin,stdout和stderr,也不会杀死孩子。
我的第一次尝试是使用subprocess.Popen()。
#!/usr/bin/python
from subprocess import call,Popen
Popen("/bin/bash", shell=True)
call("echo Hello > /tmp/FooBar", shell=True)
Run Code Online (Sandbox Code Playgroud)
之所以失败,是因为一旦退出父进程,子进程便被杀死。我知道,creationflags但这是特定于Windows的,并且我正在Linux上运行。请注意,如果我们简单地通过在父进程的末尾添加无限循环来保持父进程的活动状态,则上述代码可以很好地工作。这是不希望的,因为父母已经完成了工作,没有真正的理由坚持下去。
第二次尝试是使用os.fork()。
#!/usr/bin/python
from subprocess import call
from os import fork
try:
pid = fork()
if pid > 0:
pass
else: # child process will start interactive process
call("/bin/bash", shell=True)
except:
print "Forking failed!"
call("echo Hello > /tmp/FooBar", shell=True)
Run Code Online (Sandbox Code Playgroud)
在这里,子进程不再与父进程一起消亡,但是在父进程去世后,子进程将无法再读取输入和写入输出。
因此,我想知道我是怎么一个新的进程具有完全独立的stdout,stderr和stdin。独立意味着父进程可以终止(通常),而子进程(无论是bash还是tmux或任何其他交互式程序)的行为就像父程序没有终止一样。为了更加精确,请考虑原始程序的以下变体。
#!/usr/bin/python
from subprocess import call,Popen
Popen("/bin/bash", shell=True)
call("echo Hello > …Run Code Online (Sandbox Code Playgroud) 考虑下面的简单程序,假设它在一个名为Test.c.
#include <stdio.h>
int main(){
fprintf(stdout, "Hello stdout\n");
fprintf(stderr, "Hello stderr\n");
}
Run Code Online (Sandbox Code Playgroud)
假设我将这个程序编译成一个名为的可执行文件Test并按如下方式运行它。
./Test > Out 2> Err
Run Code Online (Sandbox Code Playgroud)
在这次运行之后,我将有两个文件Out和Err,它们将分别包含两条消息。
这很棒,因为我通常可以将两种不同类型的消息打印到控制台,然后使用 bash 重定向来过滤一种或两种类型的消息。但是,我只能使用两个文件描述符进行这种过滤这一事实似乎非常有限。
有没有办法打开指向终端输出的第三个或第 n 个文件描述符,以便我可以单独过滤它?
语法可能是这样的。
./Test > Out 2> Err 3> Err2
Run Code Online (Sandbox Code Playgroud)
bash由于以下测试,我推测可能对此有一些基本的支持,这似乎意味着bash将 a 之后的数字&视为文件描述符。
$ ./Test >&2
Hello stdout
Hello stderr
$ ./Test >&3
bash: 3: Bad file descriptor
Run Code Online (Sandbox Code Playgroud) 我正在尝试从源代码构建git,并且我想make install将二进制文件放入dist源目录中调用的目录中,因此我使用以下configure行。
./configure --prefix=`pwd`/dist
Run Code Online (Sandbox Code Playgroud)
不幸的是,这也会导致构建输出假设这是 的最终安装位置git,因此将路径硬编码到各种脚本和二进制文件中,例如libexec/git-core/git-difftool.
有没有办法在其中指定configure或者make我想要实际部署的不同路径,例如/usr/bin/local,但仍然make install进入目录pwd/dist?
我的clang-format样式文件如下:
BasedOnStyle: Google
---
Language: Java
ColumnLimit: 100
BreakStringLiterals: true
BreakAfterJavaFieldAnnotations: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
Run Code Online (Sandbox Code Playgroud)
考虑以下输入java代码:
public class Lambda {
void handle() {
// TODO Try a compiling example next to see if it's different with clang-format.
try {
updateTranscriptResponse = Utils.doWithRetry(
/* task */
() -> { …Run Code Online (Sandbox Code Playgroud) 今天,我不小心输入了命令git reset stash,它对我最近的历史做了一些非常奇怪的事情。它看起来像最小的,它删除了最近的提交,并添加了另外两个提交,一个用于索引,另一个用于存储本身。
我环顾四周,man git-reset但没有发现那里描述的这种行为。
这个命令的预期语义是什么,它是否记录在某处?
linux ×3
git ×2
java ×2
python ×2
apache ×1
assembly ×1
autoconf ×1
bash ×1
c ×1
clang-format ×1
command-line ×1
csrf ×1
fork ×1
gdb ×1
performance ×1
security ×1
shell ×1
subprocess ×1
x86 ×1