Which language can I use to write a hook script in Git? - githooks

I would like to know the script languages that you can use inside hook script in Git.
I have been reading about how to use Git hooks but I have not seen anywhere the language that can be used, I have seen some examples that look they are written in Perl but I am not sure of that since I have never programmed in Perl.

Any language, compiled or interpreted can be used (as long as the appropriate interpreter is available on the system).
The only requirement for hooks that run before events (e.g. pre-commit, pre-rebase, pre-push etc) and are allowed to block the event processing is to return the exit code 0 for success (let the operation continue) or a non-zero exit code to abort the operation.
The exit codes of the hooks that run after events (e.g. post-checkout, post-commit etc) do not matter; they cannot change anything, what had to be done has already been done before they were invoked.
Read the "Customizing Git - Git Hooks" page from the Git Book for details.

Related

Evaluating Lua for bare metal project

I'm evaluating Lua for a bare metal project (most of it is already running) and it looks like what we need.
I need to put it into my code and be able to call into Lua without hanging in there at all. I need to call into Lua repeatedly like it's a state machine and have it return a status every time I call it to say either "Keep calling me, I'm not finished", "Stop, I have an error", or "Stop, no errors, script has completed".
I've seen the hooks that allow a callback from Lua to c for every line or byte of bytecode that's evaluated, but I cannot use a callback.
Does a state machine implementation of Lua exist?
You're looking for the lua_resume C function, which uses coroutines. From its documentation:
lua_resume returns LUA_YIELD if the coroutine yields, 0 if the coroutine finishes its execution without errors, or an error code in case of errors (see lua_pcall).
That sounds to me like exactly what you're describing.

Execute or skip ld.so.preload shared library code based upon conditions

TL;DR: Can I just skip loading a shared library placed in ld.so.preload or specific code from it when executing a binary and RUID != UID?
Hi.
I'm writing a shared object, a library, that I load via ld.so.preload in order to hook some functions. I want to know if I can, based upon some conditions, skip loading such library or some parts of it.
Context: I'm working with TOCTTOU (Time To Check To Time To Use) vulnerability and I'm writing a userland library, that will be loaded via linux's loader ld.so.preload feature. The main idea is to hook all functions that operate with files, do some checkings and then call the original function so it's transparent to users and other programs.
Now, the thing is: As I don't want to overload the system and I want my library to have as little impact, overhead as possible, I'd like to execute it, that is, to hook the functions, only when RUID != EUID. That's one of the file-based TOCTTOU premises, it happens when the attacker has lesser privileges than the vulnerable application.
The only way that comes to my mind as of right now is to surround every function declaration with:
if(RUID == EUID){
call original function;
} else {
do my checkings;
call original function;
}
EDIT: The above code could be replaced by its equivalent, shorter:
if(RUID != EUID){
do my checkings;
}
call original function;
But that's actually pretty awful since I'm hooking almost 50 functions plus working with __attribute constructor and destructor and It'd mean to fill my code with if-else blocks in each and every single function.
Please bear in mind that ld.so.preload loads the listed libraries before any other library.
I'd like to know if there is any way of just not loading the library based upon the RUID != EUID condition or, alternatively, load the library but skip the hooking code.
Since my library is system-wide, I cannot create any wrapper for it.
You want to preload your library only into setuid or setgid programs.
Since the number of such programs on any system is quite small and statically known (you can find them all with a cron job every hour), the easiest solution is to create a wrapper for every such program.
The wrapper can itself be a single very small program that has the exact same setuid / setgid permissions as the "target" program, and performs an equivalent of
/bin/env "LD_PRELOAD=..." target-prog args

what is the purpose of UVM automation macro?

