Show
Ignore:
Timestamp:
07/12/06 08:12:38 (3 years ago)
Author:
ludovic.rousseau
Message:

- use strlcpy() instead of strncpy() to always have a terminating

NUL-byte

- use sizeof(field) instead of SC_PKCS15_MAX_LABEL_SIZE-1 or equivalent as

the 3rd argument of strlcpy()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/libopensc/pkcs15-infocamere.c

    r2722 r2993  
    3131#include <string.h> 
    3232#include <stdio.h> 
     33#include "strlcpy.h" 
    3334 
    3435#ifdef HAVE_ZLIB_H 
     
    9697                info.stored_length /= 2; 
    9798 
    98         strncpy(obj.label, label, SC_PKCS15_MAX_LABEL_SIZE-1); 
     99        strlcpy(obj.label, label, sizeof(obj.label)); 
    99100        obj.flags = obj_flags; 
    100101 
     
    129130 
    130131        obj.flags = obj_flags; 
    131         strncpy(obj.label, label, SC_PKCS15_MAX_LABEL_SIZE-1); 
     132        strlcpy(obj.label, label, sizeof(obj.label)); 
    132133        if (auth_id != NULL) 
    133134                obj.auth_id = *auth_id; 
     
    152153                info.path = *path; 
    153154 
    154         strncpy(obj.label, label, SC_PKCS15_MAX_LABEL_SIZE-1); 
     155        strlcpy(obj.label, label, sizeof(obj.label)); 
    155156        obj.flags = obj_flags; 
    156157 
     
    327328                cert_info.authority = authority; 
    328329                cert_info.path = path; 
    329                 strncpy(cert_obj.label, authlabel, SC_PKCS15_MAX_LABEL_SIZE - 1); 
     330                strlcpy(cert_obj.label, authlabel, sizeof(cert_obj.label)); 
    330331                cert_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE; 
    331332 
     
    385386        cert_info.authority = authority; 
    386387        cert_info.path = path; 
    387         strncpy(cert_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1); 
     388        strlcpy(cert_obj.label, label, sizeof(cert_obj.label)); 
    388389        cert_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE; 
    389390 
     
    420421                        cert_info.authority = authority; 
    421422                        cert_info.path = path; 
    422                         strncpy(cert_obj.label, calabel, SC_PKCS15_MAX_LABEL_SIZE - 1); 
     423                        strlcpy(cert_obj.label, calabel, sizeof(cert_obj.label)); 
    423424                        cert_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE; 
    424425 
     
    546547        cert_info.authority = (i == 2); 
    547548 
    548         strncpy(cert_obj.label, certLabel, SC_PKCS15_MAX_LABEL_SIZE - 1); 
     549        strlcpy(cert_obj.label, certLabel, sizeof(cert_obj.label)); 
    549550        cert_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE; 
    550551