linux/lib/strncpy_from_user.c
<<
>>
Prefs
   1#include <linux/module.h>
   2#include <linux/uaccess.h>
   3#include <linux/kernel.h>
   4#include <linux/errno.h>
   5
   6#include <asm/byteorder.h>
   7#include <asm/word-at-a-time.h>
   8
   9#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  10#define IS_UNALIGNED(src, dst)  0
  11#else
  12#define IS_UNALIGNED(src, dst)  \
  13        (((long) dst | (long) src) & (sizeof(long) - 1))
  14#endif
  15
  16/*
  17 * Do a strncpy, return length of string without final '\0'.
  18 * 'count' is the user-supplied count (return 'count' if we
  19 * hit it), 'max' is the address space maximum (and we return
  20 * -EFAULT if we hit it).
  21 */
  22static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
  23{
  24        const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
  25        long res = 0;
  26
  27        /*
  28         * Truncate 'max' to the user-specified limit, so that
  29         * we only have one limit we need to check in theloont
  20 * -EFAULT if we hit ve one lib/strncpy_from_user.c#L22" id="L22" class="3ine" nam3="L21">  21
< class="sref">srx)
count, unsigned long   22static <3 href32ass="comment"comment"lass="sref">srx)
   3#include &="lib33rncpy_from_user.c#L27" id="L27" class="3ine" nam3="L24">  24        3onst 34ass="comment>
< class="sref">sr"sref">IS_UNALIGNED(src, dst)  \
  25        3ong <35ass="comment"commentgodsword_at_a_time <word_  26
  27        3span 3lass="commentwhile< class="sref">srx)
  28ma/a>, dstataa>)  \
  29  20/*

  21
< class="sref">sruef=kelya>)  \
sr__get__user *sr/a>, ma>__user *src, res = 0;
  22static <4 href42ass="comment"commentttttttttbreakpy_from_user.c#L4" id="L4" class="linne" name4="L3">   3#include 4="lib43ass="comment"comment*(f="+code=max"  ) class="sref">srt)  \
res = 0;
   4#include &onst 44ass="comment"comment>
< class="sref">srhas_zeroa>, sr/a>, dstataa>)  \
dsef">constants =   25        4ong <45ass="comment"comment"comment"lass="sref">dstataa>)  \
sr/a>, dstataa>)  \
dsef">constants =   26
dstataa>)  \
srtataa>)  \
  27        4span 47ass="comment"comment"comment9; if wclass="sref">res = 0;
refind_zeroa>, srtataa>)  \
  28  29srs = 0;
  20srx)
  21  22static <5 href52rncpy_from_user.c#L27" id="L27" class="5ne" name5="L3">   3#include 5="lib53ass=class="sref">dsword_at_a_time <word_   4#include 5onst 54ass="commentwhile< class="sref">srx)
   5
,   26
  27        5span 57ass="comment"comment>
< class="sref">sruef=kelya>)  \
sr__get__user *sr/a>, src, res = 0;
  28re. = 0;
  29srt)  \
res = 0;
  20
< !AT_A_TIME_CONSTca>,   21res = 0;
  22static <6 href62ass="comment"comment"lass="sref">srs = 0;
   3#include 6="lib63ass="comment"commentclass="sref">srx)
   4#include 6onst 64ass="comment}y_from_user.c#L4" id="L4" class="li6ne" name6="L5">   5
   6#include &"lib/66ass="comment">/*
  27        6span 6mment"> * Do a strncpy, retuuuuuuuuu* Uhhuh. W href= user-specifi. But was="liblimit, so that  28         * Truncate 'maxtoo? If so,="libecifis ok -  29         * we only have one lib/strncpy_from_user.c#L22" id="L22" class="7m_user.c7="L20">  20
< class="sref">srs = 0;
count, unsigned long   21res = 0;
  22static <7 href72rncpy_from_user.c#L27" id="L27" class="7ne" name7="L3">   3#include 7="lib73ass="comment">/*
   4#include 7onst 74ment">         * Truncate 'maxNope:
   5
         * Truncate 'max__usactercount callet wouldeed towanted. Tlibecifis    .   6#include 7"lib/7mment">/*
   7#include &span 77ass="comment9; if w-class="sref">re. = 0;
  28  29  20 * -EFAULT if we hit/*b/strncpy_from_user.c#L28" id="L28" class="8ine" nam8="L21">  21 */
  22static <8 href82ment"> */
m (and ,   3#include 8="lib83ment"> */
   4#include 8onst 84ment">         * Truncate &i @ode:entSource>m (and ,   5
         * Truncate &* @ount&: Mn   6#include 8"lib/8mment">/*
   7#include 8span 8mment"> * Do a strncpy, returnCopihs=a NUL-terminatedl '\"L28 (rete ret=   8
 * 'count' is /strncpy_from_user.c#L28" id="L28" class="8ine" nam8="L29">  29 * hit it), 'maxOn suref="tring wicount hout finalunt  '\(not ord-at39;\unt trail39;/strncpy_from_user.c#L28" id="L28" class="9m_user.c9="L20">  20 * -EFAULT if we hit itNULib/strncpy_from_user.c#L21" id="L21" class="9ine" nam9="L21">  21 */
  22static <9 href92ment"> */
   3#include 9="lib93ment"> */
   4#include 9onst 94ment">         * Truncate &i/strncpy_from_user.c#L21" id="L21" class="9ne" name9="L5">   5
         * Truncate &* If @ount&#is smallet "linount hout finalunt  ', copihs @ount&#   6#include 9"lib/9mment">/*
   7#include 9span 9mment"> * Do a strncpy, returb/strncpy_from_user.c#L22" id="L22" class="9ne" name9="L8">   8
malass="sref">do_strncpy_from_user>(char *dst, const char __user *src, long count, unsigned long    9#ifdef   10#define max)
dsf="_m (aa>)
  11#else
  12#define <02s="
< class="sref">sruef=kelya>)  \
srcount, unsigned long   13        (03s="  14#endif
  15
max)
  16maf="_m (aa>)
src, long   17
< class="sref">srf=kelya>)  \
srf="_m (aa>)
max)
  18max)
dsf="_m (aa>)
  19re" class="sref">do_strncpy_from_user(char *dst, const char src, long srcount, unsigned long srx)
  10#define <  11#else
re. = 0;
  12#define <  13        ((((lo113ass=class="sref">dsEXPORT_SYMBOLa> = 0;
srfass="sref">do_strncpy_from_user>(char *  14#endif


1footstr> Tnt origspan>LXR softwartobylunt _from_usehttp://sourceforge.net/projects/lxtr>LXR ncpyunityvete >byl_from_usemailto:lxt@l