I'm trying to understand about UVM automation macro.
among other things, i found some sentence "UVM system Verilog call library also includes macros that automatically implement the print, copy, clone, compare, pack and unpack methods and more" from text.
and I found that lots of example used with the following usage.
For example,
....
uvm_object_utils_begin(apb_transfer)
'uvm_field_int(addr, UVM_DEFAULT)
'uvm_field_int(data, UVM_DEFAULT)
...
uvm_object_utils_end
but I didn't get it. that usage of 'uvm_field_int() is just defining the variable not copy, clone, compare....
How do I understand what uvm automation macro to do?
even I also curious about why those things are named as a automation? I can't find any something auto kind of thing.
As you say, the UVM field automation macros generate a number of class utility methods such as copy, print and clone that include the registered fields. That's it. I guess the name "automation" is used, because they automatically write code so you don't have to.
My company (Doulos) recommends you don't use these macros useless you know what you're doing. This is because they can be hard to debug, can generate more code than you need and have a strange side effect (values can be read from the configuration database automatically without your knowledge). Of course, the advantage of using them is that you get a whole bunch of code for free - the copy, compare,, print methods etc.
The HTML documentation supplied with a UVM download is very good. Search for `uvm_object_utils and follow your nose.

vim autowrite functions in header file. C lang

I tried to use vim for c program editing. Is there a way to auto write function skeleton defined in header file?
situations like
"my_code.h"
int temp(int*);
and "my_code.c"
<<< here auto write >>> like
int temp(int*) { return }
int main()
{
}
I'm using c.vim plug-in. I tried to find it, but I couldn't make it.
There are code completion scripts, yes.. However, this is not something you generally want. It works for simple things like basic C functions, and fails horribly beyond that (i.e. templates etc in c++). You don't save any time by using such plugins, and mastering vim motion/yank/paste commands provide the same result in the same amount of time, and you become more familiar with a modal editor. Is it that hard to copy-paste the function prototype and add some braces {/}?
If you want something to help as a reminder to write function definitions to go with function prototypes, consider using the taglist plugin.
snippets are like the built-in :abbreviate on steroids, usually with parameter insertions, mirroring, and multiple stops inside them. One of the first, very famous (and still widely used) Vim plugins is snipMate (inspired by the TextMate editor); unfortunately, it's not maintained any more; though there is a fork. A modern alternative (that requires Python though) is UltiSnips. There are more, see this list on the Vim Tips Wiki.
There are three things to evaluate: First, the features of the snippet engine itself, second, the quality and breadth of snippets provided by the author or others; third, how easy it is to add new snippets.
Additionally, there are also template plugins that pre-initialize a new, empty file with a skeleton, often including a file header and copyright statement. Search vim.org; you'll find plenty.
I've have a :GOTOIMPL command in lh-cpp that generates an empty function definition from a function declaration.
However, you'll have to execute the command on each function declaration and go back to the header file. I've never took the time to batch the process from an header file and no implementation file -- as this is not a use case I have as there exist other solutions...
IOW... there exist projects that do the job from the command-line (and which you could call from vim then) (like for instance https://github.com/Davidbrcz/header-expander), or even other plugins (like protodef: http://www.vim.org/scripts/script.php?script_id=2624).

How can I jump to function when doing C development in Emacs?

I am doing C development in Emacs. If I have a source file open with multiple functions and "the marker" is at a function call e.g. int n = get_number(arg); is there any way I can "jump to" the implementation of that function? e.g. to int get_number(int *arg) { ... }
I have done some Java development in Eclipse and is missing this functionallity, because I'm not that used to Emacs but I would like to learn.
You have to create a tag file.
Under Unix, you have the etags program that understands the syntax of C, C++, Java... and that create a tag file that can be used by Emacs.
This rather old page (2004) provides more information.
To jump to a function use M-. (that’s Meta-Period) and type the name of the function. If you
simply press enter Emacs will jump to the function declaration that matches the word under
the cursor.
There are several "tags" systems which allows that (there is one bundled with emacs, there is GNU global which isn't bundled with emacs but integrate well with it and has some advantages). Compared with Eclipse, you'll need to build the tags file.
Then there is semantic/EDE which is now bundled with emacs which should provide a solution without needing to build a database explicitly. I've not tried to use it recently. When I did, it has performance problem and I found the set up was painful. (Both possibly due to the fact that I'm working on a big -- several 10's millions lines -- and old -- some things date back to the mid 80's -- project without the possibility of reorganizing it).
I think semantic-mode should do you the same result. Although I haven't tried to jump to another file, but in one file it's very excellent. Go to a variable, issue keystroke C-c,j, it will jump to the definition of the variable. Go back to previous line using C-uC-space. To display reference to the symbol, use keystroke C-c,g
It really helps me.
I haven't tried it to jump to another file, because my current project is a modified Java program, where we are using preprocessor (a non standard java process). So I think that is where the problem lies.
Anyone success with semantic-mode???
thanks
I really like cscope for this, but etags probably works as well.

Resources