Wednesday, April 10, 2013

When to use strlcpy and strncpy (strlcat and strcat)


  • Found a large number of overflows due to unbounded string copies using sprintf(), strcpy() and strcat(), as well as loops that manipulated strings without an explicit length check in the loop invariant.
  • The most common misconception is that strncpy() NUL-terminates the destination string. This is only true, however, if length of the source string is less than the size parameter.  The safest way to use strncpy() in this situation is to pass it one less than the size of the destination string, and then terminate the string by hand.
  • Both strlcpy() and strlcat() guarantee to NUL-terminate the destination string for all strings where the given size is non-zero. 
  • Both functions take the full size of the destination string as a size parameter

Locking in Linux SMP - When to use what?


  • For kernels compiled without CONFIG_SMP, and without CONFIG_PREEMPT spinlocks do not exist at all.
  • If the kernel is compiled without CONFIG_SMP, but CONFIG_PREEMPT is set, then spinlocks simply disable preemption, which is sufficient to prevent any races.
  • Remember the advice above: you can always use spin_lock_irqsave(), which is a superset of all other spinlock primitives.

Monday, April 8, 2013

Internet works directly through modem but not on wireless router

- The problem is likely with the fact that your modem is keeping a cached MAC address of the laptop that you used to test your connection.
- Solution1: Disconnect all cables on the modem (including the coax) and let it stay for a minute. This allows the modem to completely discharge irrespective of a bad bleeder resistor.
- Solution2: Check  if your modem has a reset button. If it does keep it pressed when the modem is powered on for at least 20secs and then reconnect the wireless router once the modem is up.